aboutsummaryrefslogtreecommitdiff
path: root/src/ata.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2010-02-21 23:20:10 -0500
committerKevin O'Connor <kevin@koconnor.net>2010-02-21 23:20:10 -0500
commit575ffc8fd1127e3cb8fbb7f587cadfa85eb9b73d (patch)
tree718b84dbf1550276c1d3eb50e487dd160a64d6d9 /src/ata.c
parent0360e8e69bb3a773ceb9d2b091b62c027bca862b (diff)
downloadseabios-hppa-575ffc8fd1127e3cb8fbb7f587cadfa85eb9b73d.zip
seabios-hppa-575ffc8fd1127e3cb8fbb7f587cadfa85eb9b73d.tar.gz
seabios-hppa-575ffc8fd1127e3cb8fbb7f587cadfa85eb9b73d.tar.bz2
Cleanup - build drive description in temp memory during init.
Remove describe_drive() mechanism for calling printf with a drive description. Instead, have each drive build a description in temporary ram during drive initialization. Also, remove fields now unneeded from 'struct disk_s' - model and cntl_info.
Diffstat (limited to 'src/ata.c')
-rw-r--r--src/ata.c97
1 files changed, 43 insertions, 54 deletions
diff --git a/src/ata.c b/src/ata.c
index 3c57f9f..953aef2 100644
--- a/src/ata.c
+++ b/src/ata.c
@@ -711,44 +711,23 @@ extract_version(u16 *buffer)
return version;
}
-// Extract common information from IDENTIFY commands.
-static void
-extract_identify(struct drive_s *drive_g, u16 *buffer)
-{
- dprintf(3, "Identify w0=%x w2=%x\n", buffer[0], buffer[2]);
+#define MAXMODEL 40
+// Extract the ATA/ATAPI model info.
+static char *
+extract_model(char *model, u16 *buffer)
+{
// Read model name
- char *model = drive_g->model;
- int maxsize = ARRAY_SIZE(drive_g->model);
int i;
- for (i=0; i<maxsize/2; i++) {
- u16 v = buffer[27+i];
- model[i*2] = v >> 8;
- model[i*2+1] = v & 0xff;
- }
- model[maxsize-1] = 0x00;
+ for (i=0; i<MAXMODEL/2; i++)
+ *(u16*)&model[i*2] = ntohs(buffer[27+i]);
+ model[MAXMODEL] = 0x00;
// Trim trailing spaces from model name.
- for (i=maxsize-2; i>0 && model[i] == 0x20; i--)
+ for (i=MAXMODEL-1; i>0 && model[i] == 0x20; i--)
model[i] = 0x00;
- // Common flags.
- SET_GLOBAL(drive_g->removable, (buffer[0] & 0x80) ? 1 : 0);
- SET_GLOBAL(drive_g->cntl_info, extract_version(buffer));
-}
-
-// Print out a description of the given atapi drive.
-void
-describe_atapi(struct drive_s *drive_g)
-{
- u8 ataid = drive_g->cntl_id;
- u8 channel = ataid / 2;
- u8 slave = ataid % 2;
- u8 version = drive_g->cntl_info;
- int iscd = drive_g->floppy_type;
- printf("ata%d-%d: %s ATAPI-%d %s", channel, slave
- , drive_g->model, version
- , (iscd ? "CD-Rom/DVD-Rom" : "Device"));
+ return model;
}
// Detect if the given drive is an atapi - initialize it if so.
@@ -761,19 +740,29 @@ init_drive_atapi(struct drive_s *dummy, u16 *buffer)
return NULL;
// Success - setup as ATAPI.
+ char *desc = malloc_tmp(MAXDESCSIZE);
struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g));
- if (! drive_g) {
+ if (!drive_g || !desc) {
warn_noalloc();
+ free(desc);
+ free(drive_g);
return NULL;
}
memset(drive_g, 0, sizeof(*drive_g));
SET_GLOBAL(drive_g->cntl_id, dummy->cntl_id);
- extract_identify(drive_g, buffer);
SET_GLOBAL(drive_g->type, DTYPE_ATAPI);
SET_GLOBAL(drive_g->blksize, CDROM_SECTOR_SIZE);
SET_GLOBAL(drive_g->sectors, (u64)-1);
+ SET_GLOBAL(drive_g->removable, (buffer[0] & 0x80) ? 1 : 0);
u8 iscd = ((buffer[0] >> 8) & 0x1f) == 0x05;
- SET_GLOBAL(drive_g->floppy_type, iscd);
+ u8 ataid = drive_g->cntl_id;
+ u8 channel = ataid / 2;
+ u8 slave = ataid % 2;
+ char model[MAXMODEL+1];
+ drive_g->desc = desc;
+ snprintf(desc, MAXDESCSIZE, "ata%d-%d: %s ATAPI-%d %s", channel, slave
+ , extract_model(model, buffer), extract_version(buffer)
+ , (iscd ? "CD-Rom/DVD-Rom" : "Device"));
// fill cdidmap
if (iscd)
@@ -782,24 +771,6 @@ init_drive_atapi(struct drive_s *dummy, u16 *buffer)
return drive_g;
}
-// Print out a description of the given ata drive.
-void
-describe_ata(struct drive_s *drive_g)
-{
- u8 ataid = drive_g->cntl_id;
- u8 channel = ataid / 2;
- u8 slave = ataid % 2;
- u64 sectors = drive_g->sectors;
- u8 version = drive_g->cntl_info;
- char *model = drive_g->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));
-}
-
// Detect if the given drive is a regular ata drive - initialize it if so.
static struct drive_s *
init_drive_ata(struct drive_s *dummy, u16 *buffer)
@@ -810,14 +781,16 @@ init_drive_ata(struct drive_s *dummy, u16 *buffer)
return NULL;
// Success - setup as ATA.
+ char *desc = malloc_tmp(MAXDESCSIZE);
struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g));
- if (! drive_g) {
+ if (!drive_g || !desc) {
warn_noalloc();
+ free(desc);
+ free(drive_g);
return NULL;
}
memset(drive_g, 0, sizeof(*drive_g));
SET_GLOBAL(drive_g->cntl_id, dummy->cntl_id);
- extract_identify(drive_g, buffer);
SET_GLOBAL(drive_g->type, DTYPE_ATA);
SET_GLOBAL(drive_g->blksize, DISK_SECTOR_SIZE);
@@ -831,6 +804,22 @@ init_drive_ata(struct drive_s *dummy, u16 *buffer)
else
sectors = *(u32*)&buffer[60]; // word 60 and word 61
SET_GLOBAL(drive_g->sectors, sectors);
+ SET_GLOBAL(drive_g->removable, (buffer[0] & 0x80) ? 1 : 0);
+ u8 ataid = drive_g->cntl_id;
+ u8 channel = ataid / 2;
+ u8 slave = ataid % 2;
+ u64 adjsize = sectors >> 11;
+ char adjprefix = 'M';
+ if (adjsize >= (1 << 16)) {
+ adjsize >>= 10;
+ adjprefix = 'G';
+ }
+ char model[MAXMODEL+1];
+ drive_g->desc = desc;
+ snprintf(desc, MAXDESCSIZE, "ata%d-%d: %s ATA-%d Hard-Disk (%u %ciBytes)"
+ , channel, slave
+ , extract_model(model, buffer), extract_version(buffer)
+ , (u32)adjsize, adjprefix);
// Setup disk geometry translation.
setup_translation(drive_g);