Commit 7ec632b45c223bc6a01a8f5a6549854e8624b0c0
1 parent
5c130f65
Wean device tree code off phys_ram_base.
Signed-off-by: Paul Brook <paul@codesourcery.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7068 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
4 changed files
with
31 additions
and
25 deletions
device_tree.c
... | ... | @@ -25,34 +25,35 @@ |
25 | 25 | |
26 | 26 | #include <libfdt.h> |
27 | 27 | |
28 | -void *load_device_tree(const char *filename_path, void *load_addr) | |
28 | +void *load_device_tree(const char *filename_path, int *sizep) | |
29 | 29 | { |
30 | - int dt_file_size; | |
30 | + int dt_size; | |
31 | 31 | int dt_file_load_size; |
32 | 32 | int new_dt_size; |
33 | 33 | int ret; |
34 | - void *dt_file = NULL; | |
35 | - void *fdt; | |
34 | + void *fdt = NULL; | |
36 | 35 | |
37 | - dt_file_size = get_image_size(filename_path); | |
38 | - if (dt_file_size < 0) { | |
36 | + *sizep = 0; | |
37 | + dt_size = get_image_size(filename_path); | |
38 | + if (dt_size < 0) { | |
39 | 39 | printf("Unable to get size of device tree file '%s'\n", |
40 | 40 | filename_path); |
41 | 41 | goto fail; |
42 | 42 | } |
43 | 43 | |
44 | + /* Expand to 2x size to give enough room for manipulation. */ | |
45 | + dt_size *= 2; | |
44 | 46 | /* First allocate space in qemu for device tree */ |
45 | - dt_file = qemu_mallocz(dt_file_size); | |
47 | + fdt = qemu_mallocz(dt_size); | |
46 | 48 | |
47 | - dt_file_load_size = load_image(filename_path, dt_file); | |
48 | - | |
49 | - /* Second we place new copy of 2x size in guest memory | |
50 | - * This give us enough room for manipulation. | |
51 | - */ | |
52 | - new_dt_size = dt_file_size * 2; | |
49 | + dt_file_load_size = load_image(filename_path, fdt); | |
50 | + if (dt_file_load_size < 0) { | |
51 | + printf("Unable to open device tree file '%s'\n", | |
52 | + filename_path); | |
53 | + goto fail; | |
54 | + } | |
53 | 55 | |
54 | - fdt = load_addr; | |
55 | - ret = fdt_open_into(dt_file, fdt, new_dt_size); | |
56 | + ret = fdt_open_into(fdt, fdt, dt_size); | |
56 | 57 | if (ret) { |
57 | 58 | printf("Unable to copy device tree in memory\n"); |
58 | 59 | goto fail; |
... | ... | @@ -64,12 +65,11 @@ void *load_device_tree(const char *filename_path, void *load_addr) |
64 | 65 | filename_path); |
65 | 66 | goto fail; |
66 | 67 | } |
67 | - /* free qemu memory with old device tree */ | |
68 | - qemu_free(dt_file); | |
68 | + *sizep = dt_size; | |
69 | 69 | return fdt; |
70 | 70 | |
71 | 71 | fail: |
72 | - qemu_free(dt_file); | |
72 | + qemu_free(fdt); | |
73 | 73 | return NULL; |
74 | 74 | } |
75 | 75 | ... | ... |
device_tree.h
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | #ifndef __DEVICE_TREE_H__ |
15 | 15 | #define __DEVICE_TREE_H__ |
16 | 16 | |
17 | -void *load_device_tree(const char *filename_path, void *load_addr); | |
17 | +void *load_device_tree(const char *filename_path, int *sizep); | |
18 | 18 | |
19 | 19 | int qemu_devtree_setprop(void *fdt, const char *node_path, |
20 | 20 | const char *property, uint32_t *val_array, int size); | ... | ... |
hw/ppc440_bamboo.c
... | ... | @@ -27,7 +27,7 @@ |
27 | 27 | |
28 | 28 | #define BINARY_DEVICE_TREE_FILE "bamboo.dtb" |
29 | 29 | |
30 | -static void *bamboo_load_device_tree(void *addr, | |
30 | +static void *bamboo_load_device_tree(target_phys_addr_t addr, | |
31 | 31 | uint32_t ramsize, |
32 | 32 | target_phys_addr_t initrd_base, |
33 | 33 | target_phys_addr_t initrd_size, |
... | ... | @@ -37,6 +37,7 @@ static void *bamboo_load_device_tree(void *addr, |
37 | 37 | #ifdef HAVE_FDT |
38 | 38 | uint32_t mem_reg_property[] = { 0, 0, ramsize }; |
39 | 39 | char *path; |
40 | + int fdt_size; | |
40 | 41 | int pathlen; |
41 | 42 | int ret; |
42 | 43 | |
... | ... | @@ -45,7 +46,7 @@ static void *bamboo_load_device_tree(void *addr, |
45 | 46 | |
46 | 47 | snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE); |
47 | 48 | |
48 | - fdt = load_device_tree(path, addr); | |
49 | + fdt = load_device_tree(path, &fdt_size); | |
49 | 50 | free(path); |
50 | 51 | if (fdt == NULL) |
51 | 52 | goto out; |
... | ... | @@ -75,6 +76,8 @@ static void *bamboo_load_device_tree(void *addr, |
75 | 76 | if (kvm_enabled()) |
76 | 77 | kvmppc_fdt_update(fdt); |
77 | 78 | |
79 | + cpu_physical_memory_write (addr, (void *)fdt, fdt_size); | |
80 | + | |
78 | 81 | out: |
79 | 82 | #endif |
80 | 83 | |
... | ... | @@ -165,7 +168,7 @@ static void bamboo_init(ram_addr_t ram_size, int vga_ram_size, |
165 | 168 | else |
166 | 169 | dt_base = kernel_size + loadaddr; |
167 | 170 | |
168 | - fdt = bamboo_load_device_tree(phys_ram_base + dt_base, ram_size, | |
171 | + fdt = bamboo_load_device_tree(dt_base, ram_size, | |
169 | 172 | initrd_base, initrd_size, kernel_cmdline); |
170 | 173 | if (fdt == NULL) { |
171 | 174 | fprintf(stderr, "couldn't load device tree\n"); | ... | ... |
hw/ppce500_mpc8544ds.c
... | ... | @@ -71,7 +71,7 @@ out: |
71 | 71 | } |
72 | 72 | #endif |
73 | 73 | |
74 | -static void *mpc8544_load_device_tree(void *addr, | |
74 | +static void *mpc8544_load_device_tree(target_phys_addr_t addr, | |
75 | 75 | uint32_t ramsize, |
76 | 76 | target_phys_addr_t initrd_base, |
77 | 77 | target_phys_addr_t initrd_size, |
... | ... | @@ -81,6 +81,7 @@ static void *mpc8544_load_device_tree(void *addr, |
81 | 81 | #ifdef HAVE_FDT |
82 | 82 | uint32_t mem_reg_property[] = {0, ramsize}; |
83 | 83 | char *path; |
84 | + int fdt_size; | |
84 | 85 | int pathlen; |
85 | 86 | int ret; |
86 | 87 | |
... | ... | @@ -89,7 +90,7 @@ static void *mpc8544_load_device_tree(void *addr, |
89 | 90 | |
90 | 91 | snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE); |
91 | 92 | |
92 | - fdt = load_device_tree(path, addr); | |
93 | + fdt = load_device_tree(path, &fdt_size); | |
93 | 94 | qemu_free(path); |
94 | 95 | if (fdt == NULL) |
95 | 96 | goto out; |
... | ... | @@ -142,6 +143,8 @@ static void *mpc8544_load_device_tree(void *addr, |
142 | 143 | mpc8544_copy_soc_cell(fdt, buf, "timebase-frequency"); |
143 | 144 | } |
144 | 145 | |
146 | + cpu_physical_memory_write (addr, (void *)fdt, fdt_size); | |
147 | + | |
145 | 148 | out: |
146 | 149 | #endif |
147 | 150 | |
... | ... | @@ -259,7 +262,7 @@ static void mpc8544ds_init(ram_addr_t ram_size, int vga_ram_size, |
259 | 262 | |
260 | 263 | /* If we're loading a kernel directly, we must load the device tree too. */ |
261 | 264 | if (kernel_filename) { |
262 | - fdt = mpc8544_load_device_tree(phys_ram_base + dt_base, ram_size, | |
265 | + fdt = mpc8544_load_device_tree(dt_base, ram_size, | |
263 | 266 | initrd_base, initrd_size, kernel_cmdline); |
264 | 267 | if (fdt == NULL) { |
265 | 268 | fprintf(stderr, "couldn't load device tree\n"); | ... | ... |