Skip to content

Commit 7ec632b

Browse files
author
pbrook
committed
Wean device tree code off phys_ram_base.
Signed-off-by: Paul Brook <[email protected]> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@7068 c046a42c-6fe2-441c-8c8c-71466251a162
1 parent 5c130f6 commit 7ec632b

File tree

4 files changed

+31
-25
lines changed

4 files changed

+31
-25
lines changed

device_tree.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,35 @@
2525

2626
#include <libfdt.h>
2727

28-
void *load_device_tree(const char *filename_path, void *load_addr)
28+
void *load_device_tree(const char *filename_path, int *sizep)
2929
{
30-
int dt_file_size;
30+
int dt_size;
3131
int dt_file_load_size;
3232
int new_dt_size;
3333
int ret;
34-
void *dt_file = NULL;
35-
void *fdt;
34+
void *fdt = NULL;
3635

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) {
3939
printf("Unable to get size of device tree file '%s'\n",
4040
filename_path);
4141
goto fail;
4242
}
4343

44+
/* Expand to 2x size to give enough room for manipulation. */
45+
dt_size *= 2;
4446
/* First allocate space in qemu for device tree */
45-
dt_file = qemu_mallocz(dt_file_size);
47+
fdt = qemu_mallocz(dt_size);
4648

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+
}
5355

54-
fdt = load_addr;
55-
ret = fdt_open_into(dt_file, fdt, new_dt_size);
56+
ret = fdt_open_into(fdt, fdt, dt_size);
5657
if (ret) {
5758
printf("Unable to copy device tree in memory\n");
5859
goto fail;
@@ -64,12 +65,11 @@ void *load_device_tree(const char *filename_path, void *load_addr)
6465
filename_path);
6566
goto fail;
6667
}
67-
/* free qemu memory with old device tree */
68-
qemu_free(dt_file);
68+
*sizep = dt_size;
6969
return fdt;
7070

7171
fail:
72-
qemu_free(dt_file);
72+
qemu_free(fdt);
7373
return NULL;
7474
}
7575

device_tree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#ifndef __DEVICE_TREE_H__
1515
#define __DEVICE_TREE_H__
1616

17-
void *load_device_tree(const char *filename_path, void *load_addr);
17+
void *load_device_tree(const char *filename_path, int *sizep);
1818

1919
int qemu_devtree_setprop(void *fdt, const char *node_path,
2020
const char *property, uint32_t *val_array, int size);

hw/ppc440_bamboo.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#define BINARY_DEVICE_TREE_FILE "bamboo.dtb"
2929

30-
static void *bamboo_load_device_tree(void *addr,
30+
static void *bamboo_load_device_tree(target_phys_addr_t addr,
3131
uint32_t ramsize,
3232
target_phys_addr_t initrd_base,
3333
target_phys_addr_t initrd_size,
@@ -37,6 +37,7 @@ static void *bamboo_load_device_tree(void *addr,
3737
#ifdef HAVE_FDT
3838
uint32_t mem_reg_property[] = { 0, 0, ramsize };
3939
char *path;
40+
int fdt_size;
4041
int pathlen;
4142
int ret;
4243

@@ -45,7 +46,7 @@ static void *bamboo_load_device_tree(void *addr,
4546

4647
snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
4748

48-
fdt = load_device_tree(path, addr);
49+
fdt = load_device_tree(path, &fdt_size);
4950
free(path);
5051
if (fdt == NULL)
5152
goto out;
@@ -75,6 +76,8 @@ static void *bamboo_load_device_tree(void *addr,
7576
if (kvm_enabled())
7677
kvmppc_fdt_update(fdt);
7778

79+
cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
80+
7881
out:
7982
#endif
8083

@@ -165,7 +168,7 @@ static void bamboo_init(ram_addr_t ram_size, int vga_ram_size,
165168
else
166169
dt_base = kernel_size + loadaddr;
167170

168-
fdt = bamboo_load_device_tree(phys_ram_base + dt_base, ram_size,
171+
fdt = bamboo_load_device_tree(dt_base, ram_size,
169172
initrd_base, initrd_size, kernel_cmdline);
170173
if (fdt == NULL) {
171174
fprintf(stderr, "couldn't load device tree\n");

hw/ppce500_mpc8544ds.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ static int mpc8544_copy_soc_cell(void *fdt, const char *node, const char *prop)
7171
}
7272
#endif
7373

74-
static void *mpc8544_load_device_tree(void *addr,
74+
static void *mpc8544_load_device_tree(target_phys_addr_t addr,
7575
uint32_t ramsize,
7676
target_phys_addr_t initrd_base,
7777
target_phys_addr_t initrd_size,
@@ -81,6 +81,7 @@ static void *mpc8544_load_device_tree(void *addr,
8181
#ifdef HAVE_FDT
8282
uint32_t mem_reg_property[] = {0, ramsize};
8383
char *path;
84+
int fdt_size;
8485
int pathlen;
8586
int ret;
8687

@@ -89,7 +90,7 @@ static void *mpc8544_load_device_tree(void *addr,
8990

9091
snprintf(path, pathlen, "%s/%s", bios_dir, BINARY_DEVICE_TREE_FILE);
9192

92-
fdt = load_device_tree(path, addr);
93+
fdt = load_device_tree(path, &fdt_size);
9394
qemu_free(path);
9495
if (fdt == NULL)
9596
goto out;
@@ -142,6 +143,8 @@ static void *mpc8544_load_device_tree(void *addr,
142143
mpc8544_copy_soc_cell(fdt, buf, "timebase-frequency");
143144
}
144145

146+
cpu_physical_memory_write (addr, (void *)fdt, fdt_size);
147+
145148
out:
146149
#endif
147150

@@ -259,7 +262,7 @@ static void mpc8544ds_init(ram_addr_t ram_size, int vga_ram_size,
259262

260263
/* If we're loading a kernel directly, we must load the device tree too. */
261264
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,
263266
initrd_base, initrd_size, kernel_cmdline);
264267
if (fdt == NULL) {
265268
fprintf(stderr, "couldn't load device tree\n");

0 commit comments

Comments
 (0)