pci: 64bit support
PATCH v2 1/6 output: add 64bit hex print support
In reply to Gerd Hoffmann--- src/output.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-)
src/output.c +21 -2
@@ -249,6 +249,7 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list args)const char *n = s+1 ;int field_width =0 ;int spacepad =1 ; +int is64 =0 ;for (;;) { c =GET_GLOBAL (*(u8 *)n);if (!isdigit (c))
@@ -264,6 +265,11 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list args) n++; c =GET_GLOBAL (*(u8 *)n); } +if (c =='l' ) { + is64 =1 ; + n++; + c =GET_GLOBAL (*(u8 *)n); + }s32 val;const char *sarg;switch (c) {
@@ -289,8 +295,21 @@ bvprintf(struct putcinfo *action, const char *fmt, va_list args) field_width =8 ; spacepad =0 ;case 'x' : - val =va_arg (args, s32); -puthex (action, val, field_width, spacepad); +if (is64) { + val =va_arg (args, s32); +u32 upper =va_arg (args, s32); +if (upper) { +if (field_width <8 ) + field_width =8 ; +puthex (action, upper, field_width -8 , spacepad); +puthex (action, val,8 ,0 ); + }else { +puthex (action, val, field_width, spacepad); + } + }else { + val =va_arg (args, s32); +puthex (action, val, field_width, spacepad); + }break ;case 'c' : val =va_arg (args, int);
Signature · 1 line
1.7.1
PATCH v2 6/6 pci: add prefmem64
In reply to Gerd HoffmannThis patch adds a prefmem64 region for 64bit pci prefmem bars which we'll go map above 4G. This will happen when either the device is on the root bus or it is behind a bridge supporting 64bit memory windows and all prefmem bars of all devices hooked up using that bridge are 64bit capable.
--- src/acpi-dsdt.dsl | 7 +++++ src/acpi-dsdt.hex | 72 +++++++++++++++++++++++++++++++++++++++++++--------- src/config.h | 2 + src/pciinit.c | 72 +++++++++++++++++++++++++++++++++++++++++++--------- 4 files changed, 127 insertions(+), 26 deletions(-)
src/acpi-dsdt.dsl +7 -0
@@ -175,6 +175,13 @@ DefinitionBlock ( 0x00000000, // Address Translation Offset 0x1EC00000, // Address Length ,, , AddressRangeMemory, TypeStatic) + QWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed, Cacheable, ReadWrite, + 0x00000000, // Address Space Granularity + 0x8000000000, // Address Range Minimum + 0xFFFFFFFFFF, // Address Range Maximum + 0x00000000, // Address Translation Offset + 0x8000000000, // Address Length + ,, , AddressRangeMemory, TypeStatic) }) } }
src/acpi-dsdt.hex +59 -13
112 lines not on this page · raw message
src/config.h +2 -0
@@ -47,6 +47,8 @@#define BUILD_PCIMEM_START 0xe0000000#define BUILD_PCIMEM_END 0xfec00000/* IOAPIC is mapped at */ +#define BUILD_PCIMEM64_START 0x8000000000ULL +#define BUILD_PCIMEM64_END 0xFFFFFFFFFFULL#define BUILD_IOAPIC_ADDR 0xfec00000#define BUILD_HPET_ADDRESS 0xfed00000
src/pciinit.c +59 -13
160 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 4/6 pci: bridges can have two regions too
In reply to Gerd Hoffmann--- src/pciinit.c | 20 ++++++++------------ 1 files changed, 8 insertions(+), 12 deletions(-)
src/pciinit.c +8 -12
@@ -402,7 +402,7 @@ static void pci_bios_check_devices(struct pci_bus *busses)struct pci_device *pci;struct pci_bus *bus; -int i; +int i, num_regions;// init pci bridges foreachpci (pci) {
@@ -414,12 +414,11 @@ static void pci_bios_check_devices(struct pci_bus *busses)// discover pci bars foreachpci (pci) { -if (pci->class ==PCI_CLASS_BRIDGE_PCI ) -continue ; + num_regions = (pci->class ==PCI_CLASS_BRIDGE_PCI ) ?2 :PCI_NUM_REGIONS ;dprintf (1 ,"PCI: check device bdf=%02x:%02x.%x\n" ,pci_bdf_to_bus (pci->bdf),pci_bdf_to_dev (pci->bdf),pci_bdf_to_fn (pci->bdf)); -for (i =0 ; i <PCI_NUM_REGIONS ; i++) { +for (i =0 ; i < num_regions; i++) {pci_bios_get_bar (pci, i, &pci->bars[i]);if (pci->bars[i].addr ==0 )continue ;
@@ -431,10 +430,9 @@ static void pci_bios_check_devices(struct pci_bus *busses)// alloc ressources for pci bars foreachpci (pci) { -if (pci->class ==PCI_CLASS_BRIDGE_PCI ) -continue ; + num_regions = (pci->class ==PCI_CLASS_BRIDGE_PCI ) ?2 :PCI_NUM_REGIONS ; bus = &busses[pci_bdf_to_bus (pci->bdf)]; -for (i =0 ; i <PCI_NUM_REGIONS ; i++) { +for (i =0 ; i < num_regions; i++) {enum pci_region_type type;if (pci->bars[i].addr ==0 )continue ;
@@ -545,7 +543,7 @@ static void pci_bios_map_devices(struct pci_bus *busses)pci_bios_init_bus_bases (&busses[0 ]);// Map regions on each secondary bus. -int secondary_bus; +int secondary_bus, num_regions, i;for (secondary_bus=1 ; secondary_bus<=MaxPCIBus; secondary_bus++) {struct pci_bus *s = &busses[secondary_bus];if (!s->bus_dev)
@@ -583,14 +581,12 @@ static void pci_bios_map_devices(struct pci_bus *busses)// Map regions on each device. struct pci_device *pci;foreachpci (pci) { -if (pci->class ==PCI_CLASS_BRIDGE_PCI ) -continue ; + num_regions = (pci->class ==PCI_CLASS_BRIDGE_PCI ) ?2 :PCI_NUM_REGIONS ;u16 bdf = pci->bdf;dprintf (1 ,"PCI: map device bdf=%02x:%02x.%x\n" ,pci_bdf_to_bus (bdf),pci_bdf_to_dev (bdf),pci_bdf_to_fn (bdf));struct pci_bus *bus = &busses[pci_bdf_to_bus (bdf)]; -int i; -for (i =0 ; i <PCI_NUM_REGIONS ; i++) { +for (i =0 ; i < num_regions; i++) {if (pci->bars[i].addr ==0 )continue ;
Signature · 1 line
1.7.1
v2 cover pci: 64bit support
Hi,
New revision of my 64bit pci patches. This is what I'm using to play with 64bit PCI bars (ivshmem + qxl devices) and bridge support (patches from mst).
Changes in v2:
* tried to reduce the stack footprint of 64bit hex number printing.
* changed patch splitting to make them (hopefully) more readable.
* full support for bridges with 64bit memory windows, even nested.
Also availabe from:
git://git.kraxel.org/seabios pci64
enjoy,
Gerd
Gerd Hoffmann (6):
output: add 64bit hex print support
pci: split device discovery into multiple steps
pci: 64bit support.
pci: bridges can have two regions too
pci: fix bridge ressource allocation.
pci: add prefmem64
src/acpi-dsdt.dsl | 7 ++ src/acpi-dsdt.hex | 72 ++++++++++++--- src/config.h | 2 + src/output.c | 23 ++++- src/pci.h | 14 ++- src/pciinit.c | 272 ++++++++++++++++++++++++++++++++++++++--------------- 6 files changed, 294 insertions(+), 96 deletions(-)
PATCH v2 5/6 pci: fix bridge ressource allocation.
The patch changes the bridge ressource allocation: Unused memory windows are disabled: If none of the devices connected to the bridge has -- say -- I/O bars, then the I/O memory window is turned off. This implies that bridges without devices don't get any ressources assigned. The pci bridge spec wants us behave that way (figured while looking at drivers/pci/setup-bus.c in the linux kernel source tree).
--- src/pciinit.c | 43 +++++++++++++++++++++++++++++++++---------- 1 files changed, 33 insertions(+), 10 deletions(-)
src/pciinit.c +33 -10
@@ -457,6 +457,8 @@ static void pci_bios_check_devices(struct pci_bus *busses)for (type =0 ; type <PCI_REGION_TYPE_COUNT ; type++) {u64 limit = (type ==PCI_REGION_TYPE_IO ) ?PCI_BRIDGE_IO_MIN :PCI_BRIDGE_MEM_MIN ; +if (s->r[type].sum ==0 ) +continue ; s->r[type].size = s->r[type].sum;if (s->r[type].size < limit) s->r[type].size = limit;
@@ -505,6 +507,8 @@ static void pci_bios_init_bus_bases(struct pci_bus *bus)int type, i;for (type =0 ; type <PCI_REGION_TYPE_COUNT ; type++) { +if (bus->r[type].sum ==0 ) +continue ;dprintf (1 ," type %s max %llx sum %llx base %llx\n" , region_type_name[type], bus->r[type].max, bus->r[type].sum, bus->r[type].base);
@@ -522,9 +526,10 @@ static void pci_bios_init_bus_bases(struct pci_bus *bus) } } -static u32 pci_bios_bus_get_addr (struct pci_bus *bus,int type,u32 size) +static u64 pci_bios_bus_get_addr (struct pci_bus *bus,int type,u64 size) { -u32 index, addr; +u32 index; +u64 addr; index =pci_size_to_index (size, type); addr = bus->r[type].bases[index];
@@ -552,30 +557,48 @@ static void pci_bios_map_devices(struct pci_bus *busses)struct pci_bus *parent = &busses[pci_bdf_to_bus (bdf)];int type;for (type =0 ; type <PCI_REGION_TYPE_COUNT ; type++) { +if (s->r[type].sum ==0 ) +continue ; s->r[type].base =pci_bios_bus_get_addr ( parent, type, s->r[type].size); }dprintf (1 ,"PCI: init bases bus %d (secondary)\n" , secondary_bus);pci_bios_init_bus_bases (s); -u64 base = s->r[PCI_REGION_TYPE_IO ].base; -u64 limit = base + s->r[PCI_REGION_TYPE_IO ].size -1 ; +u64 base, limit; +if (s->r[PCI_REGION_TYPE_IO ].sum) { + base = s->r[PCI_REGION_TYPE_IO ].base; + limit = base + s->r[PCI_REGION_TYPE_IO ].size -1 ; + }else { + base =PCI_BRIDGE_IO_MIN ; + limit =0 ; + }pci_config_writeb (bdf,PCI_IO_BASE , base >>PCI_IO_SHIFT );pci_config_writew (bdf,PCI_IO_BASE_UPPER16 ,0 );pci_config_writeb (bdf,PCI_IO_LIMIT , limit >>PCI_IO_SHIFT );pci_config_writew (bdf,PCI_IO_LIMIT_UPPER16 ,0 ); - base = s->r[PCI_REGION_TYPE_MEM ].base; - limit = base + s->r[PCI_REGION_TYPE_MEM ].size -1 ; +if (s->r[PCI_REGION_TYPE_MEM ].sum) { + base = s->r[PCI_REGION_TYPE_MEM ].base; + limit = base + s->r[PCI_REGION_TYPE_MEM ].size -1 ; + }else { + base =PCI_BRIDGE_MEM_MIN ; + limit =0 ; + }pci_config_writew (bdf,PCI_MEMORY_BASE , base >>PCI_MEMORY_SHIFT );pci_config_writew (bdf,PCI_MEMORY_LIMIT , limit >>PCI_MEMORY_SHIFT ); - base = s->r[PCI_REGION_TYPE_PREFMEM ].base; - limit = base + s->r[PCI_REGION_TYPE_PREFMEM ].size -1 ; +if (s->r[PCI_REGION_TYPE_PREFMEM ].sum) { + base = s->r[PCI_REGION_TYPE_PREFMEM ].base; + limit = base + s->r[PCI_REGION_TYPE_PREFMEM ].size -1 ; + }else { + base =PCI_BRIDGE_MEM_MIN ; + limit =0 ; + }pci_config_writew (bdf,PCI_PREF_MEMORY_BASE , base >>PCI_PREF_MEMORY_SHIFT );pci_config_writew (bdf,PCI_PREF_MEMORY_LIMIT , limit >>PCI_PREF_MEMORY_SHIFT ); -pci_config_writel (bdf,PCI_PREF_BASE_UPPER32 ,0 ); -pci_config_writel (bdf,PCI_PREF_LIMIT_UPPER32 ,0 ); +pci_config_writel (bdf,PCI_PREF_BASE_UPPER32 , base >>32 ); +pci_config_writel (bdf,PCI_PREF_LIMIT_UPPER32 , base >>32 ); }// Map regions on each device.
Signature · 1 line
1.7.1
PATCH v2 2/6 pci: split device discovery into multiple steps
In reply to Gerd HoffmannFirst bridge init, next pci bar discovery, finally pci bar ressource allocation. Needed because we need to figure whenever we can map 64bit bars above 4G before doing ressource allocation.
--- src/pciinit.c | 39 ++++++++++++++++++++++++++++++++------- 1 files changed, 32 insertions(+), 7 deletions(-)
src/pciinit.c +32 -7
@@ -368,22 +368,28 @@ static void pci_bios_check_devices(struct pci_bus *busses) {dprintf (1 ,"PCI: check devices\n" ); -// Calculate resources needed for regular (non-bus) devices. struct pci_device *pci; +struct pci_bus *bus; +int i; + +// init pci bridges foreachpci (pci) { -if (pci->class ==PCI_CLASS_BRIDGE_PCI ) { - busses[pci->secondary_bus].bus_dev = pci; +if (pci->class !=PCI_CLASS_BRIDGE_PCI ) +continue ; + bus = &busses[pci->secondary_bus]; + bus->bus_dev = pci; + } + +// discover pci bars +foreachpci (pci) { +if (pci->class ==PCI_CLASS_BRIDGE_PCI )continue ; - } -struct pci_bus *bus = &busses[pci_bdf_to_bus (pci->bdf)]; -int i;for (i =0 ; i <PCI_NUM_REGIONS ; i++) {u32 val, size;pci_bios_get_bar (pci, i, &val, &size);if (val ==0 )continue ; -pci_bios_bus_reserve (bus,pci_addr_to_type (val), size); pci->bars[i].addr = val; pci->bars[i].size = size; pci->bars[i].is64 = (!(val & PCI_BASE_ADDRESS_SPACE_IO) &&
@@ -395,6 +401,25 @@ static void pci_bios_check_devices(struct pci_bus *busses) } } +// alloc ressources for pci bars +foreachpci (pci) { +if (pci->class ==PCI_CLASS_BRIDGE_PCI ) +continue ; + bus = &busses[pci_bdf_to_bus (pci->bdf)]; +for (i =0 ; i <PCI_NUM_REGIONS ; i++) { +enum pci_region_type type; +if (pci->bars[i].addr ==0 ) +continue ; + + type =pci_addr_to_type (pci->bars[i].addr); +pci_bios_bus_reserve (bus, type, + pci->bars[i].size); + +if (pci->bars[i].is64) + i++; + } + } +// Propagate required bus resources to parent busses. int secondary_bus;for (secondary_bus=MaxPCIBus; secondary_bus>0 ; secondary_bus--) {
Signature · 1 line
1.7.1
PATCH v2 3/6 pci: 64bit support.
In reply to Gerd HoffmannMakes pciinit.c 64bit aware. Use 64bit everywhere. Support discovery and configuration of 64bit bars, with non-zero upper32 bits. While being at it introduce a struct pci_bar which can be passed easily.
--- src/pci.h | 14 ++++-- src/pciinit.c | 126 +++++++++++++++++++++++++++++++++++---------------------- 2 files changed, 87 insertions(+), 53 deletions(-)
src/pci.h +9 -5
@@ -39,6 +39,14 @@ void pci_config_maskw(u16 bdf, u32 addr, u16 off, u16 on);struct pci_device *pci_find_device (u16 vendid,u16 devid);struct pci_device *pci_find_class (u16 classid); +struct pci_bar { +u64 addr; +u64 size; +int is64:1 , + ismem:1 , + isprefetch:1 ; +}; +struct pci_device {u16 bdf;u8 rootbus;
@@ -51,11 +59,7 @@ struct pci_device {u8 prog_if, revision;u8 header_type;u8 secondary_bus; -struct { -u32 addr; -u32 size; -int is64; - } bars[PCI_NUM_REGIONS ]; +struct pci_bar bars[PCI_NUM_REGIONS ];// Local information on device. int have_driver;
src/pciinit.c +78 -48
242 lines not on this page · raw message
Signature · 1 line
1.7.1
Re: [Qemu-devel] [SeaBIOS] [PATCH v2 1/6] output: add 64bit hex print support
In reply to Gerd HoffmannQuoted 3 lines · Gerd Hoffmann
--- src/output.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-)
Thanks Gerd.
I think your patch missed a couple of corner cases. I played with it a bit and came up with the below.
-Kevin
Quoted 1 line
From
ab16772e7f51e5d9c8e0c44695a76320439d2c78Mon Sep 17 00:00:00 2001
From: Kevin O'Connor <[email protected]>
Date: Mon, 5 Mar 2012 10:14:07 -0500
Subject: [PATCH] output: Add 64bit hex print support.
To: [email protected]
Based on patch by Gerd Hoffmann <[email protected]>.
--- src/memmap.c | 6 +--- src/output.c | 68 +++++++++++++++++++++++++++++++++++----------------------- src/post.c | 3 +- 3 files changed, 44 insertions(+), 33 deletions(-)
src/memmap.c +2 -4
@@ -63,10 +63,8 @@ dump_map(void)for (i=0 ; i<e820_count; i++) {struct e820entry *e = &e820_list[i];u64 e_end = e->start + e->size; -dprintf (1 ," %d: %08x%08x - %08x%08x = %d %s\n" , i - , (u32)(e->start >>32 ), (u32 )e->start - , (u32)(e_end >>32 ), (u32 )e_end - , e->type,e820_type_name (e->type)); +dprintf (1 ," %d: %016llx - %016llx = %d %s\n" , i + , e->start, e_end, e->type,e820_type_name (e->type)); } }
src/output.c +42 -28
130 lines not on this page · raw message
src/post.c +1 -2
@@ -150,8 +150,7 @@ ram_probe(void)add_e820 (0xfffbc000 ,4 *4096 ,E820_RESERVED ); } -dprintf (1 ,"Ram Size=0x%08x (0x%08x%08x high)\n" - , RamSize, (u32)(RamSizeOver4G >>32 ), (u32 )RamSizeOver4G); +dprintf (1 ,"Ram Size=0x%08x (0x%016llx high)\n" , RamSize, RamSizeOver4G); } static void
Signature · 1 line
1.7.6.5
Re: [Qemu-devel] [SeaBIOS] [PATCH v2 1/6] output: add 64bit hex print support
Quoted 9 lines · Kevin O'Connor
Quoted 3 lines · Gerd Hoffmann
--- src/output.c | 23 +++++++++++++++++++++-- 1 files changed, 21 insertions(+), 2 deletions(-)Thanks Gerd.
I think your patch missed a couple of corner cases. I played with it a bit and came up with the below.
Looks fine.
cheers,
Gerd