From: Kevin O'Connor Date: Sat, 12 Sep 2009 17:20:14 +0000 (-0400) Subject: Add mechanism for describing internal drives in boot menu. X-Git-Tag: rel-0.5.0~107 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=51fd0a17153a8c94c97f9a80afd6e238fb542e3b;p=seabios.git Add mechanism for describing internal drives in boot menu. 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. --- diff --git a/src/ata.c b/src/ata.c index 98d1141..884eae3 100644 --- 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) diff --git a/src/ata.h b/src/ata.h index 66477e2..f04db92 100644 --- 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 diff --git a/src/block.c b/src/block.c index 3550dcd..c24e118 100644 --- a/src/block.c +++ b/src/block.c @@ -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 diff --git a/src/boot.c b/src/boot.c index af2a893..b70d49c 100644 --- a/src/boot.c +++ b/src/boot.c @@ -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; } diff --git a/src/boot.h b/src/boot.h index 816fed5..89a2593 100644 --- a/src/boot.h +++ b/src/boot.h @@ -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 diff --git a/src/coreboot.c b/src/coreboot.c index 314d5c0..1b93f48 100644 --- a/src/coreboot.c +++ b/src/coreboot.c @@ -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) { diff --git a/src/disk.h b/src/disk.h index 36941b7..4c3f8cd 100644 --- a/src/disk.h +++ b/src/disk.h @@ -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); diff --git a/src/floppy.c b/src/floppy.c index 3d8d07d..2489507 100644 --- a/src/floppy.c +++ b/src/floppy.c @@ -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 diff --git a/src/optionroms.c b/src/optionroms.c index cd8f9d1..7d93a87 100644 --- a/src/optionroms.c +++ b/src/optionroms.c @@ -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 diff --git a/src/ramdisk.c b/src/ramdisk.c index 7ac72f8..c6672a7 100644 --- a/src/ramdisk.c +++ b/src/ramdisk.c @@ -12,6 +12,12 @@ #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