[OpenBIOS] [PATCH 2/5] pci: support PCI spaces other than memory in pci_bus_addr_to_host_addr()

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Mon Jan 4 10:52:33 CET 2016


On 04/01/16 08:05, Alexander Graf wrote:

> On 02.01.16 21:44, Mark Cave-Ayland wrote:
>> Currently only PCI memory space is mapped in ob_pci_map_in(). By adding
>> multi-space support to pci_bus_addr_to_host_addr(), it becomes possible
>> to translate physical addresses for both memory and IO space.
>>
>> Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
>> ---
>>  openbios-devel/drivers/pci.c |   28 +++++++++++++++++++++-------
>>  1 file changed, 21 insertions(+), 7 deletions(-)
>>
>> diff --git a/openbios-devel/drivers/pci.c b/openbios-devel/drivers/pci.c
>> index 6347118..97d3ef3 100644
>> --- a/openbios-devel/drivers/pci.c
>> +++ b/openbios-devel/drivers/pci.c
>> @@ -144,9 +144,13 @@ static void dump_reg_property(const char* description, int nreg, u32 *reg)
>>  }
>>  #endif
>>  
>> -static unsigned long pci_bus_addr_to_host_addr(uint32_t ba)
>> +static unsigned long pci_bus_addr_to_host_addr(int space, uint32_t ba)
>>  {
>> -    return arch->host_pci_base + (unsigned long)ba;
>> +    if (space == IO_SPACE) {
>> +        return arch->io_base + (unsigned long)ba;
>> +    } else {
>> +        return arch->host_pci_base + (unsigned long)ba;
>> +    }
>>  }
>>  
>>  static void
>> @@ -347,16 +351,20 @@ ob_pci_map_in(int *idx)
>>  {
>>  	phys_addr_t phys;
>>  	uint32_t ba;
>> -	ucell size, virt;
>> +	ucell size, virt, tmp;
>> +	int space;
>>  
>>  	PCI_DPRINTF("ob_pci_bar_map_in idx=%p\n", idx);
>>  
>>  	size = POP();
>> -	POP();
>> +	tmp = POP();
>>  	POP();
>>  	ba = POP();
>>  
>> -	phys = pci_bus_addr_to_host_addr(ba);
>> +	/* Get the space from the pci-addr.hi */
>> +	space = ((tmp & 0x03000000) >> 24);
> 
> You could try to reuse the defines we have in QEMU for the parameter bits:
> 
> #define FDT_PCI_RANGE_RELOCATABLE          0x80000000
> #define FDT_PCI_RANGE_PREFETCHABLE         0x40000000
> #define FDT_PCI_RANGE_ALIASED              0x20000000
> #define FDT_PCI_RANGE_TYPE_MASK            0x03000000
> #define FDT_PCI_RANGE_MMIO_64BIT           0x03000000
> #define FDT_PCI_RANGE_MMIO                 0x02000000
> #define FDT_PCI_RANGE_IOPORT               0x01000000
> #define FDT_PCI_RANGE_CONFIG               0x00000000

Yeah that seems a good idea - I'll add them into drivers/pci.h without
the FDT_ prefix in the next respin.

> While at it, you probably also want to double-check you're not mapping
> MMIO_64BIT or CONFIG by accident ;).

The default behaviour was just to return the address unaltered, so I'll
add that in too. Not that it will help anything that tries to access an
incorrect address, but at the very least it will appear unaltered in any
properties which makes it quite easy to spot.

I also have another patchset which tidies up the OpenPIC mappings which
I'll include in the next revision too, hopefully with the aim of
committing tomorrow to help clear my patch backlog(!)


ATB,

Mark.




More information about the OpenBIOS mailing list