Skip to contentSkip to conversation

qemu PPC Linux 2.6 IDE

PATCH In review Thayne Harbaugh 2 participants 2 messages Feb 23, 2005 – Feb 24, 2005 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu PPC Linux 2.6 IDE

I have qemu PPC booting Linux 2.6. Here's a patch for IDE.

IDE detection of macio has changed significantly. 2.4 drivers/ide/ppc/pmac.c:pmac_ide_probe() simply looked for the IDE/ATA controllers in OF. 2.6 pmac.c:pmace_ide_probe() registers macio device filters for IDE/ATA and relies on macio device enumeration to connect to the IDE driver. Where things are broken is that drivers/macintosh/macio_asic.c:macio_pci_probe() fails to match the macio device due to the bus:devfn not being set as a "reg" property in OHW.

There are two questions about this patch:

* What is the complete information expected in the "reg" property of a PCI device?

* Where should the current macio "reg" information really be stored, if at all?

I should be able to investigate the above two questions in the next few days.

A fix for 2.6 FB should be soon.

bios.h +1 -1
Index: src/bios.h
===================================================================
@@ -405,7 +405,7 @@
                               uint8_t devfn, uint8_t rev, uint32_t ccode,
                               uint16_t min_grant, uint16_t max_latency);
 void *OF_register_pci_device (void *parent, pci_dev_t *dev,
-                              uint8_t devfn, uint8_t rev, uint32_t ccode,
+                              uint8_t bus, uint8_t devfn, uint8_t rev, uint32_t ccode,
                               uint16_t min_grant, uint16_t max_latency);
 void OF_finalize_pci_host (void *dev, int first_bus, int nb_busses);
 void OF_finalize_pci_device (void *dev, uint32_t *regions, uint32_t *sizes);
