kernel/sysctl.c: define minmax conv functions in terms of non-minmax versions
[linux-block.git] / include / linux / hmm.h
CommitLineData
133ff0ea
JG
1/*
2 * Copyright 2013 Red Hat Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
f813f219 14 * Authors: Jérôme Glisse <jglisse@redhat.com>
133ff0ea
JG
15 */
16/*
17 * Heterogeneous Memory Management (HMM)
18 *
ad56b738 19 * See Documentation/vm/hmm.rst for reasons and overview of what HMM is and it
133ff0ea
JG
20 * is for. Here we focus on the HMM API description, with some explanation of
21 * the underlying implementation.
22 *
23 * Short description: HMM provides a set of helpers to share a virtual address
24 * space between CPU and a device, so that the device can access any valid
25 * address of the process (while still obeying memory protection). HMM also
26 * provides helpers to migrate process memory to device memory, and back. Each
27 * set of functionality (address space mirroring, and migration to and from
28 * device memory) can be used independently of the other.
29 *
30 *
31 * HMM address space mirroring API:
32 *
33 * Use HMM address space mirroring if you want to mirror range of the CPU page
34 * table of a process into a device page table. Here, "mirror" means "keep
35 * synchronized". Prerequisites: the device must provide the ability to write-
36 * protect its page tables (at PAGE_SIZE granularity), and must be able to
37 * recover from the resulting potential page faults.
38 *
39 * HMM guarantees that at any point in time, a given virtual address points to
40 * either the same memory in both CPU and device page tables (that is: CPU and
41 * device page tables each point to the same pages), or that one page table (CPU
42 * or device) points to no entry, while the other still points to the old page
43 * for the address. The latter case happens when the CPU page table update
44 * happens first, and then the update is mirrored over to the device page table.
45 * This does not cause any issue, because the CPU page table cannot start
46 * pointing to a new page until the device page table is invalidated.
47 *
48 * HMM uses mmu_notifiers to monitor the CPU page tables, and forwards any
49 * updates to each device driver that has registered a mirror. It also provides
50 * some API calls to help with taking a snapshot of the CPU page table, and to
51 * synchronize with any updates that might happen concurrently.
52 *
53 *
54 * HMM migration to and from device memory:
55 *
56 * HMM provides a set of helpers to hotplug device memory as ZONE_DEVICE, with
57 * a new MEMORY_DEVICE_PRIVATE type. This provides a struct page for each page
58 * of the device memory, and allows the device driver to manage its memory
59 * using those struct pages. Having struct pages for device memory makes
60 * migration easier. Because that memory is not addressable by the CPU it must
61 * never be pinned to the device; in other words, any CPU page fault can always
62 * cause the device memory to be migrated (copied/moved) back to regular memory.
63 *
64 * A new migrate helper (migrate_vma()) has been added (see mm/migrate.c) that
65 * allows use of a device DMA engine to perform the copy operation between
66 * regular system memory and device memory.
67 */
68#ifndef LINUX_HMM_H
69#define LINUX_HMM_H
70
71#include <linux/kconfig.h>
063a7d1d 72#include <asm/pgtable.h>
133ff0ea
JG
73
74#if IS_ENABLED(CONFIG_HMM)
75
858b54da 76#include <linux/device.h>
4ef589dc
JG
77#include <linux/migrate.h>
78#include <linux/memremap.h>
79#include <linux/completion.h>
80
c0b12405 81struct hmm;
133ff0ea
JG
82
83/*
f88a1e90
JG
84 * hmm_pfn_flag_e - HMM flag enums
85 *
133ff0ea 86 * Flags:
86586a41 87 * HMM_PFN_VALID: pfn is valid. It has, at least, read permission.
133ff0ea 88 * HMM_PFN_WRITE: CPU page table has write permission set
f88a1e90
JG
89 * HMM_PFN_DEVICE_PRIVATE: private device memory (ZONE_DEVICE)
90 *
91 * The driver provide a flags array, if driver valid bit for an entry is bit
92 * 3 ie (entry & (1 << 3)) is true if entry is valid then driver must provide
93 * an array in hmm_range.flags with hmm_range.flags[HMM_PFN_VALID] == 1 << 3.
94 * Same logic apply to all flags. This is same idea as vm_page_prot in vma
95 * except that this is per device driver rather than per architecture.
96 */
97enum hmm_pfn_flag_e {
98 HMM_PFN_VALID = 0,
99 HMM_PFN_WRITE,
100 HMM_PFN_DEVICE_PRIVATE,
101 HMM_PFN_FLAG_MAX
102};
103
104/*
105 * hmm_pfn_value_e - HMM pfn special value
106 *
107 * Flags:
da4c3c73 108 * HMM_PFN_ERROR: corresponding CPU page table entry points to poisoned memory
f88a1e90 109 * HMM_PFN_NONE: corresponding CPU page table entry is pte_none()
da4c3c73 110 * HMM_PFN_SPECIAL: corresponding CPU page table entry is special; i.e., the
67fa1666 111 * result of vmf_insert_pfn() or vm_insert_page(). Therefore, it should not
da4c3c73
JG
112 * be mirrored by a device, because the entry will never have HMM_PFN_VALID
113 * set and the pfn value is undefined.
f88a1e90
JG
114 *
115 * Driver provide entry value for none entry, error entry and special entry,
116 * driver can alias (ie use same value for error and special for instance). It
117 * should not alias none and error or special.
118 *
119 * HMM pfn value returned by hmm_vma_get_pfns() or hmm_vma_fault() will be:
120 * hmm_range.values[HMM_PFN_ERROR] if CPU page table entry is poisonous,
121 * hmm_range.values[HMM_PFN_NONE] if there is no CPU page table
122 * hmm_range.values[HMM_PFN_SPECIAL] if CPU page table entry is a special one
133ff0ea 123 */
f88a1e90
JG
124enum hmm_pfn_value_e {
125 HMM_PFN_ERROR,
126 HMM_PFN_NONE,
127 HMM_PFN_SPECIAL,
128 HMM_PFN_VALUE_MAX
129};
130
131/*
132 * struct hmm_range - track invalidation lock on virtual address range
133 *
134 * @vma: the vm area struct for the range
135 * @list: all range lock are on a list
136 * @start: range virtual start address (inclusive)
137 * @end: range virtual end address (exclusive)
138 * @pfns: array of pfns (big enough for the range)
139 * @flags: pfn flags to match device driver page table
140 * @values: pfn value for some special case (none, special, error, ...)
141 * @pfn_shifts: pfn shift value (should be <= PAGE_SHIFT)
142 * @valid: pfns array did not change since it has been fill by an HMM function
143 */
144struct hmm_range {
145 struct vm_area_struct *vma;
146 struct list_head list;
147 unsigned long start;
148 unsigned long end;
149 uint64_t *pfns;
150 const uint64_t *flags;
151 const uint64_t *values;
152 uint8_t pfn_shift;
153 bool valid;
154};
133ff0ea
JG
155
156/*
ff05c0c6 157 * hmm_pfn_to_page() - return struct page pointed to by a valid HMM pfn
f88a1e90 158 * @range: range use to decode HMM pfn value
ff05c0c6
JG
159 * @pfn: HMM pfn value to get corresponding struct page from
160 * Returns: struct page pointer if pfn is a valid HMM pfn, NULL otherwise
133ff0ea 161 *
ff05c0c6
JG
162 * If the HMM pfn is valid (ie valid flag set) then return the struct page
163 * matching the pfn value stored in the HMM pfn. Otherwise return NULL.
133ff0ea 164 */
f88a1e90
JG
165static inline struct page *hmm_pfn_to_page(const struct hmm_range *range,
166 uint64_t pfn)
133ff0ea 167{
f88a1e90
JG
168 if (pfn == range->values[HMM_PFN_NONE])
169 return NULL;
170 if (pfn == range->values[HMM_PFN_ERROR])
171 return NULL;
172 if (pfn == range->values[HMM_PFN_SPECIAL])
133ff0ea 173 return NULL;
f88a1e90
JG
174 if (!(pfn & range->flags[HMM_PFN_VALID]))
175 return NULL;
176 return pfn_to_page(pfn >> range->pfn_shift);
133ff0ea
JG
177}
178
179/*
ff05c0c6 180 * hmm_pfn_to_pfn() - return pfn value store in a HMM pfn
f88a1e90 181 * @range: range use to decode HMM pfn value
ff05c0c6
JG
182 * @pfn: HMM pfn value to extract pfn from
183 * Returns: pfn value if HMM pfn is valid, -1UL otherwise
133ff0ea 184 */
f88a1e90
JG
185static inline unsigned long hmm_pfn_to_pfn(const struct hmm_range *range,
186 uint64_t pfn)
133ff0ea 187{
f88a1e90
JG
188 if (pfn == range->values[HMM_PFN_NONE])
189 return -1UL;
190 if (pfn == range->values[HMM_PFN_ERROR])
191 return -1UL;
192 if (pfn == range->values[HMM_PFN_SPECIAL])
133ff0ea 193 return -1UL;
f88a1e90
JG
194 if (!(pfn & range->flags[HMM_PFN_VALID]))
195 return -1UL;
196 return (pfn >> range->pfn_shift);
133ff0ea
JG
197}
198
199/*
ff05c0c6 200 * hmm_pfn_from_page() - create a valid HMM pfn value from struct page
f88a1e90 201 * @range: range use to encode HMM pfn value
ff05c0c6
JG
202 * @page: struct page pointer for which to create the HMM pfn
203 * Returns: valid HMM pfn for the page
133ff0ea 204 */
f88a1e90
JG
205static inline uint64_t hmm_pfn_from_page(const struct hmm_range *range,
206 struct page *page)
133ff0ea 207{
f88a1e90
JG
208 return (page_to_pfn(page) << range->pfn_shift) |
209 range->flags[HMM_PFN_VALID];
133ff0ea
JG
210}
211
212/*
ff05c0c6 213 * hmm_pfn_from_pfn() - create a valid HMM pfn value from pfn
f88a1e90 214 * @range: range use to encode HMM pfn value
ff05c0c6
JG
215 * @pfn: pfn value for which to create the HMM pfn
216 * Returns: valid HMM pfn for the pfn
133ff0ea 217 */
f88a1e90
JG
218static inline uint64_t hmm_pfn_from_pfn(const struct hmm_range *range,
219 unsigned long pfn)
133ff0ea 220{
f88a1e90
JG
221 return (pfn << range->pfn_shift) |
222 range->flags[HMM_PFN_VALID];
133ff0ea
JG
223}
224
225
c0b12405
JG
226#if IS_ENABLED(CONFIG_HMM_MIRROR)
227/*
228 * Mirroring: how to synchronize device page table with CPU page table.
229 *
230 * A device driver that is participating in HMM mirroring must always
231 * synchronize with CPU page table updates. For this, device drivers can either
232 * directly use mmu_notifier APIs or they can use the hmm_mirror API. Device
233 * drivers can decide to register one mirror per device per process, or just
234 * one mirror per process for a group of devices. The pattern is:
235 *
236 * int device_bind_address_space(..., struct mm_struct *mm, ...)
237 * {
238 * struct device_address_space *das;
239 *
240 * // Device driver specific initialization, and allocation of das
241 * // which contains an hmm_mirror struct as one of its fields.
242 * ...
243 *
244 * ret = hmm_mirror_register(&das->mirror, mm, &device_mirror_ops);
245 * if (ret) {
246 * // Cleanup on error
247 * return ret;
248 * }
249 *
250 * // Other device driver specific initialization
251 * ...
252 * }
253 *
254 * Once an hmm_mirror is registered for an address space, the device driver
255 * will get callbacks through sync_cpu_device_pagetables() operation (see
256 * hmm_mirror_ops struct).
257 *
258 * Device driver must not free the struct containing the hmm_mirror struct
259 * before calling hmm_mirror_unregister(). The expected usage is to do that when
260 * the device driver is unbinding from an address space.
261 *
262 *
263 * void device_unbind_address_space(struct device_address_space *das)
264 * {
265 * // Device driver specific cleanup
266 * ...
267 *
268 * hmm_mirror_unregister(&das->mirror);
269 *
270 * // Other device driver specific cleanup, and now das can be freed
271 * ...
272 * }
273 */
274
275struct hmm_mirror;
276
277/*
44532d4c 278 * enum hmm_update_event - type of update
c0b12405
JG
279 * @HMM_UPDATE_INVALIDATE: invalidate range (no indication as to why)
280 */
44532d4c 281enum hmm_update_event {
c0b12405
JG
282 HMM_UPDATE_INVALIDATE,
283};
284
44532d4c
JG
285/*
286 * struct hmm_update - HMM update informations for callback
287 *
288 * @start: virtual start address of the range to update
289 * @end: virtual end address of the range to update
290 * @event: event triggering the update (what is happening)
291 * @blockable: can the callback block/sleep ?
292 */
293struct hmm_update {
294 unsigned long start;
295 unsigned long end;
296 enum hmm_update_event event;
297 bool blockable;
298};
299
c0b12405
JG
300/*
301 * struct hmm_mirror_ops - HMM mirror device operations callback
302 *
303 * @update: callback to update range on a device
304 */
305struct hmm_mirror_ops {
e1401513
RC
306 /* release() - release hmm_mirror
307 *
308 * @mirror: pointer to struct hmm_mirror
309 *
310 * This is called when the mm_struct is being released.
311 * The callback should make sure no references to the mirror occur
312 * after the callback returns.
313 */
314 void (*release)(struct hmm_mirror *mirror);
315
c0b12405
JG
316 /* sync_cpu_device_pagetables() - synchronize page tables
317 *
318 * @mirror: pointer to struct hmm_mirror
44532d4c
JG
319 * @update: update informations (see struct hmm_update)
320 * Returns: -EAGAIN if update.blockable false and callback need to
321 * block, 0 otherwise.
c0b12405
JG
322 *
323 * This callback ultimately originates from mmu_notifiers when the CPU
324 * page table is updated. The device driver must update its page table
325 * in response to this callback. The update argument tells what action
326 * to perform.
327 *
328 * The device driver must not return from this callback until the device
329 * page tables are completely updated (TLBs flushed, etc); this is a
330 * synchronous call.
331 */
44532d4c
JG
332 int (*sync_cpu_device_pagetables)(struct hmm_mirror *mirror,
333 const struct hmm_update *update);
c0b12405
JG
334};
335
336/*
337 * struct hmm_mirror - mirror struct for a device driver
338 *
339 * @hmm: pointer to struct hmm (which is unique per mm_struct)
340 * @ops: device driver callback for HMM mirror operations
341 * @list: for list of mirrors of a given mm
342 *
343 * Each address space (mm_struct) being mirrored by a device must register one
344 * instance of an hmm_mirror struct with HMM. HMM will track the list of all
345 * mirrors for each mm_struct.
346 */
347struct hmm_mirror {
348 struct hmm *hmm;
349 const struct hmm_mirror_ops *ops;
350 struct list_head list;
351};
352
353int hmm_mirror_register(struct hmm_mirror *mirror, struct mm_struct *mm);
354void hmm_mirror_unregister(struct hmm_mirror *mirror);
da4c3c73
JG
355
356
da4c3c73
JG
357/*
358 * To snapshot the CPU page table, call hmm_vma_get_pfns(), then take a device
359 * driver lock that serializes device page table updates, then call
360 * hmm_vma_range_done(), to check if the snapshot is still valid. The same
361 * device driver page table update lock must also be used in the
362 * hmm_mirror_ops.sync_cpu_device_pagetables() callback, so that CPU page
363 * table invalidation serializes on it.
364 *
365 * YOU MUST CALL hmm_vma_range_done() ONCE AND ONLY ONCE EACH TIME YOU CALL
366 * hmm_vma_get_pfns() WITHOUT ERROR !
367 *
368 * IF YOU DO NOT FOLLOW THE ABOVE RULE THE SNAPSHOT CONTENT MIGHT BE INVALID !
369 */
08232a45
JG
370int hmm_vma_get_pfns(struct hmm_range *range);
371bool hmm_vma_range_done(struct hmm_range *range);
74eee180
JG
372
373
374/*
375 * Fault memory on behalf of device driver. Unlike handle_mm_fault(), this will
ff05c0c6 376 * not migrate any device memory back to system memory. The HMM pfn array will
74eee180
JG
377 * be updated with the fault result and current snapshot of the CPU page table
378 * for the range.
379 *
380 * The mmap_sem must be taken in read mode before entering and it might be
381 * dropped by the function if the block argument is false. In that case, the
382 * function returns -EAGAIN.
383 *
384 * Return value does not reflect if the fault was successful for every single
ff05c0c6 385 * address or not. Therefore, the caller must to inspect the HMM pfn array to
74eee180
JG
386 * determine fault status for each address.
387 *
388 * Trying to fault inside an invalid vma will result in -EINVAL.
389 *
390 * See the function description in mm/hmm.c for further documentation.
391 */
2aee09d8 392int hmm_vma_fault(struct hmm_range *range, bool block);
c0b12405 393
9d8a463a
AB
394/* Below are for HMM internal use only! Not to be used by device driver! */
395void hmm_mm_destroy(struct mm_struct *mm);
396
397static inline void hmm_mm_init(struct mm_struct *mm)
398{
399 mm->hmm = NULL;
400}
401#else /* IS_ENABLED(CONFIG_HMM_MIRROR) */
402static inline void hmm_mm_destroy(struct mm_struct *mm) {}
403static inline void hmm_mm_init(struct mm_struct *mm) {}
404#endif /* IS_ENABLED(CONFIG_HMM_MIRROR) */
c0b12405 405
df6ad698 406#if IS_ENABLED(CONFIG_DEVICE_PRIVATE) || IS_ENABLED(CONFIG_DEVICE_PUBLIC)
4ef589dc
JG
407struct hmm_devmem;
408
409struct page *hmm_vma_alloc_locked_page(struct vm_area_struct *vma,
410 unsigned long addr);
411
412/*
413 * struct hmm_devmem_ops - callback for ZONE_DEVICE memory events
414 *
415 * @free: call when refcount on page reach 1 and thus is no longer use
416 * @fault: call when there is a page fault to unaddressable memory
417 *
418 * Both callback happens from page_free() and page_fault() callback of struct
419 * dev_pagemap respectively. See include/linux/memremap.h for more details on
420 * those.
421 *
422 * The hmm_devmem_ops callback are just here to provide a coherent and
423 * uniq API to device driver and device driver should not register their
424 * own page_free() or page_fault() but rely on the hmm_devmem_ops call-
425 * back.
426 */
427struct hmm_devmem_ops {
428 /*
429 * free() - free a device page
430 * @devmem: device memory structure (see struct hmm_devmem)
431 * @page: pointer to struct page being freed
432 *
433 * Call back occurs whenever a device page refcount reach 1 which
434 * means that no one is holding any reference on the page anymore
435 * (ZONE_DEVICE page have an elevated refcount of 1 as default so
436 * that they are not release to the general page allocator).
437 *
438 * Note that callback has exclusive ownership of the page (as no
439 * one is holding any reference).
440 */
441 void (*free)(struct hmm_devmem *devmem, struct page *page);
442 /*
443 * fault() - CPU page fault or get user page (GUP)
444 * @devmem: device memory structure (see struct hmm_devmem)
445 * @vma: virtual memory area containing the virtual address
446 * @addr: virtual address that faulted or for which there is a GUP
447 * @page: pointer to struct page backing virtual address (unreliable)
448 * @flags: FAULT_FLAG_* (see include/linux/mm.h)
449 * @pmdp: page middle directory
450 * Returns: VM_FAULT_MINOR/MAJOR on success or one of VM_FAULT_ERROR
451 * on error
452 *
453 * The callback occurs whenever there is a CPU page fault or GUP on a
454 * virtual address. This means that the device driver must migrate the
455 * page back to regular memory (CPU accessible).
456 *
457 * The device driver is free to migrate more than one page from the
458 * fault() callback as an optimization. However if device decide to
459 * migrate more than one page it must always priotirize the faulting
460 * address over the others.
461 *
462 * The struct page pointer is only given as an hint to allow quick
463 * lookup of internal device driver data. A concurrent migration
464 * might have already free that page and the virtual address might
465 * not longer be back by it. So it should not be modified by the
466 * callback.
467 *
468 * Note that mmap semaphore is held in read mode at least when this
469 * callback occurs, hence the vma is valid upon callback entry.
470 */
471 int (*fault)(struct hmm_devmem *devmem,
472 struct vm_area_struct *vma,
473 unsigned long addr,
474 const struct page *page,
475 unsigned int flags,
476 pmd_t *pmdp);
477};
478
479/*
480 * struct hmm_devmem - track device memory
481 *
482 * @completion: completion object for device memory
483 * @pfn_first: first pfn for this resource (set by hmm_devmem_add())
484 * @pfn_last: last pfn for this resource (set by hmm_devmem_add())
485 * @resource: IO resource reserved for this chunk of memory
486 * @pagemap: device page map for that chunk
487 * @device: device to bind resource to
488 * @ops: memory operations callback
489 * @ref: per CPU refcount
063a7d1d 490 * @page_fault: callback when CPU fault on an unaddressable device page
4ef589dc
JG
491 *
492 * This an helper structure for device drivers that do not wish to implement
493 * the gory details related to hotplugging new memoy and allocating struct
494 * pages.
495 *
496 * Device drivers can directly use ZONE_DEVICE memory on their own if they
497 * wish to do so.
063a7d1d
DW
498 *
499 * The page_fault() callback must migrate page back, from device memory to
500 * system memory, so that the CPU can access it. This might fail for various
501 * reasons (device issues, device have been unplugged, ...). When such error
502 * conditions happen, the page_fault() callback must return VM_FAULT_SIGBUS and
503 * set the CPU page table entry to "poisoned".
504 *
505 * Note that because memory cgroup charges are transferred to the device memory,
506 * this should never fail due to memory restrictions. However, allocation
507 * of a regular system page might still fail because we are out of memory. If
508 * that happens, the page_fault() callback must return VM_FAULT_OOM.
509 *
510 * The page_fault() callback can also try to migrate back multiple pages in one
511 * chunk, as an optimization. It must, however, prioritize the faulting address
512 * over all the others.
4ef589dc 513 */
063a7d1d
DW
514typedef int (*dev_page_fault_t)(struct vm_area_struct *vma,
515 unsigned long addr,
516 const struct page *page,
517 unsigned int flags,
518 pmd_t *pmdp);
519
4ef589dc
JG
520struct hmm_devmem {
521 struct completion completion;
522 unsigned long pfn_first;
523 unsigned long pfn_last;
524 struct resource *resource;
525 struct device *device;
526 struct dev_pagemap pagemap;
527 const struct hmm_devmem_ops *ops;
528 struct percpu_ref ref;
063a7d1d 529 dev_page_fault_t page_fault;
4ef589dc
JG
530};
531
532/*
533 * To add (hotplug) device memory, HMM assumes that there is no real resource
534 * that reserves a range in the physical address space (this is intended to be
535 * use by unaddressable device memory). It will reserve a physical range big
536 * enough and allocate struct page for it.
537 *
538 * The device driver can wrap the hmm_devmem struct inside a private device
58ef15b7 539 * driver struct.
4ef589dc
JG
540 */
541struct hmm_devmem *hmm_devmem_add(const struct hmm_devmem_ops *ops,
542 struct device *device,
543 unsigned long size);
d3df0a42
JG
544struct hmm_devmem *hmm_devmem_add_resource(const struct hmm_devmem_ops *ops,
545 struct device *device,
546 struct resource *res);
4ef589dc
JG
547
548/*
549 * hmm_devmem_page_set_drvdata - set per-page driver data field
550 *
551 * @page: pointer to struct page
552 * @data: driver data value to set
553 *
554 * Because page can not be on lru we have an unsigned long that driver can use
555 * to store a per page field. This just a simple helper to do that.
556 */
557static inline void hmm_devmem_page_set_drvdata(struct page *page,
558 unsigned long data)
559{
50e7fbc3 560 page->hmm_data = data;
4ef589dc
JG
561}
562
563/*
564 * hmm_devmem_page_get_drvdata - get per page driver data field
565 *
566 * @page: pointer to struct page
567 * Return: driver data value
568 */
0bea803e 569static inline unsigned long hmm_devmem_page_get_drvdata(const struct page *page)
4ef589dc 570{
50e7fbc3 571 return page->hmm_data;
4ef589dc 572}
858b54da
JG
573
574
575/*
576 * struct hmm_device - fake device to hang device memory onto
577 *
578 * @device: device struct
579 * @minor: device minor number
580 */
581struct hmm_device {
582 struct device device;
583 unsigned int minor;
584};
585
586/*
587 * A device driver that wants to handle multiple devices memory through a
588 * single fake device can use hmm_device to do so. This is purely a helper and
589 * it is not strictly needed, in order to make use of any HMM functionality.
590 */
591struct hmm_device *hmm_device_new(void *drvdata);
592void hmm_device_put(struct hmm_device *hmm_device);
df6ad698 593#endif /* CONFIG_DEVICE_PRIVATE || CONFIG_DEVICE_PUBLIC */
6b368cd4 594#else /* IS_ENABLED(CONFIG_HMM) */
133ff0ea
JG
595static inline void hmm_mm_destroy(struct mm_struct *mm) {}
596static inline void hmm_mm_init(struct mm_struct *mm) {}
b28b08de 597#endif /* IS_ENABLED(CONFIG_HMM) */
9d8a463a 598
133ff0ea 599#endif /* LINUX_HMM_H */