Move common "command data block" functions to new file blockcmd.c.
[seabios.git] / src / ata.c
index a27da56b0337589f61cac17c0ad2709384e89321..3c57f9f3b7045ae4dc91186f521833e4ac9801ac 100644 (file)
--- a/src/ata.c
+++ b/src/ata.c
@@ -653,32 +653,18 @@ atapi_cmd_data(struct disk_op_s *op, void *cdbcmd, u16 blocksize)
 fail:
     // Enable interrupts
     outb(ATA_CB_DC_HD15, iobase2+ATA_CB_DC);
-    return ret;
-}
-
-// Read sectors from the cdrom.
-int
-cdrom_read(struct disk_op_s *op)
-{
-    struct cdb_rwdata_10 cmd;
-    memset(&cmd, 0, sizeof(cmd));
-    cmd.command = CDB_CMD_READ_10;
-    cmd.lba = htonl(op->lba);
-    cmd.count = htons(op->count);
-    return atapi_cmd_data(op, &cmd, CDROM_SECTOR_SIZE);
+    if (ret)
+        return DISK_RET_EBADTRACK;
+    return DISK_RET_SUCCESS;
 }
 
 // 16bit command demuxer for ATAPI cdroms.
 int
 process_atapi_op(struct disk_op_s *op)
 {
-    int ret;
     switch (op->command) {
     case CMD_READ:
-        ret = cdrom_read(op);
-        if (ret)
-            return DISK_RET_EBADTRACK;
-        return DISK_RET_SUCCESS;
+        return cdb_read(op);
     case CMD_FORMAT:
     case CMD_WRITE:
         return DISK_RET_EWRITEPROTECT;
@@ -775,9 +761,12 @@ init_drive_atapi(struct drive_s *dummy, u16 *buffer)
         return NULL;
 
     // Success - setup as ATAPI.
-    struct drive_s *drive_g = allocDrive();
-    if (! drive_g)
+    struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g));
+    if (! drive_g) {
+        warn_noalloc();
         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);
@@ -821,9 +810,12 @@ init_drive_ata(struct drive_s *dummy, u16 *buffer)
         return NULL;
 
     // Success - setup as ATA.
-    struct drive_s *drive_g = allocDrive();
-    if (! drive_g)
+    struct drive_s *drive_g = malloc_fseg(sizeof(*drive_g));
+    if (! drive_g) {
+        warn_noalloc();
         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);