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

David Gibson david at gibson.dropbear.id.au
Wed Jul 27 12:04:04 EST 2005


On Tue, Jul 26, 2005 at 06:58:40PM +1000, Michael Ellerman wrote:
> 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
> +{

{ generally goes on the same line as the struct name.

> +	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;

The offsetof macro would make these a little cleaner.

> +	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));

If you need an ALIGN here at all, surely it should go before you emit
the value.

> +	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));

Again, I don't see that u64 aligning, after the value makes any sense.

> +	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);

I think having the str_offset() and adding the name to the string
section separated a little confusing.  Better to have a function which
adds the string to the string section and returns the appropriate
offset (there's one like this in dtc).  That also makes the change to
add name-combining (if it's worth it) more localised.

> +}
> +
> +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 \
> _______________________________________________
> Linuxppc64-dev mailing list
> Linuxppc64-dev at ozlabs.org
> https://ozlabs.org/mailman/listinfo/linuxppc64-dev
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/people/dgibson



More information about the Linuxppc64-dev mailing list