pci.c +2 -2
Index: src/pci.c
===================================================================
@@ -1908,12 +1914,12 @@
     /* register PCI device in OF tree */
     if (bridge->dev.common.type == PCI_FAKE_BRIDGE) {
         newd->common.OF_private =
-            OF_register_pci_device(host->dev.common.OF_private, dev, devfn,
+            OF_register_pci_device(host->dev.common.OF_private, dev, bus, devfn,
                                    rev, ccode, min_grant, max_latency);
     } else {
         newd->common.OF_private =
-            OF_register_pci_device(bridge->dev.common.OF_private, dev, devfn,
+            OF_register_pci_device(bridge->dev.common.OF_private, dev, bus, devfn,
                                    rev, ccode, min_grant, max_latency);
     }
  configure_device:
of.c +8 -2
Index: src/of.c
===================================================================
@@ -2122,10 +2125,11 @@
 
 __attribute__ (( section (".OpenFirmware") ))
 void *OF_register_pci_device (void *parent, pci_dev_t *dev,
-                              uint8_t devfn, uint8_t rev, uint32_t ccode,
+                              uint8_t bus, uint8_t devfn, uint8_t rev, uint32_t ccode,
                               uint16_t min_grant, uint16_t max_latency)
 {
     OF_env_t *OF_env;
+    OF_regprop_t regs[1];
     OF_node_t *pci_dev;
 
     OF_env = OF_env_main;
@@ -2134,6 +2138,10 @@
     pci_dev = OF_pci_device_new(OF_env, parent, dev, devfn >> 3,
                                 rev, ccode, min_grant, max_latency);
 
+    /* FIXME - this likely isn't complete: low 8 and high 8 of the 32 bits? */
+    regs[0].address = (bus << 16) | (devfn << 8);
+    OF_property_new(OF_env, pci_dev, "reg", regs, sizeof(OF_regprop_t));
+
     return pci_dev;
 }
 
@@ -2347,7 +2355,8 @@
     pregs[0].addr.lo = 0x00000000;
     pregs[0].size_hi = 0x00000000;
     pregs[0].size_lo = size;
-    OF_property_new(OF_env, mio, "reg",
+    /* FIXME - pregs can't be property "reg" because bus:devfn is expected in "reg" */
+    OF_property_new(OF_env, mio, "preg",
                     &pregs, 2 * sizeof(pci_reg_prop_t));
 #endif
     pregs[0].addr.hi = 0x00000000;
#1 lore raw
Quoted 10 lines · Thayne Harbaugh

I have qemu PPC booting Linux 2.6. Here's a patch for IDE.

IDE detection of macio has changed significantly. 2.4 drivers/ide/ppc/pmac.c:pmac_ide_probe() simply looked for the IDE/ATA controllers in OF. 2.6 pmac.c:pmace_ide_probe() registers macio device filters for IDE/ATA and relies on macio device enumeration to connect to the IDE driver. Where things are broken is that drivers/macintosh/macio_asic.c:macio_pci_probe() fails to match the macio device due to the bus:devfn not being set as a "reg" property in OHW.

OK, your patch is as false as what I've done for many reasons (see below)

Quoted 5 lines

There are two questions about this patch:

* What is the complete information expected in the "reg" property of a PCI device?

"reg" is supposed to contain information about the configuration space, I/O regions and memory regions for the PCI device.

Quoted 2 lines

* Where should the current macio "reg" information really be stored, if at all?

Current MacIO "reg" informations are to be stored in "reg" property, but there are false, as you've seen. Those "reg" properties where taken from a real mac...
I did not notice that I should have changed the preg.hi cell to match the Qemu PCI device informations, but the real fix is to generate the whole information...

I made a quick fix, following OF bindings for PCI specifications. Note that I already had a fix for OF_property_set with no value, less intrusive than yours.
I also did add a dprintf (as debug printf) function to make early debug easier and there's also a needed fix in CHRP boot file loader.

Please consider this patch against 0.4-pre1d, it should fix the macIO problem the right way.
There's still a lack of informations about configuration space in reg properties for PCI devices, but this should not hurt.

Signature · 2 lines
J. Mayer <[email protected]>
Never organized
bios.h +2 -1
Index: src/bios.h
===================================================================
@@ -401,7 +401,8 @@ void *OF_register_pci_device (void *pare
                               uint8_t devfn, uint8_t rev, uint32_t ccode,
                               uint16_t min_grant, uint16_t max_latency);
 void OF_finalize_pci_host (void *dev, int first_bus, int nb_busses);
-void OF_finalize_pci_device (void *dev, uint32_t *regions, uint32_t *sizes);
+void OF_finalize_pci_device (void *dev, uint8_t bus, uint8_t devfn,
+                             uint32_t *regions, uint32_t *sizes);
 void OF_finalize_pci_macio (void *dev, uint32_t base_address, uint32_t size,
                             void *private_data);
 int OF_register_bus (const unsigned char *name, uint32_t address,
of.c +94 -17

166 lines not on this page · raw message

pci.c +1 -1
Index: src/pci.c
===================================================================
@@ -2003,7 +2003,7 @@ static pci_u_t *pci_check_device (pci_ho
     }
  update_device:
     pci_update_device(bridge, newd, min_grant, max_latency, irq_line);
-    OF_finalize_pci_device(newd->common.OF_private,
+    OF_finalize_pci_device(newd->common.OF_private, bus, devfn,
                            newd->regions, newd->sizes);
     /* Call special inits if needed */
     if (dev->config_cb != NULL)
char.c +14 -0
Index: src/char.c
===================================================================
@@ -300,6 +300,20 @@ static cops_t pc_serial_ops = {
     .close = &pc_serial_close,
 };
 
+/* XXX: debug stuff only ! (TOFIX with a generic debug console) */
+int serial_write (const void *buffer, int len)
+{
+    const char *p;
+
+    for (p = buffer; len > 0; len--) {
+        if (!(inb(0x3F8 + PC_SERIAL_LSR_OFFSET) & 0x20))
+            usleep(100);
+        outb(0x3F8, *p++);
+    }
+
+    return 0;
+}
+
 int pc_serial_register (uint16_t base)
 {
     pc_serial_t *serial;
libc/include/stdio.h +2 -0
Index: src/libc/include/stdio.h
===================================================================
@@ -35,9 +35,11 @@
 #define EOF ((int)-1)
 
 int printf (const char *format, ...);
+int dprintf (const char *format, ...);
 int sprintf (char *str, const char *format, ...);
 int snprintf (char *str, size_t size, const char *format, ...);
 int vprintf (const char *format, va_list ap);
+int vdprintf (const char *format, va_list ap);
 int vsprintf (char *str, const char *format, va_list ap);
 int vsnprintf (char *str, size_t size, const char *format, va_list ap);
 
libc/src/format.c +37 -0
Index: src/libc/src/format.c
===================================================================
@@ -41,6 +41,8 @@
 
 #define unused __attribute__ (( unused ))
 int console_write (const void *buffer, int len);
+int serial_write (const void *buffer, int len);
+#define debug_write serial_write
 
 /* Low level output fonctions */
 typedef size_t (*outf_t)(void *private, const unsigned char *buf, size_t len);
@@ -57,6 +59,16 @@ size_t outfd (void *private, const unsig
     return write(*fd, buf, len);
 }
 
+size_t outf_dbg (void *private, const unsigned char *buf, size_t len)
+{
+    int *fd = private;
+
+    if (*fd == 1 || *fd == 2)
+        return debug_write(buf, len);
+
+    return write(*fd, buf, len);
+}
+
 /* output to buffer */
 size_t outbuf (void *private, const unsigned char *buf, size_t len)
 {
@@ -362,6 +374,7 @@ int _vprintf(outf_t outf, void *private,
 }
 #else /* defined (__USE__vprintf__) */
 size_t outfd (void *private, const unsigned char *buf, size_t len);
+size_t outf_dbg (void *private, const unsigned char *buf, size_t len);
 size_t outbuf (void *private, const unsigned char *buf, size_t len);
 int _vprintf(outf_t outf, void *private, size_t maxlen,
              const unsigned char *format, va_list ap);
@@ -382,6 +395,21 @@ int printf (const char *format, ...)
 }
 #endif /* defined (__USE_printf__) */
 
+#if defined (__USE_dprintf__)
+int dprintf (const char *format, ...)
+{
+    va_list ap;
+    int fd = 1;
+    int ret;
+
+    va_start(ap, format);
+    ret = _vprintf(&outf_dbg, &fd, -1, format, ap);
+    va_end(ap);
+
+    return ret;
+}
+#endif /* defined (__USE_dprintf__) */
+
 #if defined (__USE_sprintf__)
 int sprintf (char *str, const char *format, ...)
 {
@@ -419,6 +447,15 @@ int vprintf (const char *format, va_list
 }
 #endif /* defined (__USE_vprintf__) */
 
+#if defined (__USE_vdprintf__)
+int vdprintf (const char *format, va_list ap)
+{
+    int fd = 1;
+
+    return _vprintf(&outf_dbg, &fd, -1, format, ap);
+}
+#endif /* defined (__USE_vdprintf__) */
+
 #if defined (__USE_vsprintf__)
 int vsprintf (char *str, const char *format, va_list ap)
 {
libexec/chrp.c +4 -4
Index: src/libexec/chrp.c
===================================================================
@@ -168,7 +168,7 @@ int exec_load_chrp (inode_t *file, void 
                     if (*(char *)tag->data == 0x0d) {
                         pos++;
                     }
-                    DPRINTF("Boot file: '%s'\n", pos);
+                    DPRINTF("Description: '%s'\n", pos);
                     break;
                 case CHRP_TAG_BOOT_SCRIPT:
                     /* Here is the interresting part... */
@@ -255,7 +255,8 @@ int exec_load_chrp (inode_t *file, void 
                             /* Find file name end */
                         redo:
                             for (endc = pos;
-                                 *endc != ' ' && *endc != '"' && *endc != '\n';
+                                 *endc != ' ' && *endc != '"' &&
+                                 *endc != '\n' && *endc != '\r';
                                  endc++)
                                 continue;
                             if (memcmp(pos, "ofwboot", 7) == 0) {
@@ -274,8 +275,7 @@ int exec_load_chrp (inode_t *file, void 
                             *endc = '/';
                         }
                         /* check if it's a path or just a file */
-                        if (strchr(pos, '/') == NULL ||
-                            (pos[0] == '/' && pos[1] == '/')) {
+                        if (pos[0] == '/' && pos[1] == '/') {
                             unsigned char *bootdir;
                             bootdir = fs_get_boot_dirname(part_fs(part));
                             if (bootdir == NULL) {
Makefile +1 -0
Index: Makefile
===================================================================
@@ -72,6 +72,7 @@ main.out_OBJS:= main.o bootinfos.o bloc.
 main.out_OBJS:= $(addprefix $(OBJDIR)/, $(main.out_OBJS))
 # Pseudo-libc objects
 FORMAT_FUNCS:= _vprintf printf sprintf snprintf vprintf vsprintf vsnprintf
+FORMAT_FUNCS+= dprintf vdprintf
 MEM_FUNCS:= memcpy memccpy mempcpy memmove memcmove mempmove
 MEM_FUNCS+= memset memcmp memchr rawmemchr memrchr memmem
 STR_FUNCS:= strcpy strdup strndup stpcpy stpncpy strcat strncat