Add a flags field to struct dev_pagemap to replace the altmap_valid boolean to be a little more extensible. Also add a pgmap_altmap() helper to find the optional altmap and clean up the code using the altmap using it.
Showing the changes to include/linux (1 of 9 files). Show all
Unified · Split
| @@ -88,6 +88,8 @@ struct dev_pagemap_ops { · 87 unmodified lines | ||
| 88 | 88 | vm_fault_t (*migrate_to_ram)(struct vm_fault *vmf); |
| 89 | 89 | }; |
| 90 | 90 | |
| 91 | +#define PGMAP_ALTMAP_VALID (1 << 0) | |
| 92 | + | |
| 91 | 93 | /** |
| 92 | 94 | * struct dev_pagemap - metadata for ZONE_DEVICE mappings |
| 93 | 95 | * @altmap: pre-allocated/reserved memory for vmemmap allocations |
| @@ -96,19 +98,27 @@ struct dev_pagemap_ops { · 2 unmodified lines | ||
| 96 | 98 | * @dev: host device of the mapping for debug |
| 97 | 99 | * @data: private data pointer for page_free() |
| 98 | 100 | * @type: memory type: see MEMORY_* in memory_hotplug.h |
| 101 | + * @flags: PGMAP_* flags to specify defailed behavior | |
| 99 | 102 | * @ops: method table |
| 100 | 103 | */ |
| 101 | 104 | struct dev_pagemap { |
| 102 | 105 | struct vmem_altmap altmap; |
| 103 | − bool altmap_valid; | |
| 104 | 106 | struct resource res; |
| 105 | 107 | struct percpu_ref *ref; |
| 106 | 108 | struct device *dev; |
| 107 | 109 | enum memory_type type; |
| 110 | + unsigned int flags; | |
| 108 | 111 | u64 pci_p2pdma_bus_offset; |
| 109 | 112 | const struct dev_pagemap_ops *ops; |
| 110 | 113 | }; |
| 111 | 114 | |
| 115 | +static inline struct vmem_altmap *pgmap_altmap(struct dev_pagemap *pgmap) | |
| 116 | +{ | |
| 117 | + if (pgmap->flags & PGMAP_ALTMAP_VALID) | |
| 118 | + return &pgmap->altmap; | |
| 119 | + return NULL; | |
| 120 | +} | |
| 121 | + | |
| 112 | 122 | #ifdef CONFIG_ZONE_DEVICE |
| 113 | 123 | void *devm_memremap_pages(struct device *dev, struct dev_pagemap *pgmap); |
| 114 | 124 | void devm_memunmap_pages(struct device *dev, struct dev_pagemap *pgmap); |