diff options
-rw-r--r-- | Documentation/devicetree/bindings/memory.txt | 168 | ||||
-rw-r--r-- | arch/arm/mm/init.c | 3 | ||||
-rw-r--r-- | drivers/of/Kconfig | 6 | ||||
-rw-r--r-- | drivers/of/Makefile | 1 | ||||
-rw-r--r-- | drivers/of/base.c | 4 | ||||
-rw-r--r-- | drivers/of/fdt.c | 12 | ||||
-rw-r--r-- | drivers/of/of_reserved_mem.c | 173 | ||||
-rw-r--r-- | drivers/of/platform.c | 4 | ||||
-rw-r--r-- | include/linux/of_reserved_mem.h | 14 |
9 files changed, 1 insertions, 384 deletions
diff --git a/Documentation/devicetree/bindings/memory.txt b/Documentation/devicetree/bindings/memory.txt deleted file mode 100644 index eb2469365593..000000000000 --- a/Documentation/devicetree/bindings/memory.txt +++ /dev/null | |||
@@ -1,168 +0,0 @@ | |||
1 | *** Memory binding *** | ||
2 | |||
3 | The /memory node provides basic information about the address and size | ||
4 | of the physical memory. This node is usually filled or updated by the | ||
5 | bootloader, depending on the actual memory configuration of the given | ||
6 | hardware. | ||
7 | |||
8 | The memory layout is described by the following node: | ||
9 | |||
10 | / { | ||
11 | #address-cells = <(n)>; | ||
12 | #size-cells = <(m)>; | ||
13 | memory { | ||
14 | device_type = "memory"; | ||
15 | reg = <(baseaddr1) (size1) | ||
16 | (baseaddr2) (size2) | ||
17 | ... | ||
18 | (baseaddrN) (sizeN)>; | ||
19 | }; | ||
20 | ... | ||
21 | }; | ||
22 | |||
23 | A memory node follows the typical device tree rules for "reg" property: | ||
24 | n: number of cells used to store base address value | ||
25 | m: number of cells used to store size value | ||
26 | baseaddrX: defines a base address of the defined memory bank | ||
27 | sizeX: the size of the defined memory bank | ||
28 | |||
29 | |||
30 | More than one memory bank can be defined. | ||
31 | |||
32 | |||
33 | *** Reserved memory regions *** | ||
34 | |||
35 | In /memory/reserved-memory node one can create child nodes describing | ||
36 | particular reserved (excluded from normal use) memory regions. Such | ||
37 | memory regions are usually designed for the special usage by various | ||
38 | device drivers. A good example are contiguous memory allocations or | ||
39 | memory sharing with other operating system on the same hardware board. | ||
40 | Those special memory regions might depend on the board configuration and | ||
41 | devices used on the target system. | ||
42 | |||
43 | Parameters for each memory region can be encoded into the device tree | ||
44 | with the following convention: | ||
45 | |||
46 | [(label):] (name) { | ||
47 | compatible = "linux,contiguous-memory-region", "reserved-memory-region"; | ||
48 | reg = <(address) (size)>; | ||
49 | (linux,default-contiguous-region); | ||
50 | }; | ||
51 | |||
52 | compatible: one or more of: | ||
53 | - "linux,contiguous-memory-region" - enables binding of this | ||
54 | region to Contiguous Memory Allocator (special region for | ||
55 | contiguous memory allocations, shared with movable system | ||
56 | memory, Linux kernel-specific). | ||
57 | - "reserved-memory-region" - compatibility is defined, given | ||
58 | region is assigned for exclusive usage for by the respective | ||
59 | devices. | ||
60 | |||
61 | reg: standard property defining the base address and size of | ||
62 | the memory region | ||
63 | |||
64 | linux,default-contiguous-region: property indicating that the region | ||
65 | is the default region for all contiguous memory | ||
66 | allocations, Linux specific (optional) | ||
67 | |||
68 | It is optional to specify the base address, so if one wants to use | ||
69 | autoconfiguration of the base address, '0' can be specified as a base | ||
70 | address in the 'reg' property. | ||
71 | |||
72 | The /memory/reserved-memory node must contain the same #address-cells | ||
73 | and #size-cells value as the root node. | ||
74 | |||
75 | |||
76 | *** Device node's properties *** | ||
77 | |||
78 | Once regions in the /memory/reserved-memory node have been defined, they | ||
79 | may be referenced by other device nodes. Bindings that wish to reference | ||
80 | memory regions should explicitly document their use of the following | ||
81 | property: | ||
82 | |||
83 | memory-region = <&phandle_to_defined_region>; | ||
84 | |||
85 | This property indicates that the device driver should use the memory | ||
86 | region pointed by the given phandle. | ||
87 | |||
88 | |||
89 | *** Example *** | ||
90 | |||
91 | This example defines a memory consisting of 4 memory banks. 3 contiguous | ||
92 | regions are defined for Linux kernel, one default of all device drivers | ||
93 | (named contig_mem, placed at 0x72000000, 64MiB), one dedicated to the | ||
94 | framebuffer device (labelled display_mem, placed at 0x78000000, 8MiB) | ||
95 | and one for multimedia processing (labelled multimedia_mem, placed at | ||
96 | 0x77000000, 64MiB). 'display_mem' region is then assigned to fb@12300000 | ||
97 | device for DMA memory allocations (Linux kernel drivers will use CMA is | ||
98 | available or dma-exclusive usage otherwise). 'multimedia_mem' is | ||
99 | assigned to scaler@12500000 and codec@12600000 devices for contiguous | ||
100 | memory allocations when CMA driver is enabled. | ||
101 | |||
102 | The reason for creating a separate region for framebuffer device is to | ||
103 | match the framebuffer base address to the one configured by bootloader, | ||
104 | so once Linux kernel drivers starts no glitches on the displayed boot | ||
105 | logo appears. Scaller and codec drivers should share the memory | ||
106 | allocations. | ||
107 | |||
108 | / { | ||
109 | #address-cells = <1>; | ||
110 | #size-cells = <1>; | ||
111 | |||
112 | /* ... */ | ||
113 | |||
114 | memory { | ||
115 | reg = <0x40000000 0x10000000 | ||
116 | 0x50000000 0x10000000 | ||
117 | 0x60000000 0x10000000 | ||
118 | 0x70000000 0x10000000>; | ||
119 | |||
120 | reserved-memory { | ||
121 | #address-cells = <1>; | ||
122 | #size-cells = <1>; | ||
123 | |||
124 | /* | ||
125 | * global autoconfigured region for contiguous allocations | ||
126 | * (used only with Contiguous Memory Allocator) | ||
127 | */ | ||
128 | contig_region@0 { | ||
129 | compatible = "linux,contiguous-memory-region"; | ||
130 | reg = <0x0 0x4000000>; | ||
131 | linux,default-contiguous-region; | ||
132 | }; | ||
133 | |||
134 | /* | ||
135 | * special region for framebuffer | ||
136 | */ | ||
137 | display_region: region@78000000 { | ||
138 | compatible = "linux,contiguous-memory-region", "reserved-memory-region"; | ||
139 | reg = <0x78000000 0x800000>; | ||
140 | }; | ||
141 | |||
142 | /* | ||
143 | * special region for multimedia processing devices | ||
144 | */ | ||
145 | multimedia_region: region@77000000 { | ||
146 | compatible = "linux,contiguous-memory-region"; | ||
147 | reg = <0x77000000 0x4000000>; | ||
148 | }; | ||
149 | }; | ||
150 | }; | ||
151 | |||
152 | /* ... */ | ||
153 | |||
154 | fb0: fb@12300000 { | ||
155 | status = "okay"; | ||
156 | memory-region = <&display_region>; | ||
157 | }; | ||
158 | |||
159 | scaler: scaler@12500000 { | ||
160 | status = "okay"; | ||
161 | memory-region = <&multimedia_region>; | ||
162 | }; | ||
163 | |||
164 | codec: codec@12600000 { | ||
165 | status = "okay"; | ||
166 | memory-region = <&multimedia_region>; | ||
167 | }; | ||
168 | }; | ||
diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c index febaee7ca57b..18ec4c504abf 100644 --- a/arch/arm/mm/init.c +++ b/arch/arm/mm/init.c | |||
@@ -17,7 +17,6 @@ | |||
17 | #include <linux/nodemask.h> | 17 | #include <linux/nodemask.h> |
18 | #include <linux/initrd.h> | 18 | #include <linux/initrd.h> |
19 | #include <linux/of_fdt.h> | 19 | #include <linux/of_fdt.h> |
20 | #include <linux/of_reserved_mem.h> | ||
21 | #include <linux/highmem.h> | 20 | #include <linux/highmem.h> |
22 | #include <linux/gfp.h> | 21 | #include <linux/gfp.h> |
23 | #include <linux/memblock.h> | 22 | #include <linux/memblock.h> |
@@ -379,8 +378,6 @@ void __init arm_memblock_init(struct meminfo *mi, | |||
379 | if (mdesc->reserve) | 378 | if (mdesc->reserve) |
380 | mdesc->reserve(); | 379 | mdesc->reserve(); |
381 | 380 | ||
382 | early_init_dt_scan_reserved_mem(); | ||
383 | |||
384 | /* | 381 | /* |
385 | * reserve memory for DMA contigouos allocations, | 382 | * reserve memory for DMA contigouos allocations, |
386 | * must come from DMA area inside low memory | 383 | * must come from DMA area inside low memory |
diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index 9d2009a9004d..78cc76053328 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig | |||
@@ -74,10 +74,4 @@ config OF_MTD | |||
74 | depends on MTD | 74 | depends on MTD |
75 | def_bool y | 75 | def_bool y |
76 | 76 | ||
77 | config OF_RESERVED_MEM | ||
78 | depends on OF_FLATTREE && (DMA_CMA || (HAVE_GENERIC_DMA_COHERENT && HAVE_MEMBLOCK)) | ||
79 | def_bool y | ||
80 | help | ||
81 | Initialization code for DMA reserved memory | ||
82 | |||
83 | endmenu # OF | 77 | endmenu # OF |
diff --git a/drivers/of/Makefile b/drivers/of/Makefile index ed9660adad77..efd05102c405 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile | |||
@@ -9,4 +9,3 @@ obj-$(CONFIG_OF_MDIO) += of_mdio.o | |||
9 | obj-$(CONFIG_OF_PCI) += of_pci.o | 9 | obj-$(CONFIG_OF_PCI) += of_pci.o |
10 | obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o | 10 | obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o |
11 | obj-$(CONFIG_OF_MTD) += of_mtd.o | 11 | obj-$(CONFIG_OF_MTD) += of_mtd.o |
12 | obj-$(CONFIG_OF_RESERVED_MEM) += of_reserved_mem.o | ||
diff --git a/drivers/of/base.c b/drivers/of/base.c index 865d3f66c86b..7d4c70f859e3 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -303,10 +303,8 @@ struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) | |||
303 | struct device_node *cpun, *cpus; | 303 | struct device_node *cpun, *cpus; |
304 | 304 | ||
305 | cpus = of_find_node_by_path("/cpus"); | 305 | cpus = of_find_node_by_path("/cpus"); |
306 | if (!cpus) { | 306 | if (!cpus) |
307 | pr_warn("Missing cpus node, bailing out\n"); | ||
308 | return NULL; | 307 | return NULL; |
309 | } | ||
310 | 308 | ||
311 | for_each_child_of_node(cpus, cpun) { | 309 | for_each_child_of_node(cpus, cpun) { |
312 | if (of_node_cmp(cpun->type, "cpu")) | 310 | if (of_node_cmp(cpun->type, "cpu")) |
diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index 229dd9d69e18..a4fa9ad31b8f 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c | |||
@@ -18,7 +18,6 @@ | |||
18 | #include <linux/string.h> | 18 | #include <linux/string.h> |
19 | #include <linux/errno.h> | 19 | #include <linux/errno.h> |
20 | #include <linux/slab.h> | 20 | #include <linux/slab.h> |
21 | #include <linux/random.h> | ||
22 | 21 | ||
23 | #include <asm/setup.h> /* for COMMAND_LINE_SIZE */ | 22 | #include <asm/setup.h> /* for COMMAND_LINE_SIZE */ |
24 | #ifdef CONFIG_PPC | 23 | #ifdef CONFIG_PPC |
@@ -803,14 +802,3 @@ void __init unflatten_device_tree(void) | |||
803 | } | 802 | } |
804 | 803 | ||
805 | #endif /* CONFIG_OF_EARLY_FLATTREE */ | 804 | #endif /* CONFIG_OF_EARLY_FLATTREE */ |
806 | |||
807 | /* Feed entire flattened device tree into the random pool */ | ||
808 | static int __init add_fdt_randomness(void) | ||
809 | { | ||
810 | if (initial_boot_params) | ||
811 | add_device_randomness(initial_boot_params, | ||
812 | be32_to_cpu(initial_boot_params->totalsize)); | ||
813 | |||
814 | return 0; | ||
815 | } | ||
816 | core_initcall(add_fdt_randomness); | ||
diff --git a/drivers/of/of_reserved_mem.c b/drivers/of/of_reserved_mem.c deleted file mode 100644 index 0fe40c7d6904..000000000000 --- a/drivers/of/of_reserved_mem.c +++ /dev/null | |||
@@ -1,173 +0,0 @@ | |||
1 | /* | ||
2 | * Device tree based initialization code for reserved memory. | ||
3 | * | ||
4 | * Copyright (c) 2013 Samsung Electronics Co., Ltd. | ||
5 | * http://www.samsung.com | ||
6 | * Author: Marek Szyprowski <m.szyprowski@samsung.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU General Public License as | ||
10 | * published by the Free Software Foundation; either version 2 of the | ||
11 | * License or (at your optional) any later version of the license. | ||
12 | */ | ||
13 | |||
14 | #include <linux/memblock.h> | ||
15 | #include <linux/err.h> | ||
16 | #include <linux/of.h> | ||
17 | #include <linux/of_fdt.h> | ||
18 | #include <linux/of_platform.h> | ||
19 | #include <linux/mm.h> | ||
20 | #include <linux/sizes.h> | ||
21 | #include <linux/mm_types.h> | ||
22 | #include <linux/dma-contiguous.h> | ||
23 | #include <linux/dma-mapping.h> | ||
24 | #include <linux/of_reserved_mem.h> | ||
25 | |||
26 | #define MAX_RESERVED_REGIONS 16 | ||
27 | struct reserved_mem { | ||
28 | phys_addr_t base; | ||
29 | unsigned long size; | ||
30 | struct cma *cma; | ||
31 | char name[32]; | ||
32 | }; | ||
33 | static struct reserved_mem reserved_mem[MAX_RESERVED_REGIONS]; | ||
34 | static int reserved_mem_count; | ||
35 | |||
36 | static int __init fdt_scan_reserved_mem(unsigned long node, const char *uname, | ||
37 | int depth, void *data) | ||
38 | { | ||
39 | struct reserved_mem *rmem = &reserved_mem[reserved_mem_count]; | ||
40 | phys_addr_t base, size; | ||
41 | int is_cma, is_reserved; | ||
42 | unsigned long len; | ||
43 | const char *status; | ||
44 | __be32 *prop; | ||
45 | |||
46 | is_cma = IS_ENABLED(CONFIG_DMA_CMA) && | ||
47 | of_flat_dt_is_compatible(node, "linux,contiguous-memory-region"); | ||
48 | is_reserved = of_flat_dt_is_compatible(node, "reserved-memory-region"); | ||
49 | |||
50 | if (!is_reserved && !is_cma) { | ||
51 | /* ignore node and scan next one */ | ||
52 | return 0; | ||
53 | } | ||
54 | |||
55 | status = of_get_flat_dt_prop(node, "status", &len); | ||
56 | if (status && strcmp(status, "okay") != 0) { | ||
57 | /* ignore disabled node nad scan next one */ | ||
58 | return 0; | ||
59 | } | ||
60 | |||
61 | prop = of_get_flat_dt_prop(node, "reg", &len); | ||
62 | if (!prop || (len < (dt_root_size_cells + dt_root_addr_cells) * | ||
63 | sizeof(__be32))) { | ||
64 | pr_err("Reserved mem: node %s, incorrect \"reg\" property\n", | ||
65 | uname); | ||
66 | /* ignore node and scan next one */ | ||
67 | return 0; | ||
68 | } | ||
69 | base = dt_mem_next_cell(dt_root_addr_cells, &prop); | ||
70 | size = dt_mem_next_cell(dt_root_size_cells, &prop); | ||
71 | |||
72 | if (!size) { | ||
73 | /* ignore node and scan next one */ | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | pr_info("Reserved mem: found %s, memory base %lx, size %ld MiB\n", | ||
78 | uname, (unsigned long)base, (unsigned long)size / SZ_1M); | ||
79 | |||
80 | if (reserved_mem_count == ARRAY_SIZE(reserved_mem)) | ||
81 | return -ENOSPC; | ||
82 | |||
83 | rmem->base = base; | ||
84 | rmem->size = size; | ||
85 | strlcpy(rmem->name, uname, sizeof(rmem->name)); | ||
86 | |||
87 | if (is_cma) { | ||
88 | struct cma *cma; | ||
89 | if (dma_contiguous_reserve_area(size, base, 0, &cma) == 0) { | ||
90 | rmem->cma = cma; | ||
91 | reserved_mem_count++; | ||
92 | if (of_get_flat_dt_prop(node, | ||
93 | "linux,default-contiguous-region", | ||
94 | NULL)) | ||
95 | dma_contiguous_set_default(cma); | ||
96 | } | ||
97 | } else if (is_reserved) { | ||
98 | if (memblock_remove(base, size) == 0) | ||
99 | reserved_mem_count++; | ||
100 | else | ||
101 | pr_err("Failed to reserve memory for %s\n", uname); | ||
102 | } | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static struct reserved_mem *get_dma_memory_region(struct device *dev) | ||
108 | { | ||
109 | struct device_node *node; | ||
110 | const char *name; | ||
111 | int i; | ||
112 | |||
113 | node = of_parse_phandle(dev->of_node, "memory-region", 0); | ||
114 | if (!node) | ||
115 | return NULL; | ||
116 | |||
117 | name = kbasename(node->full_name); | ||
118 | for (i = 0; i < reserved_mem_count; i++) | ||
119 | if (strcmp(name, reserved_mem[i].name) == 0) | ||
120 | return &reserved_mem[i]; | ||
121 | return NULL; | ||
122 | } | ||
123 | |||
124 | /** | ||
125 | * of_reserved_mem_device_init() - assign reserved memory region to given device | ||
126 | * | ||
127 | * This function assign memory region pointed by "memory-region" device tree | ||
128 | * property to the given device. | ||
129 | */ | ||
130 | void of_reserved_mem_device_init(struct device *dev) | ||
131 | { | ||
132 | struct reserved_mem *region = get_dma_memory_region(dev); | ||
133 | if (!region) | ||
134 | return; | ||
135 | |||
136 | if (region->cma) { | ||
137 | dev_set_cma_area(dev, region->cma); | ||
138 | pr_info("Assigned CMA %s to %s device\n", region->name, | ||
139 | dev_name(dev)); | ||
140 | } else { | ||
141 | if (dma_declare_coherent_memory(dev, region->base, region->base, | ||
142 | region->size, DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) != 0) | ||
143 | pr_info("Declared reserved memory %s to %s device\n", | ||
144 | region->name, dev_name(dev)); | ||
145 | } | ||
146 | } | ||
147 | |||
148 | /** | ||
149 | * of_reserved_mem_device_release() - release reserved memory device structures | ||
150 | * | ||
151 | * This function releases structures allocated for memory region handling for | ||
152 | * the given device. | ||
153 | */ | ||
154 | void of_reserved_mem_device_release(struct device *dev) | ||
155 | { | ||
156 | struct reserved_mem *region = get_dma_memory_region(dev); | ||
157 | if (!region && !region->cma) | ||
158 | dma_release_declared_memory(dev); | ||
159 | } | ||
160 | |||
161 | /** | ||
162 | * early_init_dt_scan_reserved_mem() - create reserved memory regions | ||
163 | * | ||
164 | * This function grabs memory from early allocator for device exclusive use | ||
165 | * defined in device tree structures. It should be called by arch specific code | ||
166 | * once the early allocator (memblock) has been activated and all other | ||
167 | * subsystems have already allocated/reserved memory. | ||
168 | */ | ||
169 | void __init early_init_dt_scan_reserved_mem(void) | ||
170 | { | ||
171 | of_scan_flat_dt_by_path("/memory/reserved-memory", | ||
172 | fdt_scan_reserved_mem, NULL); | ||
173 | } | ||
diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 9b439ac63d8e..f6dcde220821 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c | |||
@@ -21,7 +21,6 @@ | |||
21 | #include <linux/of_device.h> | 21 | #include <linux/of_device.h> |
22 | #include <linux/of_irq.h> | 22 | #include <linux/of_irq.h> |
23 | #include <linux/of_platform.h> | 23 | #include <linux/of_platform.h> |
24 | #include <linux/of_reserved_mem.h> | ||
25 | #include <linux/platform_device.h> | 24 | #include <linux/platform_device.h> |
26 | 25 | ||
27 | const struct of_device_id of_default_bus_match_table[] = { | 26 | const struct of_device_id of_default_bus_match_table[] = { |
@@ -219,8 +218,6 @@ static struct platform_device *of_platform_device_create_pdata( | |||
219 | dev->dev.bus = &platform_bus_type; | 218 | dev->dev.bus = &platform_bus_type; |
220 | dev->dev.platform_data = platform_data; | 219 | dev->dev.platform_data = platform_data; |
221 | 220 | ||
222 | of_reserved_mem_device_init(&dev->dev); | ||
223 | |||
224 | /* We do not fill the DMA ops for platform devices by default. | 221 | /* We do not fill the DMA ops for platform devices by default. |
225 | * This is currently the responsibility of the platform code | 222 | * This is currently the responsibility of the platform code |
226 | * to do such, possibly using a device notifier | 223 | * to do such, possibly using a device notifier |
@@ -228,7 +225,6 @@ static struct platform_device *of_platform_device_create_pdata( | |||
228 | 225 | ||
229 | if (of_device_add(dev) != 0) { | 226 | if (of_device_add(dev) != 0) { |
230 | platform_device_put(dev); | 227 | platform_device_put(dev); |
231 | of_reserved_mem_device_release(&dev->dev); | ||
232 | return NULL; | 228 | return NULL; |
233 | } | 229 | } |
234 | 230 | ||
diff --git a/include/linux/of_reserved_mem.h b/include/linux/of_reserved_mem.h deleted file mode 100644 index c84128255814..000000000000 --- a/include/linux/of_reserved_mem.h +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | #ifndef __OF_RESERVED_MEM_H | ||
2 | #define __OF_RESERVED_MEM_H | ||
3 | |||
4 | #ifdef CONFIG_OF_RESERVED_MEM | ||
5 | void of_reserved_mem_device_init(struct device *dev); | ||
6 | void of_reserved_mem_device_release(struct device *dev); | ||
7 | void early_init_dt_scan_reserved_mem(void); | ||
8 | #else | ||
9 | static inline void of_reserved_mem_device_init(struct device *dev) { } | ||
10 | static inline void of_reserved_mem_device_release(struct device *dev) { } | ||
11 | static inline void early_init_dt_scan_reserved_mem(void) { } | ||
12 | #endif | ||
13 | |||
14 | #endif /* __OF_RESERVED_MEM_H */ | ||