Bug#594967: Bug #594967: [poulsbo] grub-pc Hangs After "Welcome to GRUB!"
Quoted 7 lines · Steve McIntyre
1.iso:
last bus number printed is b0
2.iso:
goes all the way through to bus ff and returns to a grub prompt
This is interesting and suggests a measure of coincidence. What that patch did was skip remaining functions on a device that doesn't implement function 0, taking that as an indication that it doesn't exist. This was based on:
http://en.wikipedia.org/wiki/PCI_configuration_space#Bus_enumeration
Vladimir, are you OK with this change to trunk?
2011-01-02 Colin Watson <[email protected]>
* grub-core/bus/pci.c (grub_pci_iterate): Skip remaining functions on devices that do not implement function 0.
=== modified file 'grub-core/bus/pci.c'
bus/pci.c +8 -1
@@ -90,7 +90,14 @@ grub_pci_iterate (grub_pci_iteratefunc_t/* Check if there is a device present. */ if (id >>16 ==0xFFFF ) -continue ; + { +if (dev.function ==0 ) +/* Devices are required to implement function 0, so if +it's missing then there is no device here. */ +break ; +else +continue ; + }#ifdef GRUB_MACHINE_MIPS_YEELOONG /* Skip ghosts. */
Nevertheless, I'm not confident that this will fix the problem on all machines, so I would like to sort out the bridge handling as well.
Quoted 17 lines
3.iso:
grub> set debug=pci
grub> lspci
bus/pci.c:92: bus 0
00:00.0 8086:8100 [0600] Host Bridge
00:02.0 8086:8108 [0300] VGA Controller
00:1b.0 8086:811b [0403] Multimedia device
00:1c.0 8086:8110 [0604] PCI-PCI Bridge
00:1c.1 8086:8112 [0604] PCI-PCI Bridge
00:1d.0 8086:8114 [0c03] USB Controller
00:1d.1 8086:8115 [0c03] USB Controller
00:1d.2 8086:8116 [0c03] USB Controller
00:1d.7 8086:8117 [0c03] USB Controller [PI 20]
00:1f.0 8086:8119 [0601] ISA Bridge
00:1f.1 8086:811a [0101] IDE Controller [PI 80]
grub>
Whoops, I forgot to right-shift the header word. Can you try 4.iso instead, at the same location? I also made it handle PCI-to-CardBus bridges the same way as PCI-to-PCI bridges since that's what pciutils does.
(In addition to 'set debug=pci', I'd recommend also doing 'set pager=1' so that lspci's output will be paged.)
Thanks,
Signature · 1 line
Colin Watson [[email protected]]
Quoted 25 lines · Steve McIntyre
Quoted 7 lines · Colin Watson
Whoops, I forgot to right-shift the header word. Can you try 4.iso instead, at the same location? I also made it handle PCI-to-CardBus bridges the same way as PCI-to-PCI bridges since that's what pciutils does.
(In addition to 'set debug=pci', I'd recommend also doing 'set pager=1' so that lspci's output will be paged.)
4.iso:
grub> set debug=pci
grub> set pager=1
grub> lspci
bus/pci.c:92: bus0x0
00:00.0 8086:8100 [0600] Host Bridge
00:02.0 8086:8108 [0300] VGA Controller
00:1b.0 8086:811b [0403] Multimedia device
bus/pci.c:143: bridge range 0x2-0x2
00:1c.0 8086:8110 [0604] PCI-PCI Bridge
bus/pci.c:143: bridge range 0x3-0x3
00:1c.1 8086:8112 [0604] PCI-PCI Bridge
00:1d.0 8086:8114 [0c03] USB Controller
00:1d.1 8086:8115 [0c03] USB Controller
00:1d.2 8086:8116 [0c03] USB Controller
Quoted 8 lines
00:1d.7 8086:8117 [0c03] USB Controller [PI 20]
00:1f.0 8086:8119 [0601] ISA Bridge
00:1f.1 8086:811a [0101] IDE Controller [PI 80]
bus/pci.c:92: bus0x2
02:00.0 10ec:8136 [0200] Ethernet Controller
bus/pci.c:92: bus0x3
03:00.0 168c:001c [0200] Ethernet Controller
grub>
This looks right to me. Excellent. Vladimir, how does this patch look, on top of my previous one? (This is edited slightly relative to what Steve tested, to make sure that the bus number never overflows bus_present; this will never happen on x86 but might happen on other architectures. I've smoke-tested this change.)
2011-01-03 Colin Watson <[email protected]>
* grub-core/bus/pci.c (grub_pci_iterate): Only scan bus 0 plus any buses linked by PCI-to-PCI or PCI-to-CardBus bridges.
* include/grub/pci.h: Add definitions for bridges.
=== modified file 'grub-core/bus/pci.c'
bus/pci.c +42 -0
@@ -20,6 +20,7 @@#include <grub/dl.h> #include <grub/pci.h> #include <grub/mm.h> +#include <grub/misc.h> /* FIXME: correctly support 64-bit architectures. */ /* #if GRUB_TARGET_SIZEOF_VOID_P == 4 */
@@ -78,9 +79,18 @@ grub_pci_iterate (grub_pci_iteratefunc_tgrub_pci_address_t addr;grub_pci_id_t id;grub_uint32_t hdr; +grub_uint8_t bus_present[(GRUB_PCI_NUM_BUS +7 ) /8 ]; + +grub_memset (bus_present,0 ,sizeof (bus_present)); + bus_present[0 ] =1 ;/* bus 0 is always enabled */ for (dev.bus =0 ; dev.bus <GRUB_PCI_NUM_BUS ; dev.bus++) { +if (!(bus_present[dev.bus /8 ] & (1 << (dev.bus %8 )))) +continue ; + +grub_dprintf ("pci" ,"bus 0x%x\n" , dev.bus); +for (dev.device =0 ; dev.device <GRUB_PCI_NUM_DEVICES ; dev.device++) {for (dev.function =0 ; dev.function <8 ; dev.function++)
@@ -112,6 +119,38 @@ grub_pci_iterate (grub_pci_iteratefunc_tcontinue ;#endif +/* On bus 0, look for PCI-to-PCI bridges and mark all buses +within their ranges as present. */ +if (dev.bus ==0 ) + { + addr =grub_pci_make_address (dev,GRUB_PCI_REG_CACHELINE ); + hdr =grub_pci_read (addr); + +switch ((hdr >>16 ) &0x7F ) { +case GRUB_PCI_HEADER_PCI_BRIDGE : +case GRUB_PCI_HEADER_CARDBUS_BRIDGE : + { +grub_uint32_t bus_numbers; +grub_uint32_t secondary, subordinate, i; + + addr =grub_pci_make_address + (dev,GRUB_PCI_REG_SEC_LAT_TIMER ); + bus_numbers =grub_pci_read (addr); + secondary = (bus_numbers >>8 ) &0xFF ; + subordinate = (bus_numbers >>16 ) &0xFF ; + +grub_dprintf ("pci" ,"bridge range 0x%x-0x%x\n" , + secondary, subordinate); + +for (i = secondary; + i <= subordinate && i <GRUB_PCI_NUM_BUS ; i++) + bus_present[i /8 ] |= (1 << (i %8 )); + +break ; + } + } + } +if (hook (dev, id))return ;
=== modified file 'include/grub/pci.h'
grub/pci.h +22 -0
@@ -68,6 +68,24 @@#define GRUB_PCI_REG_MIN_GNT 0x3e#define GRUB_PCI_REG_MAX_LAT 0x3f +/* Alternative register meanings if header type is 1 (PCI-to-PCI bridge). */ +#define GRUB_PCI_REG_SEC_LAT_TIMER 0x18 +#define GRUB_PCI_REG_SUB_BUS_NUMBER 0x19 +#define GRUB_PCI_REG_SEC_BUS_NUMBER 0x1a +#define GRUB_PCI_REG_PRI_BUS_NUMBER 0x1b +#define GRUB_PCI_REG_SEC_STATUS 0x1c +#define GRUB_PCI_REG_IO_LIMIT 0x1e +#define GRUB_PCI_REG_IO_BASE 0x1f +#define GRUB_PCI_REG_MEM_LIMIT 0x20 +#define GRUB_PCI_REG_MEM_BASE 0x22 +#define GRUB_PCI_REG_PF_MEM_LIMIT 0x24 +#define GRUB_PCI_REG_PF_MEM_BASE 0x26 +#define GRUB_PCI_REG_PF_MEM_BASE_HI 0x28 +#define GRUB_PCI_REG_PF_MEM_LIMIT_HI 0x2c +#define GRUB_PCI_REG_IO_LIMIT_HI 0x30 +#define GRUB_PCI_REG_IO_BASE_HI 0x32 +#define GRUB_PCI_REG_BRIDGE_CONTROL 0x3c +#define GRUB_PCI_COMMAND_IO_ENABLED 0x0001#define GRUB_PCI_COMMAND_MEM_ENABLED 0x0002#define GRUB_PCI_COMMAND_BUS_MASTER 0x0004
@@ -82,6 +100,10 @@#define GRUB_PCI_STATUS_DEVSEL_TIMING_MASK 0x0600#define GRUB_PCI_CLASS_SUBCLASS_VGA 0x0300 +#define GRUB_PCI_HEADER_GENERAL 0x0 +#define GRUB_PCI_HEADER_PCI_BRIDGE 0x1 +#define GRUB_PCI_HEADER_CARDBUS_BRIDGE 0x2 +#ifndef ASM_FILE typedef grub_uint32_t grub_pci_id_t ;
Thanks,
Signature · 1 line
Colin Watson [[email protected]]
Quoted 10 lines · Colin Watson
Quoted 3 lines · Steve McIntyre
2.iso:
goes all the way through to bus ff and returns to a grub prompt
This is interesting and suggests a measure of coincidence. What that patch did was skip remaining functions on a device that doesn't implement function 0, taking that as an indication that it doesn't exist. This was based on:
Quoted 8 lines
http://en.wikipedia.org/wiki/PCI_configuration_space#Bus_enumeration
Vladimir, are you OK with this change to trunk?
2011-01-02 Colin Watson <[email protected]>
*
grub-core/bus/pci.c(grub_pci_iterate): Skip remaining functions on devices that do not implement function 0.
I've applied this patch to trunk following an ack from Vladimir on IRC. I'll prepare an updated package for unstable shortly.
Quoted 2 lines
Nevertheless, I'm not confident that this will fix the problem on all machines, so I would like to sort out the bridge handling as well.
This may be more complicated than I thought. Seth Goldberg pointed out that my approach fails to deal with peer host bridges correctly (i.e. cases where there are multiple trees, not just a single one rooted at bus 0). Linux deals with this by asking the PCI BIOS for the last bus number, but at this point things get complicated as you have to do things in different ways for different firmware.
I am inclined to try the first piece alone and see how this works out, and if we can fix the affected systems by just probing function 0 on every device on every bus then let it stand at that, even if it feels less elegant. Inventing new piles of infrastructure to handle a case I'm unsure about in a subsystem I don't know well isn't my idea of a good time.
Signature · 1 line
Colin Watson [[email protected]]
Quoted 26 lines · Colin Watson
Quoted 10 lines · Colin Watson
Quoted 3 lines · Steve McIntyre
2.iso:
goes all the way through to bus ff and returns to a grub prompt
This is interesting and suggests a measure of coincidence. What that patch did was skip remaining functions on a device that doesn't implement function 0, taking that as an indication that it doesn't exist. This was based on:
Quoted 8 lines
http://en.wikipedia.org/wiki/PCI_configuration_space#Bus_enumeration
Vladimir, are you OK with this change to trunk?
2011-01-02 Colin Watson <[email protected]>
*
grub-core/bus/pci.c(grub_pci_iterate): Skip remaining functions on devices that do not implement function 0.I've applied this patch to trunk following an ack from Vladimir on IRC. I'll prepare an updated package for unstable shortly.
Quoted 2 lines
Nevertheless, I'm not confident that this will fix the problem on all machines, so I would like to sort out the bridge handling as well.
Quoted 7 lines
This may be more complicated than I thought. Seth Goldberg pointed out that my approach fails to deal with peer host bridges correctly (i.e. cases where there are multiple trees, not just a single one rooted at bus 0). Linux deals with this by asking the PCI BIOS for the last bus number, but at this point things get complicated as you have to do things in different ways for different firmware.
The proper way to do this on modern systems is to traverse the system's [DSDT/SSDT] ACPI tables looking for Device objects with the host bridge HID/CID and evaluate the BBN object (which can be a method), if it exists (which it must if there are multiple host bridges). Since grub2 does not have a full ACPI interpreter (pulling in Intel's acpica would work ;), though the license may force it to be a grub-extra), going that route with anything less would never cover all systems' BBNs, so PCI BIOS would be simplest. Things get a bit more complicated when a system has multiple PCI segments (i.e.: using the MCFG table, MMIO addresses that may be >4G, etc.), but that can be tackled later.
--S
Quoted 14 lines
I am inclined to try the first piece alone and see how this works out, and if we can fix the affected systems by just probing function 0 on every device on every bus then let it stand at that, even if it feels less elegant. Inventing new piles of infrastructure to handle a case I'm unsure about in a subsystem I don't know well isn't my idea of a good time.
Signature · 6 lines
Colin Watson [[email protected]] _______________________________________________ Grub-devel mailing list [email protected] http://lists.gnu.org/mailman/listinfo/grub-devel
Quoted 8 lines · Colin Watson
Quoted 4 lines · Colin Watson
2011-01-02 Colin Watson <[email protected]>
*
grub-core/bus/pci.c(grub_pci_iterate): Skip remaining functions on devices that do not implement function 0.I've applied this patch to trunk following an ack from Vladimir on IRC. I'll prepare an updated package for unstable shortly.
Uploading now. I'd appreciate confirmation from affected folks that this is enough to make things boot. If it is, we can perhaps avoid worrying about the rest; otherwise, we'll have to get more creative.
Thanks,
Signature · 1 line
Colin Watson [[email protected]]
Quoted 8 lines · Colin Watson
Whoops, I forgot to right-shift the header word. Can you try 4.iso instead, at the same location? I also made it handle PCI-to-CardBus bridges the same way as PCI-to-PCI bridges since that's what pciutils does.
(In addition to 'set debug=pci', I'd recommend also doing 'set pager=1' so that lspci's output will be paged.)
4.iso:
grub> set debug=pci
grub> set pager=1
grub> lspci
bus/pci.c:92: bus 0x0
00:00.0 8086:8100 [0600] Host Bridge
00:02.0 8086:8108 [0300] VGA Controller
00:1b.0 8086:811b [0403] Multimedia device
bus/pci.c:143: bridge range 0x2-0x2
00:1c.0 8086:8110 [0604] PCI-PCI Bridge
bus/pci.c:143: bridge range 0x3-0x3
00:1c.1 8086:8112 [0604] PCI-PCI Bridge
00:1d.0 8086:8114 [0c03] USB Controller
00:1d.1 8086:8115 [0c03] USB Controller
00:1d.2 8086:8116 [0c03] USB Controller
00:1d.7 8086:8117 [0c03] USB Controller [PI 20]
00:1f.0 8086:8119 [0601] ISA Bridge
00:1f.1 8086:811a [0101] IDE Controller [PI 80]
bus/pci.c:92: bus 0x2
02:00.0 10ec:8136 [0200] Ethernet Controller
bus/pci.c:92: bus 0x3
03:00.0 168c:001c [0200] Ethernet Controller
grub>
Signature · 2 lines
Steve McIntyre, Cambridge, UK. [email protected] "Because heaters aren't purple!" -- Catherine Pitt
Quoted 7 lines · Colin Watson
Quoted 6 lines · Colin Watson
Quoted 4 lines · Colin Watson
2011-01-02 Colin Watson <[email protected]>
*
grub-core/bus/pci.c(grub_pci_iterate): Skip remaining functions on devices that do not implement function 0.
Quoted 6 lines
Quoted 2 lines
I've applied this patch to trunk following an ack from Vladimir on IRC. I'll prepare an updated package for unstable shortly.
Uploading now. I'd appreciate confirmation from affected folks that this is enough to make things boot. If it is, we can perhaps avoid worrying about the rest; otherwise, we'll have to get more creative.
Just tested on Jo's laptop now, and the new version works exactly as hoped. Thanks for the quick fix! Jo says "many thankyous" too. :-)
Signature · 4 lines
Steve McIntyre, Cambridge, UK. [email protected] "Since phone messaging became popular, the young generation has lost the ability to read or write anything that is longer than one hundred and sixty characters." -- Ignatios Souvatzis
Quoted 7 lines · Colin Watson
Quoted 6 lines · Colin Watson
Quoted 4 lines · Colin Watson
2011-01-02 Colin Watson <[email protected]>
*
grub-core/bus/pci.c(grub_pci_iterate): Skip remaining functions on devices that do not implement function 0.
Quoted 6 lines
Quoted 2 lines
I've applied this patch to trunk following an ack from Vladimir on IRC. I'll prepare an updated package for unstable shortly.
Uploading now. I'd appreciate confirmation from affected folks that this is enough to make things boot. If it is, we can perhaps avoid worrying about the rest; otherwise, we'll have to get more creative.
"Graphical" booting is back. Thanks Colin.
-matt
Quoted 9 lines · Colin Watson
Quoted 7 lines · Colin Watson
Quoted 5 lines · Colin Watson
2011-01-02 Colin Watson <[email protected]>
*
grub-core/bus/pci.c(grub_pci_iterate): Skip remaining functions on devices that do not implement function 0.
Quoted 9 lines
Quoted 3 lines
I've applied this patch to trunk following an ack from Vladimir on IRC. I'll prepare an updated package for unstable shortly.
Uploading now. I'd appreciate confirmation from affected folks that this is enough to make things boot. If it is, we can perhaps avoid worrying about the rest; otherwise, we'll have to get more creative.
Thanks,
Sorry I haven't responded to this more quickly; I was busy with some personal business last week. Thanks for the patch, and it does make GRUB 2's graphical menu load on my AO751h. :)
I noticed an odd lingering aesthetics issue though; most of the background image is missing. The only parts of Squeeze's `spacefun-grub.png' that are visible are the bottom of Earth and the two stars on the top-right corner (basically, anything along the edges). I've consistently reproduced this on two installations (one is a fresh installation on a flash drive), even after purging and reinstalling grub-pc and grub-common. The odd thing though is that it only happens with desktop-base 6.0.5. The `spacefun-grub.png' from version 6.0.2 is displayed in full.
P. J.