mirror of
https://gitlab.com/qemu-project/openbios.git
synced 2024-02-13 08:34:06 +08:00
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> git-svn-id: svn://coreboot.org/openbios/trunk/openbios-devel@493 f158a5a8-5612-0410-a976-696ce0be7e32
This commit is contained in:
committed by
Blue Swirl
parent
0ba0e77ecd
commit
02130e8240
@@ -52,7 +52,7 @@ enum {
|
|||||||
MEMORY_SPACE_64 = 3,
|
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)
|
pci_addr dev, uint8_t reg, uint64_t addr)
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -174,27 +174,27 @@ NODE_METHODS(ob_pci_simple_node) = {
|
|||||||
static void pci_set_bus_range(const pci_config_t *config)
|
static void pci_set_bus_range(const pci_config_t *config)
|
||||||
{
|
{
|
||||||
phandle_t dev = get_cur_dev();
|
phandle_t dev = get_cur_dev();
|
||||||
cell props[2];
|
u32 props[2];
|
||||||
|
|
||||||
props[0] = (config->dev >> 16) & 0xFF;
|
props[0] = (config->dev >> 16) & 0xFF;
|
||||||
props[1] = 1;
|
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)
|
static void pci_host_set_reg(const pci_config_t *config)
|
||||||
{
|
{
|
||||||
phandle_t dev = get_cur_dev();
|
phandle_t dev = get_cur_dev();
|
||||||
cell props[2];
|
u32 props[2];
|
||||||
|
|
||||||
props[0] = arch->cfg_base;
|
props[0] = arch->cfg_base;
|
||||||
props[1] = arch->cfg_len;
|
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)
|
static void pci_host_set_ranges(const pci_config_t *config)
|
||||||
{
|
{
|
||||||
phandle_t dev = get_cur_dev();
|
phandle_t dev = get_cur_dev();
|
||||||
cell props[32];
|
u32 props[32];
|
||||||
int ncells;
|
int ncells;
|
||||||
|
|
||||||
ncells = 0;
|
ncells = 0;
|
||||||
@@ -222,7 +222,7 @@ static void pci_host_set_ranges(const pci_config_t *config)
|
|||||||
props[ncells++] = 0x00000000;
|
props[ncells++] = 0x00000000;
|
||||||
props[ncells++] = arch->mem_len;
|
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)
|
int host_config_cb(const pci_config_t *config)
|
||||||
@@ -234,6 +234,7 @@ int host_config_cb(const pci_config_t *config)
|
|||||||
set_property(aliases, "pci",
|
set_property(aliases, "pci",
|
||||||
config->path, strlen(config->path) + 1);
|
config->path, strlen(config->path) + 1);
|
||||||
|
|
||||||
|
//XXX this overrides "reg" property
|
||||||
pci_host_set_reg(config);
|
pci_host_set_reg(config);
|
||||||
pci_host_set_ranges(config);
|
pci_host_set_ranges(config);
|
||||||
pci_set_bus_range(config);
|
pci_set_bus_range(config);
|
||||||
@@ -265,7 +266,7 @@ int ide_config_cb2 (const pci_config_t *config)
|
|||||||
|
|
||||||
int eth_config_cb (const pci_config_t *config)
|
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, "network-type", "ethernet", 9);
|
||||||
set_property(ph, "removable", "network", 8);
|
set_property(ph, "removable", "network", 8);
|
||||||
@@ -325,7 +326,7 @@ static void pci_set_AAPL_address(const pci_config_t *config)
|
|||||||
static void pci_set_assigned_addresses(const pci_config_t *config)
|
static void pci_set_assigned_addresses(const pci_config_t *config)
|
||||||
{
|
{
|
||||||
phandle_t dev = get_cur_dev();
|
phandle_t dev = get_cur_dev();
|
||||||
cell props[32];
|
u32 props[32];
|
||||||
int ncells;
|
int ncells;
|
||||||
int i;
|
int i;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
@@ -349,13 +350,13 @@ static void pci_set_assigned_addresses(const pci_config_t *config)
|
|||||||
}
|
}
|
||||||
if (ncells)
|
if (ncells)
|
||||||
set_property(dev, "assigned-addresses", (char *)props,
|
set_property(dev, "assigned-addresses", (char *)props,
|
||||||
ncells * sizeof(cell));
|
ncells * sizeof(props[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void pci_set_reg(const pci_config_t *config)
|
static void pci_set_reg(const pci_config_t *config)
|
||||||
{
|
{
|
||||||
phandle_t dev = get_cur_dev();
|
phandle_t dev = get_cur_dev();
|
||||||
cell props[38];
|
u32 props[38];
|
||||||
int ncells;
|
int ncells;
|
||||||
int i;
|
int i;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
@@ -387,14 +388,14 @@ static void pci_set_reg(const pci_config_t *config)
|
|||||||
props[ncells++] = 0x00000000;
|
props[ncells++] = 0x00000000;
|
||||||
props[ncells++] = config->sizes[i];
|
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)
|
static void pci_set_ranges(const pci_config_t *config)
|
||||||
{
|
{
|
||||||
phandle_t dev = get_cur_dev();
|
phandle_t dev = get_cur_dev();
|
||||||
cell props[32];
|
u32 props[32];
|
||||||
int ncells;
|
int ncells;
|
||||||
int i;
|
int i;
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
@@ -423,7 +424,7 @@ static void pci_set_ranges(const pci_config_t *config)
|
|||||||
|
|
||||||
props[ncells++] = config->sizes[i];
|
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)
|
int macio_heathrow_config_cb (const pci_config_t *config)
|
||||||
|
|||||||
@@ -175,9 +175,9 @@ defer find-dev
|
|||||||
: my-address ( -- phys.lo ... )
|
: my-address ( -- phys.lo ... )
|
||||||
?my-self >in.device-node @
|
?my-self >in.device-node @
|
||||||
>dn.probe-addr
|
>dn.probe-addr
|
||||||
my-#acells tuck cells + swap 1- 0
|
my-#acells tuck /l* + swap 1- 0
|
||||||
?do
|
?do
|
||||||
cell - dup @ swap
|
/l - dup l@ swap
|
||||||
loop
|
loop
|
||||||
drop
|
drop
|
||||||
;
|
;
|
||||||
@@ -189,8 +189,8 @@ defer find-dev
|
|||||||
|
|
||||||
: my-unit ( -- phys.lo ... phys.hi )
|
: my-unit ( -- phys.lo ... phys.hi )
|
||||||
?my-self >in.my-unit
|
?my-self >in.my-unit
|
||||||
my-#acells tuck cells + swap 0 ?do
|
my-#acells tuck /l* + swap 0 ?do
|
||||||
cell - dup @ swap
|
/l - dup l@ swap
|
||||||
loop
|
loop
|
||||||
drop
|
drop
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -61,8 +61,8 @@ extern void close_dev( ihandle_t ih );
|
|||||||
extern void set_property( phandle_t ph, const char *name,
|
extern void set_property( phandle_t ph, const char *name,
|
||||||
const char *buf, int len );
|
const char *buf, int len );
|
||||||
extern void set_int_property( phandle_t ph, const char *name,
|
extern void set_int_property( phandle_t ph, const char *name,
|
||||||
cell val );
|
u32 val );
|
||||||
extern cell get_int_property( phandle_t ph, const char *name,
|
extern u32 get_int_property( phandle_t ph, const char *name,
|
||||||
int *retlen );
|
int *retlen );
|
||||||
extern char *get_property( phandle_t ph, const char *name,
|
extern char *get_property( phandle_t ph, const char *name,
|
||||||
int *retlen );
|
int *retlen );
|
||||||
|
|||||||
@@ -287,10 +287,10 @@ set_property( phandle_t ph, const char *name, const char *buf, int len )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
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);
|
u32 swapped=__cpu_to_be32(val);
|
||||||
set_property( ph, name, (char*)&swapped, sizeof(cell) );
|
set_property( ph, name, (char*)&swapped, sizeof(swapped) );
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
@@ -312,14 +312,14 @@ get_property( phandle_t ph, const char *name, int *retlen )
|
|||||||
return (char*)POP();
|
return (char*)POP();
|
||||||
}
|
}
|
||||||
|
|
||||||
cell
|
u32
|
||||||
get_int_property( phandle_t ph, const char *name, int *retlen )
|
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 0;
|
||||||
return __becell_to_cpu(*p);
|
return __be32_to_cpu(*p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user