[PATCH 8/19] ppc64: Create a fake flat device tree on iSeries

Michael Ellerman michael at ellerman.id.au
Tue Jul 26 18:58:40 EST 2005


This patch adds infrastructure for creating a fake flattened device tree
on iSeries. This is very much work-in-progress and a bit hacky.

We also need to build prom.o for iSeries which means we'll always need it.

---

 arch/ppc64/kernel/Makefile        |    4 -
 arch/ppc64/kernel/iSeries_setup.c |  131 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 133 insertions(+), 2 deletions(-)

Index: work/arch/ppc64/kernel/iSeries_setup.c
===================================================================
--- work.orig/arch/ppc64/kernel/iSeries_setup.c
+++ work/arch/ppc64/kernel/iSeries_setup.c
@@ -940,6 +940,135 @@ struct machdep_calls __initdata iseries_
 	.progress	= iSeries_progress,
 };
 
+struct blob
+{
+	unsigned char data[PAGE_SIZE];
+	unsigned long next;
+};
+
+struct iseries_flat_dt
+{
+	struct boot_param_header header;
+	u64 reserve_map[2];
+	struct blob dt;
+	struct blob strings;
+};
+
+struct iseries_flat_dt iseries_dt;
+
+void dt_init(struct iseries_flat_dt *dt)
+{
+	unsigned char *dt_addr = (unsigned char *)dt;
+
+	dt->header.off_mem_rsvmap = (unsigned char *)&dt->reserve_map - dt_addr;
+	dt->header.off_dt_struct = (unsigned char *)&dt->dt - dt_addr;
+	dt->header.off_dt_strings = (unsigned char *)&dt->strings - dt_addr;
+	dt->header.totalsize = sizeof(*dt);
+
+	/* There is no notion of hardware cpu id on iSeries */
+	dt->header.boot_cpuid_phys = smp_processor_id();
+
+	dt->dt.next = (unsigned long)&dt->dt.data;
+	dt->strings.next = (unsigned long)&dt->strings.data;
+
+	dt->header.magic = OF_DT_HEADER;
+	dt->header.version = 0x2;
+	dt->header.last_comp_version = 0x2;
+
+	dt->reserve_map[0] = 0;
+	dt->reserve_map[1] = 0;
+}
+
+void dt_push_u32(struct iseries_flat_dt *dt, u32 value)
+{
+	*((u32*)dt->dt.next) = value;
+	dt->dt.next += sizeof(u32);
+	dt->dt.next = _ALIGN(dt->dt.next, sizeof(u32));
+	BUG_ON(dt->dt.next - (unsigned long)dt->dt.data > sizeof(dt->dt.data));
+}
+
+void dt_push_u64(struct iseries_flat_dt *dt, u64 value)
+{
+	*((u64*)dt->dt.next) = value;
+	dt->dt.next += sizeof(u64);
+	dt->dt.next = _ALIGN(dt->dt.next, sizeof(u64));
+	BUG_ON(dt->dt.next - (unsigned long)dt->dt.data > sizeof(dt->dt.data));
+}
+
+void dt_push_str(struct blob *blob, char *str)
+{
+	memcpy((char *)blob->next, str, strlen(str) + 1);
+	blob->next += strlen(str) + 1;
+	blob->next = _ALIGN(blob->next, 4);
+}
+
+#define str_offset(dt) (dt->strings.next - (unsigned long)&dt->strings)
+
+void dt_start_node(struct iseries_flat_dt *dt, char *name)
+{
+	dt_push_u32(dt, OF_DT_BEGIN_NODE);
+	dt_push_str(&dt->dt, name);
+}
+
+#define dt_end_node(dt) dt_push_u32(dt, OF_DT_END_NODE)
+
+void dt_prop(struct iseries_flat_dt *dt, char *name, char *data, int len)
+{
+	dt_push_u32(dt, OF_DT_PROP);
+
+	/* Length of the data */
+	dt_push_u32(dt, len);
+
+	/* The offset of the properties name in the string blob. */
+	dt_push_u32(dt, str_offset(dt));
+
+	/* The actual data. */
+	/* For versions below 16 the data is 4 or 8 byte aligned. */
+	dt->dt.next = _ALIGN(dt->dt.next, len >= 8 ? 8 : 4);
+	memcpy((char *)dt->dt.next, data, len);
+	dt->dt.next += len;
+	/* and then 4 byte aligned after the data. */
+	dt->dt.next = _ALIGN(dt->dt.next, 4);
+
+	/* Put the property name in the string blob. */
+	dt_push_str(&dt->strings, name);
+}
+
+void dt_prop_str(struct iseries_flat_dt *dt, char *name, char *data)
+{
+	dt_prop(dt, name, data, strlen(data) + 1); /* + 1 for NULL */
+}
+
+void dt_prop_u32(struct iseries_flat_dt *dt, char *name, u32 data)
+{
+	dt_prop(dt, name, (char *)&data, sizeof(u32));
+}
+
+void dt_prop_u64(struct iseries_flat_dt *dt, char *name, u64 data)
+{
+	dt_prop(dt, name, (char *)&data, sizeof(u64));
+}
+
+void dt_prop_u64_list(struct iseries_flat_dt *dt, char *name, u64 *data, int n)
+{
+	dt_prop(dt, name, (char *)data, sizeof(u64) * n);
+}
+
+void dt_prop_empty(struct iseries_flat_dt *dt, char *name)
+{
+	dt_prop(dt, name, NULL, 0);
+}
+
+void build_flat_dt(struct iseries_flat_dt *dt)
+{
+	dt_init(dt);
+
+	dt_start_node(dt, "/");
+	dt_end_node(dt);
+
+	dt_push_u32(dt, OF_DT_END);
+}
+
 void __init iSeries_early_setup(void)
 {
 	iSeries_fixup_klimit();
@@ -952,6 +1081,8 @@ void __init iSeries_early_setup(void)
 	 */
 	build_iSeries_Memory_Map();
 
+	build_flat_dt(&iseries_dt);
+
 	/* Bolt mappings for all of memory (or some if we've got a limit) */
 	iSeries_bolt_kernel(0, systemcfg->physicalMemorySize);
 }
Index: work/arch/ppc64/kernel/Makefile
===================================================================
--- work.orig/arch/ppc64/kernel/Makefile
+++ work/arch/ppc64/kernel/Makefile
@@ -11,7 +11,7 @@ obj-y               :=	setup.o entry.o t
 			udbg.o binfmt_elf32.o sys_ppc32.o ioctl32.o \
 			ptrace32.o signal32.o rtc.o init_task.o \
 			lmb.o cputable.o cpu_setup_power4.o idle_power4.o \
-			iommu.o sysfs.o vdso.o pmc.o
+			iommu.o sysfs.o vdso.o pmc.o prom.o
 obj-y += vdso32/ vdso64/
 
 obj-$(CONFIG_PPC_OF) +=	of_device.o
@@ -27,7 +27,7 @@ obj-$(CONFIG_PPC_ISERIES) += HvCall.o Hv
 			     mf.o HvLpEvent.o iSeries_proc.o iSeries_htab.o \
 			     iSeries_iommu.o
 
-obj-$(CONFIG_PPC_MULTIPLATFORM) += nvram.o i8259.o prom_init.o prom.o
+obj-$(CONFIG_PPC_MULTIPLATFORM) += nvram.o i8259.o prom_init.o
 
 obj-$(CONFIG_PPC_PSERIES) += pSeries_pci.o pSeries_lpar.o pSeries_hvCall.o \
 			     pSeries_nvram.o rtasd.o ras.o pSeries_reconfig.o \



More information about the Linuxppc64-dev mailing list