Index: c/src/lib/libbsp/i386/pc386/ChangeLog
===================================================================
--- c/src/lib/libbsp/i386/pc386/ChangeLog	(revision b30c618ab155cbd3040fc979b3729f3c57fca2dc)
+++ c/src/lib/libbsp/i386/pc386/ChangeLog	(revision 57be444e596c11981ee4cefb2d3922e46d6d0c85)
@@ -1,2 +1,11 @@
+2009-05-30	Chris Johns <chrisj@rtems.org>
+
+	* ide/ide.c: Add initialisation code to reset the IDE devices and
+	to probe them and display their model numbers. Also add code to
+	display the probing to aid bring up new hardware.
+
+	* ide/idecfg.c: Add the --ide-show command to show probing type
+	accessing when finding devices on the configured IDE buses.
+
 2009-05-29	Roxana Leontie <roxana.leontie@gmail.com>
 
Index: c/src/lib/libbsp/i386/pc386/ide/ide.c
===================================================================
--- c/src/lib/libbsp/i386/pc386/ide/ide.c	(revision b30c618ab155cbd3040fc979b3729f3c57fca2dc)
+++ c/src/lib/libbsp/i386/pc386/ide/ide.c	(revision 57be444e596c11981ee4cefb2d3922e46d6d0c85)
@@ -30,8 +30,8 @@
 #include <libchip/ide_ctrl_io.h>
 
+bool pc386_ide_show;
+
 /* #define DEBUG_OUT */
 
-/* Not using this currently */
-#if 0
 static bool pc386_ide_status_busy (uint32_t port,
                                    uint32_t timeout,
@@ -54,5 +54,4 @@
   return false;
 }
-#endif
 
 static bool pc386_ide_status_data_ready (uint32_t port,
@@ -105,4 +104,10 @@
 }
 
