@@ -33,6 +33,7 @@ static const char *const if_name[IF_COUNT] = {
[IF_SD] = "sd",
[IF_VIRTIO] = "virtio",
[IF_XEN] = "xen",
+ [IF_AHCI] = "ahci",
};
static const int if_max_devs[IF_COUNT] = {
@@ -158,6 +159,21 @@ int drive_get_max_bus(BlockInterfaceType type)
return max_bus;
}
+int drive_get_max_unit(BlockInterfaceType type)
+{
+ int max_unit;
+ DriveInfo *dinfo;
+
+ max_unit = -1;
+ QTAILQ_FOREACH(dinfo, &drives, next) {
+ if (dinfo->type == type &&
+ dinfo->unit > max_unit) {
+ max_unit = dinfo->unit;
+ }
+ }
+ return max_unit;
+}
+
/* Get a block device. This should only be used for single-drive devices
(e.g. SD/Floppy/MTD). Multi-disk devices (scsi/ide) should use the
appropriate bus. */
@@ -518,7 +534,7 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType default_drive_if)
} else {
/* no id supplied -> create one */
dinfo->id = g_malloc0(32);
- if (type == IF_IDE || type == IF_SCSI)
+ if (type == IF_IDE || type == IF_SCSI || type == IF_AHCI)
mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
if (max_devs)
snprintf(dinfo->id, 32, "%s%i%s%i",
@@ -550,6 +566,7 @@ DriveInfo *drive_init(QemuOpts *opts, BlockInterfaceType default_drive_if)
switch(type) {
case IF_IDE:
+ case IF_AHCI:
case IF_SCSI:
case IF_XEN:
case IF_NONE:
@@ -21,6 +21,7 @@ typedef enum {
IF_DEFAULT = -1, /* for use with drive_add() only */
IF_NONE,
IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
+ IF_AHCI,
IF_COUNT
} BlockInterfaceType;
@@ -63,6 +64,7 @@ static inline int get_default_drive_if(int default_drive_if)
DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
DriveInfo *drive_get_by_index(BlockInterfaceType type, int index);
int drive_get_max_bus(BlockInterfaceType type);
+int drive_get_max_unit(BlockInterfaceType type);
DriveInfo *drive_get_next(BlockInterfaceType type);
void drive_get_ref(DriveInfo *dinfo);
void drive_put_ref(DriveInfo *dinfo);
@@ -35,5 +35,6 @@ int ide_get_bios_chs_trans(BusState *bus, int unit);
/* ide/core.c */
void ide_drive_get(DriveInfo **hd, int max_bus);
+void ahci_drive_get(DriveInfo **hd, int bus, int nports);
#endif /* HW_IDE_H */
@@ -2354,3 +2354,12 @@ void ide_drive_get(DriveInfo **hd, int max_bus)
hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
}
}
+
+void ahci_drive_get(DriveInfo **hd, int bus, int nports)
+{
+ int i;
+
+ for (i = 0; i < nports; i++) {
+ hd[i] = drive_get(IF_AHCI, bus, i);
+ }
+}
@@ -28,8 +28,10 @@
#include <hw/isa.h>
#include "block.h"
#include "dma.h"
+#include "blockdev.h"
#include <hw/ide/pci.h>
+#include <hw/ide/ahci.h>
#define BMDMA_PAGE_SIZE 4096
@@ -504,6 +506,23 @@ void pci_ide_create_devs(PCIDevice *dev, DriveInfo **hd_table)
}
}
+void pci_ahci_create_devs(PCIDevice *pci_dev, DriveInfo **hd_table, int table_size)
+{
+ struct AHCIPCIState *dev = DO_UPCAST(struct AHCIPCIState, card, pci_dev);
+ int i;
+ DriveInfo *drive;
+
+ for (i = 0; i < table_size; i++) {
+ if (hd_table[i] == NULL) {
+ continue;
+ }
+ drive = hd_table[i];
+ assert(drive->type == IF_AHCI);
+ ide_create_drive(&dev->ahci.dev[i].port, 0,
+ hd_table[i]);
+ }
+}
+
static const struct IDEDMAOps bmdma_ops = {
.start_dma = bmdma_start_dma,
.start_transfer = bmdma_start_transfer,
@@ -58,6 +58,7 @@ void bmdma_init(IDEBus *bus, BMDMAState *bm, PCIIDEState *d);
void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val);
extern MemoryRegionOps bmdma_addr_ioport_ops;
void pci_ide_create_devs(PCIDevice *dev, DriveInfo **hd_table);
+void pci_ahci_create_devs(PCIDevice *pci_dev, DriveInfo **hd_table, int table_size);
extern const VMStateDescription vmstate_ide_pci;
#endif