Re: [PATCH] byte-addressable grub_pci_make_address

2009-12-24 Thread Robert Millan
On Tue, Dec 22, 2009 at 03:12:09PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko 
wrote:
 === modified file 'commands/efi/loadbios.c'
 --- commands/efi/loadbios.c   2009-12-21 22:06:04 +
 +++ commands/efi/loadbios.c   2009-12-22 12:03:12 +
 @@ -50,7 +50,7 @@
return 0;
  }
  
 -  addr = grub_pci_make_address (dev, 36);
 +  addr = grub_pci_make_address (dev, 144);
grub_pci_write_byte (addr++, 0x30);
grub_pci_write_byte (addr++, 0x33);
grub_pci_write_byte (addr++, 0x33);
 @@ -76,7 +76,7 @@
grub_pci_address_t addr;
grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};
  
 -  addr = grub_pci_make_address (dev, 36);
 +  addr = grub_pci_make_address (dev, 144);

These look like black magic.  Could they be macroified instead?

-- 
Robert Millan

  Be the change you want to see in the world -- Gandhi


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


Re: [PATCH] byte-addressable grub_pci_make_address

2009-12-24 Thread Seth Goldberg


 What's the basis for these writes, btw?  I askesd a while ago but no one 
seemed to know.  Feel free to point me to a chipset datasheet, but right now 
this code truly a black box :).


 --S

Quoting Robert Millan, who wrote the following on Thu, 24 Dec 2009:


On Tue, Dec 22, 2009 at 03:12:09PM +0100, Vladimir 'φ-coder/phcoder' Serbinenko 
wrote:

=== modified file 'commands/efi/loadbios.c'
--- commands/efi/loadbios.c 2009-12-21 22:06:04 +
+++ commands/efi/loadbios.c 2009-12-22 12:03:12 +
@@ -50,7 +50,7 @@
   return 0;
 }

-  addr = grub_pci_make_address (dev, 36);
+  addr = grub_pci_make_address (dev, 144);
   grub_pci_write_byte (addr++, 0x30);
   grub_pci_write_byte (addr++, 0x33);
   grub_pci_write_byte (addr++, 0x33);
@@ -76,7 +76,7 @@
   grub_pci_address_t addr;
   grub_pci_device_t dev = { .bus = 0, .device = 0, .function = 0};

-  addr = grub_pci_make_address (dev, 36);
+  addr = grub_pci_make_address (dev, 144);


These look like black magic.  Could they be macroified instead?

--
Robert Millan

 Be the change you want to see in the world -- Gandhi


___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel

___
Grub-devel mailing list
Grub-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/grub-devel


[PATCH] byte-addressable grub_pci_make_address

2009-12-22 Thread Vladimir 'φ-coder/phcoder' Serbinenko
Hello, I noticed that grub_pci_make_address addresses register on dword
boundaries whereas some important byte registers aren't dword-aligned.
It's impossible to access such registers in opaque way which is required
when using grub-emu with PCI support. Here is a fix

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko

=== added file 'ChangeLog.pciclean'
--- ChangeLog.pciclean	1970-01-01 00:00:00 +
+++ ChangeLog.pciclean	2009-12-22 14:07:47 +
@@ -0,0 +1,52 @@
+2009-12-22  Vladimir Serbinenko  phco...@gmail.com
+
+	Byte-addressable PCI configuration space.
+
+	* bus/pci.c (grub_pci_make_address): Use byte address instead of
+	dword address.
+	(grub_pci_iterate): Use macroses GRUB_PCI_REG_PCI_ID and
+	GRUB_PCI_REG_CACHELINE.
+	* bus/usb/ohci.c (grub_ohci_pci_iter): Use macroses
+	GRUB_PCI_REG_CLASS and GRUB_PCI_REG_ADDRESS_REG0.
+	* bus/usb/uhci.c (grub_ohci_pci_iter): Use macroses
+	GRUB_PCI_REG_CLASS and GRUB_PCI_REG_ADDRESS_REG4.
+	* commands/efi/fixvideo.c (scan_card): Use macros GRUB_PCI_REG_CLASS.
+	* commands/efi/loadbios.c (enable_rom_area): Pass byte-address to
+	grub_pci_make_address.
+	(lock_rom_area): Likewise.
+	* commands/lspci.c (grub_lspci_iter): Use macroses
+	GRUB_PCI_REG_CLASS and GRUB_PCI_REG_ADDRESSES. Handle byte-addressing
+	of grub_pci_make_address.
+	* disk/ata.c (grub_ata_pciinit): Likewise.
+	* include/grub/pci.h (GRUB_PCI_REG_PCI_ID): New macro.
+	(GRUB_PCI_REG_VENDOR): Likewise.
+	(GRUB_PCI_REG_DEVICE): Likewise.
+	(GRUB_PCI_REG_COMMAND): Likewise.
+	(GRUB_PCI_REG_STATUS): Likewise.
+	(GRUB_PCI_REG_REVISION): Likewise.
+	(GRUB_PCI_REG_CLASS): Likewise.
+	(GRUB_PCI_REG_CACHELINE): Likewise.
+	(GRUB_PCI_REG_LAT_TIMER): Likewise.
+	(GRUB_PCI_REG_HEADER_TYPE): Likewise.
+	(GRUB_PCI_REG_BIST): Likewise.
+	(GRUB_PCI_REG_ADDRESSES): Likewise.
+	(GRUB_PCI_REG_ADDRESS_REG): Likewise.
+	(GRUB_PCI_REG_ADDRESS_REG): Likewise.
+	(GRUB_PCI_REG_ADDRESS_REG): Likewise.
+	(GRUB_PCI_REG_ADDRESS_REG): Likewise.
+	(GRUB_PCI_REG_ADDRESS_REG): Likewise.
+	(GRUB_PCI_REG_ADDRESS_REG): Likewise.
+	(GRUB_PCI_REG_CIS_POINTER): Likewise.
+	(GRUB_PCI_REG_SUBVENDOR): Likewise.
+	(GRUB_PCI_REG_SUBSYSTEM): Likewise.
+	(GRUB_PCI_REG_ROM_ADDRESS): Likewise.
+	(GRUB_PCI_REG_CAP_POINTER): Likewise.
+	(GRUB_PCI_REG_IRQ_LINE): Likewise.
+	(GRUB_PCI_REG_IRQ_PIN): Likewise.
+	(GRUB_PCI_REG_MIN_GNT): Likewise.
+	(GRUB_PCI_REG_MAX_LAT): Likewise.
+	* loader/i386/efi/linux.c (find_framebuf): Use GRUB_PCI_REG_CLASS.
+	* loader/i386/efi/xnu.c (find_framebuf): Likewise.
+	* video/efi_uga.c (find_framebuf): Likewise.
+	* util/pci.c (grub_pci_make_address): Use byte-addressed configuration
+	space.

