Add mechanism for describing internal drives in boot menu.
authorKevin O'Connor <kevin@koconnor.net>
Sat, 12 Sep 2009 17:20:14 +0000 (13:20 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Sat, 12 Sep 2009 17:20:14 +0000 (13:20 -0400)
Allow each drive type to describe itself on the boot menu.
This fixes a bug where driveid was used in place of ataid in the boot
   menu.
Also, expand descriptions for each drive type.
Don't overload the IPL type for BCVs - instead introduce new types.

src/ata.c
src/ata.h
src/block.c
src/boot.c
src/boot.h
src/coreboot.c
src/disk.h
src/floppy.c
src/optionroms.c
src/ramdisk.c

index 98d114159fda800072da2b01e0f4ecb760157d51..884eae3eb55ed8a0399e3ecb94ca61bc89a3695a 100644 (file)
--- a/src/ata.c
+++ b/src/ata.c
@@ -11,7 +11,7 @@
 #include "cmos.h" // inb_cmos
 #include "pic.h" // enable_hwirq
 #include "biosvar.h" // GET_EBDA
-#include "pci.h" // pci_find_class
+#include "pci.h" // foreachpci
 #include "pci_ids.h" // PCI_CLASS_STORAGE_OTHER
 #include "pci_regs.h" // PCI_INTERRUPT_LINE
 #include "boot.h" // add_bcv_hd
@@ -527,6 +527,20 @@ extract_identify(int driveid, u16 *buffer)
 
     // Common flags.
     SET_GLOBAL(Drives.drives[driveid].removable, (buffer[0] & 0x80) ? 1 : 0);
+    SET_GLOBAL(Drives.drives[driveid].cntl_info, extract_version(buffer));
+}
+
+void
+describe_atapi(int driveid)
+{
+    u8 ataid = Drives.drives[driveid].cntl_id;
+    u8 channel = ataid / 2;
+    u8 slave = ataid % 2;
+    u8 version = Drives.drives[driveid].cntl_info;
+    int iscd = Drives.drives[driveid].floppy_type;
+    printf("ata%d-%d: %s ATAPI-%d %s", channel, slave
+           , Drives.drives[driveid].model, version
+           , (iscd ? "CD-Rom/DVD-Rom" : "Device"));
 }
 
 static int
@@ -550,14 +564,7 @@ init_drive_atapi(int driveid, u16 *buffer)
     SET_GLOBAL(Drives.drives[driveid].blksize, CDROM_SECTOR_SIZE);
     SET_GLOBAL(Drives.drives[driveid].sectors, (u64)-1);
     u8 iscd = ((buffer[0] >> 8) & 0x1f) == 0x05;
-
-    // Report drive info to user.
-    u8 ataid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
-    u8 channel = ataid / 2;
-    u8 slave = ataid % 2;
-    printf("ata%d-%d: %s ATAPI-%d %s\n", channel, slave
-           , Drives.drives[driveid].model, extract_version(buffer)
-           , (iscd ? "CD-Rom/DVD-Rom" : "Device"));
+    SET_GLOBAL(Drives.drives[driveid].floppy_type, iscd);
 
     // fill cdidmap
     if (iscd)
@@ -566,6 +573,23 @@ init_drive_atapi(int driveid, u16 *buffer)
     return 0;
 }
 
+void
+describe_ata(int driveid)
+{
+    u8 ataid = Drives.drives[driveid].cntl_id;
+    u8 channel = ataid / 2;
+    u8 slave = ataid % 2;
+    u64 sectors = Drives.drives[driveid].sectors;
+    u8 version = Drives.drives[driveid].cntl_info;
+    char *model = Drives.drives[driveid].model;
+    printf("ata%d-%d: %s ATA-%d Hard-Disk", channel, slave, model, version);
+    u64 sizeinmb = sectors >> 11;
+    if (sizeinmb < (1 << 16))
+        printf(" (%u MiBytes)", (u32)sizeinmb);
+    else
+        printf(" (%u GiBytes)", (u32)(sizeinmb >> 10));
+}
+
 static int
 init_drive_ata(int driveid, u16 *buffer)
 {
@@ -600,21 +624,8 @@ init_drive_ata(int driveid, u16 *buffer)
     // Setup disk geometry translation.
     setup_translation(driveid);
 
-    // Report drive info to user.
-    u8 ataid = GET_GLOBAL(Drives.drives[driveid].cntl_id);
-    u8 channel = ataid / 2;
-    u8 slave = ataid % 2;
-    char *model = Drives.drives[driveid].model;
-    printf("ata%d-%d: %s ATA-%d Hard-Disk ", channel, slave, model
-           , extract_version(buffer));
-    u64 sizeinmb = sectors >> 11;
-    if (sizeinmb < (1 << 16))
-        printf("(%u MiBytes)\n", (u32)sizeinmb);
-    else
-        printf("(%u GiBytes)\n", (u32)(sizeinmb >> 10));
-
     // Register with bcv system.
-    add_bcv_hd(driveid, model);
+    add_bcv_internal(driveid);
 
     return 0;
 }
