ahci/cdrom: shared bounce buffer
[seabios.git] / src / ahci.c
index 1f119bb4fdfaefb80eb69dd78513a8f5804a5c78..9da198968bde4ef037ef8f70ba0068d3ca49caf8 100644 (file)
@@ -24,7 +24,6 @@
 /****************************************************************
  * these bits must run in both 16bit and 32bit modes
  ****************************************************************/
-u8 *ahci_buf_fl VAR16VISIBLE;
 
 // prepare sata command fis
 static void sata_prep_simple(struct sata_cmd_fis *fis, u8 command)
@@ -269,7 +268,7 @@ ahci_disk_readwrite(struct disk_op_s *op, int iswrite)
     // Use a word aligned buffer for AHCI I/O
     int rc;
     struct disk_op_s localop = *op;
-    u8 *alignedbuf_fl = GET_GLOBAL(ahci_buf_fl);
+    u8 *alignedbuf_fl = GET_GLOBAL(bounce_buf_fl);
     u8 *position = op->buf_fl;
 
     localop.buf_fl = alignedbuf_fl;
@@ -541,7 +540,8 @@ static int ahci_port_init(struct ahci_port_s *port)
         dprintf(1, "%s\n", desc);
 
         // Register with bcv system.
-        boot_add_hd(&port->drive, desc, -1);
+        int prio = bootprio_find_ata_device(ctrl->pci_tmp, pnr, 0);
+        boot_add_hd(&port->drive, desc, prio);
     } else {
         // found cdrom (atapi)
         port->drive.blksize = CDROM_SECTOR_SIZE;
@@ -556,8 +556,10 @@ static int ahci_port_init(struct ahci_port_s *port)
         dprintf(1, "%s\n", desc);
 
         // fill cdidmap
-        if (iscd)
-            boot_add_cd(&port->drive, desc, -1);
+        if (iscd) {
+            int prio = bootprio_find_ata_device(ctrl->pci_tmp, pnr, 0);
+            boot_add_cd(&port->drive, desc, prio);
+        }
     }
     return 0;
 }
@@ -590,9 +592,10 @@ ahci_detect(void *data)
 
 // Initialize an ata controller and detect its drives.
 static void
-ahci_init_controller(int bdf)
+ahci_init_controller(struct pci_device *pci)
 {
     struct ahci_ctrl_s *ctrl = malloc_fseg(sizeof(*ctrl));
+    u16 bdf = pci->bdf;
     u32 val;
 
     if (!ctrl) {
@@ -600,12 +603,13 @@ ahci_init_controller(int bdf)
         return;
     }
 
-    ahci_buf_fl = malloc_low(DISK_SECTOR_SIZE);
-    if (!ahci_buf_fl) {
+    if (bounce_buf_init() < 0) {
         warn_noalloc();
+        free(ctrl);
         return;
     }
 
+    ctrl->pci_tmp = pci;
     ctrl->pci_bdf = bdf;
     ctrl->iobase = pci_config_readl(bdf, PCI_BASE_ADDRESS_5);
     ctrl->irq = pci_config_readb(bdf, PCI_INTERRUPT_LINE);
@@ -637,7 +641,7 @@ ahci_init(void)
             continue;
         if (pci->prog_if != 1 /* AHCI rev 1 */)
             continue;
-        ahci_init_controller(pci->bdf);
+        ahci_init_controller(pci);
     }
 }