+static void wait(volatile uint32_t loops)
+{
+  while (loops)
+    loops--;
+}
+
 /*=========================================================================*\
 | Function:                                                                 |
@@ -123,4 +128,134 @@
 \*=========================================================================*/
 {
+  uint32_t port = IDE_Controller_Table[minor].port1;
+  uint8_t  dev = 0;
+
+  if (pc386_ide_show)
+    printk("IDE%d: port base: %04x\n", minor, port);
+
+  outport_byte(port+IDE_REGISTER_DEVICE_HEAD,
+               (dev << IDE_REGISTER_DEVICE_HEAD_DEV_POS) | 0xE0);
+  wait(10000);
+  outport_byte(port+IDE_REGISTER_DEVICE_CONTROL,
+               IDE_REGISTER_DEVICE_CONTROL_SRST | IDE_REGISTER_DEVICE_CONTROL_nIEN);
+  wait(10000);
+  outport_byte(port+IDE_REGISTER_DEVICE_CONTROL,
+               IDE_REGISTER_DEVICE_CONTROL_nIEN);
+  wait(10000);
+
+  for (dev = 0; dev < 2; dev++)
+  {
+    uint32_t    byte;
+    uint8_t     status;
+    uint8_t     error;
+    uint8_t     cyllsb;
+    uint8_t     cylmsb;
+    const char* label = dev ? " slave" : "master";
+    char        model_number[41];
+    char*       p = &model_number[0];
+
+    memset(model_number, 0, sizeof(model_number));
+
+    outport_byte(port+IDE_REGISTER_DEVICE_HEAD,
+                 (dev << IDE_REGISTER_DEVICE_HEAD_DEV_POS) | 0xE0);
+    /*
+    outport_byte(port+IDE_REGISTER_SECTOR_NUMBER,
+                 (dev << IDE_REGISTER_DEVICE_HEAD_DEV_POS) | IDE_REGISTER_LBA3_L);
+    */
+
+    outport_byte(port+IDE_REGISTER_COMMAND, 0x00);
+    
+    if (!pc386_ide_status_busy (port, 6000, &status))
+      continue;
+    
+    inport_byte(port+IDE_REGISTER_STATUS,        status);
+    inport_byte(port+IDE_REGISTER_ERROR,         error);
+    inport_byte(port+IDE_REGISTER_CYLINDER_LOW,  cyllsb);
+    inport_byte(port+IDE_REGISTER_CYLINDER_HIGH, cylmsb);
+
+    if (pc386_ide_show)
+    {
+      printk("IDE%d:%s: status=%02x\n", minor, label, status);
+      printk("IDE%d:%s: error=%02x\n", minor, label, error);
+      printk("IDE%d:%s: cylinder-low=%02x\n", minor, label, cyllsb);
+      printk("IDE%d:%s: cylinder-high=%02x\n", minor, label, cylmsb);
+    }
+
+#if 0
+    /*
+     * Filter based on the cylinder values and the status.
+     * Taken from grub's ata.c.
+     */
+    if (cyllsb != 0x14 || cylmsb != 0xeb)
+      if (status == 0 || (cyllsb != 0 && cylmsb != 0 &&
+                          cyllsb != 0xc3 && cylmsb != 0x3c))
+      {
+        if (pc386_ide_show)
+          printk("IDE%d:%s: bad device\n", minor, label);
+      }
+#endif
+    
+    outport_byte(port+IDE_REGISTER_COMMAND, 0xec);
+
+    if (!pc386_ide_status_busy (port, 6000, &status))
+    {
+      if (pc386_ide_show)
+        printk("IDE%d:%s: device busy: %02x\n", minor, label, status);
+      continue;
+    }
+    
+    byte = 0;
+    while (byte < 512)
+    {
+      uint16_t word;
+      bool     data_ready;
+
+      if (pc386_ide_show && ((byte % 16) == 0))
+        printk("\n %04x : ", byte);
+      
+      data_ready = pc386_ide_status_data_ready (port, 100, &status);
+
+      if (status & IDE_REGISTER_STATUS_ERR)
+      {
+        inport_byte(port+IDE_REGISTER_ERROR, error);
+        if (error != 4)
+        {
+          if (pc386_ide_show)
+            printk("IDE%d:%s: error=%04x\n", minor, label, error);
+          break;
+        }
+        /*
+         * The device is an ATAPI device.
+         */
+        outport_byte(port+IDE_REGISTER_COMMAND, 0xa1);
+        continue;
+      }
+
+      if (!data_ready)
+        break;
+      
+      inport_word(port+IDE_REGISTER_DATA, word);
+
+      if (pc386_ide_show)
+        printk ("%04x ", word);
+
+      if (byte >= 54 && byte < (54 + 40))
+      {
+        *p = word >> 8;
+        p++;
+        *p = word;
+        p++;
+      }
+        
+      byte += 2;
+    }
+    
+    if (pc386_ide_show)
+      printk("\nbytes read = %d\n", byte);
+
+    if (p != &model_number[0])
+      printk("IDE%d:%s: %s\n", minor, label, model_number);
+  }
+  
   /*
    * FIXME: enable interrupts, if needed
Index: c/src/lib/libbsp/i386/pc386/ide/idecfg.c
===================================================================
--- c/src/lib/libbsp/i386/pc386/ide/idecfg.c	(revision b30c618ab155cbd3040fc979b3729f3c57fca2dc)
+++ c/src/lib/libbsp/i386/pc386/ide/idecfg.c	(revision 57be444e596c11981ee4cefb2d3922e46d6d0c85)
@@ -23,4 +23,6 @@
 #include <libchip/ide_ctrl_cfg.h>
 #include <libchip/ide_ctrl_io.h>
+
+extern bool pc386_ide_show;
 
 /*
@@ -79,5 +81,5 @@
   /*
    * Can have:
-   *  --ide=1,2
+   *  --ide=0,1
    */
   ide = bsp_cmdline_arg ("--ide=");
@@ -97,10 +99,11 @@
       switch (ide[i])
       {
-        case '1':
+        case '0':
           ide1 = true;
           break;
-        case '2':
+        case '1':
           ide2 = true;
           break;
+        case '2':
         case '3':
         case '4':
@@ -113,5 +116,5 @@
           break;
         default:
-        break;
+          break;
       }
     }
@@ -125,3 +128,12 @@
   if (ide2)
     IDE_Controller_Count++;
+
+  /*
+   * Allow the user to get the initialise to print probing
+   * type information.
+   */
+  ide = bsp_cmdline_arg ("--ide-show");
+  
+  if (ide)
+    pc386_ide_show = true;
 }