@@ -697,9 +708,8 @@ ata_detect()
         // check for ATAPI
         u16 buffer[256];
         int ret = init_drive_atapi(driveid, buffer);
-        if (!ret) {
-            // Found an ATAPI drive.
-        } else {
+        if (ret) {
+            // Didn't find an ATAPI drive - look for ATA drive.
             u8 st = inb(iobase1+ATA_CB_STAT);
             if (!st)
                 // Status not set - can't be a valid drive.
@@ -718,6 +728,10 @@ ata_detect()
         }
         SET_GLOBAL(Drives.drivecount, driveid+1);
 
+        // Report drive info to user.
+        describe_drive(driveid);
+        printf("\n");
+
         u16 resetresult = buffer[93];
         dprintf(6, "ata_detect resetresult=%04x\n", resetresult);
         if (!slave && (resetresult & 0xdf61) == 0x4041)
index 66477e202bf258782b9e04aa6ed2fd4601cff7b4..f04db9214642cab53690d73f008639360e3cd90a 100644 (file)
--- a/src/ata.h
+++ b/src/ata.h
@@ -19,6 +19,8 @@ int ata_cmd_packet(int driveid, u8 *cmdbuf, u8 cmdlen
 void ata_setup();
 int process_ata_op(struct disk_op_s *op);
 int process_atapi_op(struct disk_op_s *op);
+void describe_ata(int driveid);
+void describe_atapi(int driveid);
 
 // Global defines -- ATA register and register bits.
 // command block & control block regs
index 3550dcdd28a01025b922536a5d849c54165bf58b..c24e11828c8daa0abf7ace66e541ea55004159cc 100644 (file)
@@ -224,6 +224,31 @@ map_floppy_drive(int driveid)
     }
 }
 
