Author: blueswirl Date: 2009-05-22 19:14:10 +0200 (Fri, 22 May 2009) New Revision: 493
Modified: trunk/openbios-devel/drivers/pci.c trunk/openbios-devel/forth/device/package.fs trunk/openbios-devel/include/openbios/bindings.h trunk/openbios-devel/modules/bindings.c Log: Fix regprop int encoding (Igor Kovalenko)
Wrong encoding of "#address-cells" property can lead to a failure fetching correct value in my-#acells method. According to docs properties must be encoded with "encode-int". I spent some time looking at the docs and it is clear that encode-int produces quad-sized result (of size /l bytes).
This patch fixes pci helpers to encode to 32bit instead of 64bit values, and correctes my-address and my-unit methods to read 32bit data to match encode-int rules modules/bindings.c: also fixed set_int_property and get_int_property to match encode-int rules
Signed-off-by: Igor Kovalenko igor.v.kovalenko@gmail.com
Modified: trunk/openbios-devel/drivers/pci.c =================================================================== --- trunk/openbios-devel/drivers/pci.c 2009-05-22 17:09:52 UTC (rev 492) +++ trunk/openbios-devel/drivers/pci.c 2009-05-22 17:14:10 UTC (rev 493) @@ -52,7 +52,7 @@ MEMORY_SPACE_64 = 3, };
-static inline void pci_encode_phys_addr(cell *phys, int flags, int space_code, +static inline void pci_encode_phys_addr(u32 *phys, int flags, int space_code, pci_addr dev, uint8_t reg, uint64_t addr) {
@@ -174,27 +174,27 @@ static void pci_set_bus_range(const pci_config_t *config) { phandle_t dev = get_cur_dev(); - cell props[2]; + u32 props[2];
props[0] = (config->dev >> 16) & 0xFF; props[1] = 1; - set_property(dev, "bus-range", (char *)props, 2 * sizeof(cell)); + set_property(dev, "bus-range", (char *)props, 2 * sizeof(props[0])); }
static void pci_host_set_reg(const pci_config_t *config) { phandle_t dev = get_cur_dev(); - cell props[2]; + u32 props[2];
props[0] = arch->cfg_base; props[1] = arch->cfg_len; - set_property(dev, "reg", (char *)props, 2 * sizeof(cell)); + set_property(dev, "reg", (char *)props, 2 * sizeof(props[0])); }
static void pci_host_set_ranges(const pci_config_t *config) { phandle_t dev = get_cur_dev(); - cell props[32]; + u32 props[32]; int ncells;
ncells = 0; @@ -222,7 +222,7 @@ props[ncells++] = 0x00000000; props[ncells++] = arch->mem_len; } - set_property(dev, "ranges", (char *)props, ncells * sizeof(cell)); + set_property(dev, "ranges", (char *)props, ncells * sizeof(props[0])); }
int host_config_cb(const pci_config_t *config) @@ -234,6 +234,7 @@ set_property(aliases, "pci", config->path, strlen(config->path) + 1);
+ //XXX this overrides "reg" property pci_host_set_reg(config); pci_host_set_ranges(config); pci_set_bus_range(config); @@ -265,7 +266,7 @@
int eth_config_cb (const pci_config_t *config) { - phandle_t ph = get_cur_dev();; + phandle_t ph = get_cur_dev();
set_property(ph, "network-type", "ethernet", 9); set_property(ph, "removable", "network", 8); @@ -325,7 +326,7 @@ static void pci_set_assigned_addresses(const pci_config_t *config) { phandle_t dev = get_cur_dev(); - cell props[32]; + u32 props[32]; int ncells; int i; uint32_t mask; @@ -349,13 +350,13 @@ } if (ncells) set_property(dev, "assigned-addresses", (char *)props, - ncells * sizeof(cell)); + ncells * sizeof(props[0])); }
static void pci_set_reg(const pci_config_t *config) { phandle_t dev = get_cur_dev(); - cell props[38]; + u32 props[38]; int ncells; int i; uint32_t mask; @@ -387,14 +388,14 @@ props[ncells++] = 0x00000000; props[ncells++] = config->sizes[i]; } - set_property(dev, "reg", (char *)props, ncells * sizeof(cell)); + set_property(dev, "reg", (char *)props, ncells * sizeof(props[0])); }
static void pci_set_ranges(const pci_config_t *config) { phandle_t dev = get_cur_dev(); - cell props[32]; + u32 props[32]; int ncells; int i; uint32_t mask; @@ -423,7 +424,7 @@
props[ncells++] = config->sizes[i]; } - set_property(dev, "ranges", (char *)props, ncells * sizeof(cell)); + set_property(dev, "ranges", (char *)props, ncells * sizeof(props[0])); }
int macio_heathrow_config_cb (const pci_config_t *config)
Modified: trunk/openbios-devel/forth/device/package.fs =================================================================== --- trunk/openbios-devel/forth/device/package.fs 2009-05-22 17:09:52 UTC (rev 492) +++ trunk/openbios-devel/forth/device/package.fs 2009-05-22 17:14:10 UTC (rev 493) @@ -175,9 +175,9 @@ : my-address ( -- phys.lo ... ) ?my-self >in.device-node @
dn.probe-addr
- my-#acells tuck cells + swap 1- 0 + my-#acells tuck /l* + swap 1- 0 ?do - cell - dup @ swap + /l - dup l@ swap loop drop ; @@ -189,8 +189,8 @@
: my-unit ( -- phys.lo ... phys.hi ) ?my-self >in.my-unit - my-#acells tuck cells + swap 0 ?do - cell - dup @ swap + my-#acells tuck /l* + swap 0 ?do + /l - dup l@ swap loop drop ;
Modified: trunk/openbios-devel/include/openbios/bindings.h =================================================================== --- trunk/openbios-devel/include/openbios/bindings.h 2009-05-22 17:09:52 UTC (rev 492) +++ trunk/openbios-devel/include/openbios/bindings.h 2009-05-22 17:14:10 UTC (rev 493) @@ -61,8 +61,8 @@ extern void set_property( phandle_t ph, const char *name, const char *buf, int len ); extern void set_int_property( phandle_t ph, const char *name, - cell val ); -extern cell get_int_property( phandle_t ph, const char *name, + u32 val ); +extern u32 get_int_property( phandle_t ph, const char *name, int *retlen ); extern char *get_property( phandle_t ph, const char *name, int *retlen );
Modified: trunk/openbios-devel/modules/bindings.c =================================================================== --- trunk/openbios-devel/modules/bindings.c 2009-05-22 17:09:52 UTC (rev 492) +++ trunk/openbios-devel/modules/bindings.c 2009-05-22 17:14:10 UTC (rev 493) @@ -287,10 +287,10 @@ }
void -set_int_property( phandle_t ph, const char *name, cell val ) +set_int_property( phandle_t ph, const char *name, u32 val ) { - cell swapped=__cpu_to_becell(val); - set_property( ph, name, (char*)&swapped, sizeof(cell) ); + u32 swapped=__cpu_to_be32(val); + set_property( ph, name, (char*)&swapped, sizeof(swapped) ); }
char * @@ -312,14 +312,14 @@ return (char*)POP(); }
-cell +u32 get_int_property( phandle_t ph, const char *name, int *retlen ) { - cell *p; + u32 *p;
- if( !(p=(cell *)get_property(ph, name, retlen)) ) + if( !(p=(u32 *)get_property(ph, name, retlen)) ) return 0; - return __becell_to_cpu(*p); + return __be32_to_cpu(*p); }