Dan Williams | 9476df7 | 2016-01-15 16:56:19 -0800 | [diff] [blame] | 1 | #ifndef _LINUX_MEMREMAP_H_ |
| 2 | #define _LINUX_MEMREMAP_H_ |
| 3 | #include <linux/mm.h> |
| 4 | |
| 5 | struct resource; |
| 6 | struct device; |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame^] | 7 | |
| 8 | /** |
| 9 | * struct vmem_altmap - pre-allocated storage for vmemmap_populate |
| 10 | * @base_pfn: base of the entire dev_pagemap mapping |
| 11 | * @reserve: pages mapped, but reserved for driver use (relative to @base) |
| 12 | * @free: free pages set aside in the mapping for memmap storage |
| 13 | * @align: pages reserved to meet allocation alignments |
| 14 | * @alloc: track pages consumed, private to vmemmap_populate() |
| 15 | */ |
| 16 | struct vmem_altmap { |
| 17 | const unsigned long base_pfn; |
| 18 | const unsigned long reserve; |
| 19 | unsigned long free; |
| 20 | unsigned long align; |
| 21 | unsigned long alloc; |
| 22 | }; |
| 23 | |
| 24 | unsigned long vmem_altmap_offset(struct vmem_altmap *altmap); |
| 25 | void vmem_altmap_free(struct vmem_altmap *altmap, unsigned long nr_pfns); |
| 26 | |
| 27 | #if defined(CONFIG_SPARSEMEM_VMEMMAP) && defined(CONFIG_ZONE_DEVICE) |
| 28 | struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start); |
| 29 | #else |
| 30 | static inline struct vmem_altmap *to_vmem_altmap(unsigned long memmap_start) |
| 31 | { |
| 32 | return NULL; |
| 33 | } |
| 34 | #endif |
| 35 | |
Dan Williams | 9476df7 | 2016-01-15 16:56:19 -0800 | [diff] [blame] | 36 | /** |
| 37 | * struct dev_pagemap - metadata for ZONE_DEVICE mappings |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame^] | 38 | * @altmap: pre-allocated/reserved memory for vmemmap allocations |
Dan Williams | 9476df7 | 2016-01-15 16:56:19 -0800 | [diff] [blame] | 39 | * @dev: host device of the mapping for debug |
| 40 | */ |
| 41 | struct dev_pagemap { |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame^] | 42 | struct vmem_altmap *altmap; |
| 43 | const struct resource *res; |
Dan Williams | 9476df7 | 2016-01-15 16:56:19 -0800 | [diff] [blame] | 44 | struct device *dev; |
| 45 | }; |
| 46 | |
| 47 | #ifdef CONFIG_ZONE_DEVICE |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame^] | 48 | void *devm_memremap_pages(struct device *dev, struct resource *res, |
| 49 | struct vmem_altmap *altmap); |
Dan Williams | 9476df7 | 2016-01-15 16:56:19 -0800 | [diff] [blame] | 50 | struct dev_pagemap *find_dev_pagemap(resource_size_t phys); |
| 51 | #else |
| 52 | static inline void *devm_memremap_pages(struct device *dev, |
Dan Williams | 4b94ffd | 2016-01-15 16:56:22 -0800 | [diff] [blame^] | 53 | struct resource *res, struct vmem_altmap *altmap) |
Dan Williams | 9476df7 | 2016-01-15 16:56:19 -0800 | [diff] [blame] | 54 | { |
| 55 | /* |
| 56 | * Fail attempts to call devm_memremap_pages() without |
| 57 | * ZONE_DEVICE support enabled, this requires callers to fall |
| 58 | * back to plain devm_memremap() based on config |
| 59 | */ |
| 60 | WARN_ON_ONCE(1); |
| 61 | return ERR_PTR(-ENXIO); |
| 62 | } |
| 63 | |
| 64 | static inline struct dev_pagemap *find_dev_pagemap(resource_size_t phys) |
| 65 | { |
| 66 | return NULL; |
| 67 | } |
| 68 | #endif |
Dan Williams | 9476df7 | 2016-01-15 16:56:19 -0800 | [diff] [blame] | 69 | #endif /* _LINUX_MEMREMAP_H_ */ |