=== modified file 'bus/pci.c'
--- bus/pci.c	2009-10-14 08:11:59 +
+++ bus/pci.c	2009-12-22 12:02:51 +
@@ -24,7 +24,7 @@
 grub_pci_make_address (grub_pci_device_t dev, int reg)
 {
   return (1  31) | (dev.bus  16) | (dev.device  11)
-| (dev.function  8) | (reg  2);
+| (dev.function  8) | reg;
 }
 
 void
@@ -41,7 +41,7 @@
 	{
 	  for (dev.function = 0; dev.function  8; dev.function++)
 	{
-	  addr = grub_pci_make_address (dev, 0);
+	  addr = grub_pci_make_address (dev, GRUB_PCI_REG_PCI_ID);
 	  id = grub_pci_read (addr);
 
 	  /* Check if there is a device present.  */
@@ -54,7 +54,7 @@
 	  /* Probe only func = 0 if the device if not multifunction */
 	  if (dev.function == 0)
 		{
-		  addr = grub_pci_make_address (dev, 3);
+		  addr = grub_pci_make_address (dev, GRUB_PCI_REG_CACHELINE);
 		  hdr = grub_pci_read (addr);
 		  if (!(hdr  0x80))
 		break;

=== modified file 'bus/usb/ohci.c'
--- bus/usb/ohci.c	2009-10-14 08:11:59 +
+++ bus/usb/ohci.c	2009-12-22 11:52:59 +
@@ -126,7 +126,7 @@
   grub_uint32_t revision;
   grub_uint32_t frame_interval;
 
-  addr = grub_pci_make_address (dev, 2);
+  addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
   class_code = grub_pci_read (addr)  8;
 
   interf = class_code  0xFF;
@@ -138,7 +138,7 @@
 return 0;
 
   /* Determine IO base address.  */
-  addr = grub_pci_make_address (dev, 4);
+  addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG0);
   base = grub_pci_read (addr);
 
 #if 0

=== modified file 'bus/usb/uhci.c'
--- bus/usb/uhci.c	2009-12-22 09:15:59 +
+++ bus/usb/uhci.c	2009-12-22 11:51:58 +
@@ -150,7 +150,7 @@
   struct grub_uhci *u;
   int i;
 
-  addr = grub_pci_make_address (dev, 2);
+  addr = grub_pci_make_address (dev, GRUB_PCI_REG_CLASS);
   class_code = grub_pci_read (addr)  8;
 
   interf = class_code  0xFF;
@@ -162,7 +162,7 @@
 return 0;
 
   /* Determine IO base address.  */
-  addr = grub_pci_make_address (dev, 8);
+  addr = grub_pci_make_address (dev, GRUB_PCI_REG_ADDRESS_REG4);
   base = grub_pci_read (addr);
   /* Stop if there is no IO space base address defined.  */
   if (! (base  1))

=== modified file 'commands/efi/fixvideo.c'
--- commands/efi/fixvideo.c	2009-11-30 18:09:11 +
+++ commands/efi/fixvideo.c	2009-12-22 11:54:44 +
@@ -42,7 +42,7 @@
 {