+// Show a one line description (without trailing newline) of a drive.
+void
+describe_drive(int driveid)
+{
+    ASSERT32();
+    u8 type = GET_GLOBAL(Drives.drives[driveid].type);
+    switch (type) {
+    case DTYPE_FLOPPY:
+        describe_floppy(driveid);
+        break;
+    case DTYPE_ATA:
+        describe_ata(driveid);
+        break;
+    case DTYPE_ATAPI:
+        describe_atapi(driveid);
+        break;
+    case DTYPE_RAMDISK:
+        describe_ramdisk(driveid);
+        break;
+    default:
+        printf("Unknown");
+        break;
+    }
+}
+
 
 /****************************************************************
  * 16bit calling interface
index af2a893bff3986f931b780c4caf5deefa3ca19ca..b70d49cb01970870d06dcc7703bea921899fb55d 100644 (file)
@@ -96,7 +96,7 @@ add_bcv(u16 seg, u16 ip, u16 desc)
         return;
 
     struct ipl_entry_s *ie = &IPL.bcv[IPL.bcvcount++];
-    ie->type = IPL_TYPE_BEV;
+    ie->type = BCV_TYPE_EXTERNAL;
     ie->vector = (seg << 16) | ip;
     const char *d = "Legacy option rom";
     if (desc)
@@ -104,9 +104,9 @@ add_bcv(u16 seg, u16 ip, u16 desc)
     ie->description = d;
 }
 
-// Add a bcv entry for an ata harddrive
+// Add a bcv entry for an internal harddrive
 void
-add_bcv_hd(int driveid, const char *desc)
+add_bcv_internal(int driveid)
 {
     if (! CONFIG_BOOT)
         return;
@@ -114,9 +114,9 @@ add_bcv_hd(int driveid, const char *desc)
         return;
 
     struct ipl_entry_s *ie = &IPL.bcv[IPL.bcvcount++];
-    ie->type = IPL_TYPE_HARDDISK;
+    ie->type = BCV_TYPE_INTERNAL;
     ie->vector = driveid;
-    ie->description = desc;
+    ie->description = "";
 }
 
 
@@ -140,7 +140,10 @@ menu_show_floppy(struct ipl_entry_s *ie, int menupos)
 {
     int i;
     for (i = 0; i < Drives.floppycount; i++) {
-        printf("%d. floppy %d\n", menupos + i, i+1);
+        int driveid = Drives.idmap[EXTTYPE_FLOPPY][i];
+        printf("%d. Floppy [", menupos + i);
+        describe_drive(driveid);
+        printf("]\n");
     }
     return Drives.floppycount;
 }
@@ -153,9 +156,10 @@ menu_show_harddisk(struct ipl_entry_s *ie, int menupos)
     for (i = 0; i < IPL.bcvcount; i++) {
         struct ipl_entry_s *ie = &IPL.bcv[i];
         switch (ie->type) {
-        case IPL_TYPE_HARDDISK:
-            printf("%d. ata%d-%d %s\n", menupos + i
-                   , ie->vector / 2, ie->vector % 2, ie->description);
+        case BCV_TYPE_INTERNAL:
+            printf("%d. ", menupos + i);
+            describe_drive(ie->vector);
+            printf("\n");
             break;
         default:
             menu_show_default(ie, menupos+i);
@@ -172,8 +176,9 @@ menu_show_cdrom(struct ipl_entry_s *ie, int menupos)
     int i;
     for (i = 0; i < Drives.cdcount; i++) {
         int driveid = Drives.idmap[EXTTYPE_CD][i];
-        printf("%d. CD-Rom [ata%d-%d %s]\n", menupos + i
-               , driveid / 2, driveid % 2, Drives.drives[driveid].model);
+        printf("%d. CD-Rom [", menupos + i);
+        describe_drive(driveid);
+        printf("]\n");
     }
     return Drives.cdcount;
 }
@@ -275,10 +280,10 @@ static void
 run_bcv(struct ipl_entry_s *ie)
 {
     switch (ie->type) {
-    case IPL_TYPE_HARDDISK:
+    case BCV_TYPE_INTERNAL:
         map_hd_drive(ie->vector);
         break;
-    case IPL_TYPE_BEV:
+    case BCV_TYPE_EXTERNAL:
         call_bcv(ie->vector >> 16, ie->vector & 0xffff);
         break;
     }
index 816fed5a9bf08dba6d486713dd7ba5e8dbd2bbf6..89a25932d67683a70ea2b402ad6834b19a11ded3 100644 (file)
@@ -28,6 +28,9 @@ struct ipl_s {
 #define IPL_TYPE_CBFS        0x20
 #define IPL_TYPE_BEV         0x80
 
+#define BCV_TYPE_EXTERNAL    0x80
+#define BCV_TYPE_INTERNAL    0x02
+
 
 /****************************************************************
  * Function defs
@@ -38,7 +41,7 @@ extern struct ipl_s IPL;
 void boot_setup();
 void add_bev(u16 seg, u16 bev, u16 desc);
 void add_bcv(u16 seg, u16 ip, u16 desc);
-void add_bcv_hd(int driveid, const char *desc);
+void add_bcv_internal(int driveid);
 void boot_prep();
 
 #endif // __BOOT_H
index 314d5c0d438c6a3d4ea49420ff1c2d1afa855524..1b93f480a85aacb36353f28f039652d88442299c 100644 (file)
@@ -442,6 +442,7 @@ cbfs_findfile(const char *fname)
     return NULL;
 }
 
+// Find next file with the given filename prefix.
 struct cbfs_file *
 cbfs_findprefix(const char *prefix, struct cbfs_file *last)
 {
index 36941b71b6422e9aac22c031ee909b63d7918c27..4c3f8cd9e9353c0446742076848062527e9d0686 100644 (file)
@@ -172,7 +172,8 @@ struct drive_s {
     u8  type;         // Detected type of drive (ata/atapi/none)
     u8  removable;    // Removable device flag
     u16 blksize;      // block size
-    int cntl_id;
+    u32 cntl_id;
+    u32 cntl_info;
     u8  floppy_type;  // Type of floppy (only for floppy drives).
 
     char model[41];
@@ -224,13 +225,15 @@ void setup_translation(int driveid);
 void map_floppy_drive(int driveid);
 void map_hd_drive(int driveid);
 void map_cd_drive(int driveid);
+void describe_drive(int driveid);
 int send_disk_op(struct disk_op_s *op);
 void drive_setup();
 
 // floppy.c
 extern struct floppy_ext_dbt_s diskette_param_table2;
 void floppy_setup();
-void addFloppy(int floppyid, int ftype, int driver);
+int addFloppy(int floppyid, int ftype, int driver);
+void describe_floppy(int driveid);
 int find_floppy_type(u32 size);
 int process_floppy_op(struct disk_op_s *op);
 void floppy_tick();
@@ -247,6 +250,7 @@ void cdemu_134b(struct bregs *regs);
 int cdrom_boot(int cdid);
 
 // ramdisk.c
+void describe_ramdisk(int driveid);
 void ramdisk_setup();
 int process_ramdisk_op(struct disk_op_s *op);
 
index 3d8d07d386c3fc21effcc6cbe1923f0f23ba9328..248950715cccedc1aa7a95a48151d25e779ca8f6 100644 (file)
@@ -89,17 +89,17 @@ struct floppyinfo_s FloppyInfo[] VAR16VISIBLE = {
     { {2, 40, 8}, 0x00, 0x27},
 };
 
-void
+int
 addFloppy(int floppyid, int ftype, int driver)
 {
     if (ftype <= 0 || ftype >= ARRAY_SIZE(FloppyInfo)) {
         dprintf(1, "Bad floppy type %d\n", ftype);
-        return;
+        return -1;
     }
 
     int driveid = Drives.drivecount;
     if (driveid >= ARRAY_SIZE(Drives.drives))
-        return;
+        return -1;
     Drives.drivecount++;
     memset(&Drives.drives[driveid], 0, sizeof(Drives.drives[0]));
     Drives.drives[driveid].cntl_id = floppyid;
@@ -112,6 +112,13 @@ addFloppy(int floppyid, int ftype, int driver)
            , sizeof(FloppyInfo[ftype].chs));
 
     map_floppy_drive(driveid);
+    return driveid;
+}
+
+void
+describe_floppy(int driveid)
+{
+    printf("drive %c", 'A' + Drives.drives[driveid].cntl_id);
 }
 
 void
index cd8f9d1a6eb4182a6a104be592e36d35911b3d20..7d93a87b4ad32792ef633e3369b5bfce1af8ce8a 100644 (file)
@@ -9,7 +9,7 @@
 #include "farptr.h" // FLATPTR_TO_SEG
 #include "config.h" // CONFIG_*
 #include "util.h" // dprintf
-#include "pci.h" // pci_find_class
+#include "pci.h" // foreachpci
 #include "pci_regs.h" // PCI_ROM_ADDRESS
 #include "pci_ids.h" // PCI_CLASS_DISPLAY_VGA
 #include "boot.h" // IPL
index 7ac72f82befebb9fc6f18838c24044ace2312b1f..c6672a71ac1ef59b0a2c53a286fe4ecce4413d44 100644 (file)
 
 #define RAMDISK_SECTOR_SIZE 512
 
+void
+describe_ramdisk(int driveid)
+{
+    printf("%s", Drives.drives[driveid].model);
+}
+
 void
 ramdisk_setup()
 {
@@ -43,7 +49,10 @@ ramdisk_setup()
 
     // Setup driver.
     dprintf(1, "Mapping CBFS floppy %s to addr %p\n", cbfs_filename(file), pos);
-    addFloppy((u32)pos, ftype, DTYPE_RAMDISK);
+    int driveid = addFloppy((u32)pos, ftype, DTYPE_RAMDISK);
+    if (driveid >= 0)
+        strtcpy(Drives.drives[driveid].model, cbfs_filename(file)
+                , ARRAY_SIZE(Drives.drives[driveid].model));
 }
 
 static int