Commit 9be5dafe488088bcff8f8365bc7dd35d3dac5186

Authored by Paul Brook
1 parent 86394e96

LSI SCSI qdev conversion

Signed-off-by: Paul Brook <paul@codesourcery.com>
hw/lsi53c895a.c
... ... @@ -1939,9 +1939,9 @@ static void lsi_mmio_mapfunc(PCIDevice *pci_dev, int region_num,
1939 1939 cpu_register_physical_memory(addr + 0, 0x400, s->mmio_io_addr);
1940 1940 }
1941 1941  
1942   -void lsi_scsi_attach(void *opaque, BlockDriverState *bd, int id)
  1942 +void lsi_scsi_attach(DeviceState *host, BlockDriverState *bd, int id)
1943 1943 {
1944   - LSIState *s = (LSIState *)opaque;
  1944 + LSIState *s = (LSIState *)host;
1945 1945  
1946 1946 if (id < 0) {
1947 1947 for (id = 0; id < LSI_MAX_DEVS; id++) {
... ... @@ -1976,18 +1976,11 @@ static int lsi_scsi_uninit(PCIDevice *d)
1976 1976 return 0;
1977 1977 }
1978 1978  
1979   -void *lsi_scsi_init(PCIBus *bus, int devfn)
  1979 +static void lsi_scsi_init(PCIDevice *dev)
1980 1980 {
1981   - LSIState *s;
  1981 + LSIState *s = (LSIState *)dev;
1982 1982 uint8_t *pci_conf;
1983 1983  
1984   - s = (LSIState *)pci_register_device(bus, "LSI53C895A SCSI HBA",
1985   - sizeof(*s), devfn, NULL, NULL);
1986   - if (s == NULL) {
1987   - fprintf(stderr, "lsi-scsi: Failed to register PCI device\n");
1988   - return NULL;
1989   - }
1990   -
1991 1984 pci_conf = s->pci_dev.config;
1992 1985  
1993 1986 /* PCI Vendor ID (word) */
... ... @@ -2022,5 +2015,12 @@ void *lsi_scsi_init(PCIBus *bus, int devfn)
2022 2015  
2023 2016 lsi_soft_reset(s);
2024 2017  
2025   - return s;
  2018 + scsi_bus_new(&dev->qdev, lsi_scsi_attach);
2026 2019 }
  2020 +
  2021 +static void lsi53c895a_register_devices(void)
  2022 +{
  2023 + pci_qdev_register("lsi53c895a", sizeof(LSIState), lsi_scsi_init);
  2024 +}
  2025 +
  2026 +device_init(lsi53c895a_register_devices);
... ...
... ... @@ -1122,19 +1122,11 @@ static void pc_init1(ram_addr_t ram_size,
1122 1122  
1123 1123 if (pci_enabled) {
1124 1124 int max_bus;
1125   - int bus, unit;
1126   - void *scsi;
  1125 + int bus;
1127 1126  
1128 1127 max_bus = drive_get_max_bus(IF_SCSI);
1129   -
1130 1128 for (bus = 0; bus <= max_bus; bus++) {
1131   - scsi = lsi_scsi_init(pci_bus, -1);
1132   - for (unit = 0; unit < LSI_MAX_DEVS; unit++) {
1133   - index = drive_get_index(IF_SCSI, bus, unit);
1134   - if (index == -1)
1135   - continue;
1136   - lsi_scsi_attach(scsi, drives_table[index].bdrv, unit);
1137   - }
  1129 + pci_create_simple(pci_bus, -1, "lsi53c895a");
1138 1130 }
1139 1131 }
1140 1132  
... ...
hw/pci-hotplug.c
... ... @@ -71,8 +71,8 @@ void drive_hot_add(Monitor *mon, const char *pci_addr, const char *opts)
71 71 switch (type) {
72 72 case IF_SCSI:
73 73 success = 1;
74   - lsi_scsi_attach (dev, drives_table[drive_idx].bdrv,
75   - drives_table[drive_idx].unit);
  74 + lsi_scsi_attach(&dev->qdev, drives_table[drive_idx].bdrv,
  75 + drives_table[drive_idx].unit);
76 76 break;
77 77 default:
78 78 monitor_printf(mon, "Can't hot-add drive to type %d\n", type);
... ... @@ -117,10 +117,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, PCIBus *pci_bus,
117 117  
118 118 switch (type) {
119 119 case IF_SCSI:
120   - opaque = lsi_scsi_init (pci_bus, -1);
121   - if (opaque && drive_idx >= 0)
122   - lsi_scsi_attach (opaque, drives_table[drive_idx].bdrv,
123   - drives_table[drive_idx].unit);
  120 + opaque = pci_create_simple(pci_bus, -1, "lsi53c895a");
124 121 break;
125 122 case IF_VIRTIO:
126 123 opaque = virtio_blk_init (pci_bus, drives_table[drive_idx].bdrv);
... ...
hw/pci.h
... ... @@ -227,8 +227,7 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name);
227 227  
228 228 /* lsi53c895a.c */
229 229 #define LSI_MAX_DEVS 7
230   -void lsi_scsi_attach(void *opaque, BlockDriverState *bd, int id);
231   -void *lsi_scsi_init(PCIBus *bus, int devfn);
  230 +void lsi_scsi_attach(DeviceState *host, BlockDriverState *bd, int id);
232 231  
233 232 /* vmware_vga.c */
234 233 void pci_vmsvga_init(PCIBus *bus);
... ...
hw/realview.c
... ... @@ -32,7 +32,6 @@ static void realview_init(ram_addr_t ram_size,
32 32 CPUState *env;
33 33 ram_addr_t ram_offset;
34 34 qemu_irq *pic;
35   - void *scsi_hba;
36 35 PCIBus *pci_bus;
37 36 NICInfo *nd;
38 37 int n;
... ... @@ -111,16 +110,10 @@ static void realview_init(ram_addr_t ram_size,
111 110 if (usb_enabled) {
112 111 usb_ohci_init_pci(pci_bus, 3, -1);
113 112 }
114   - if (drive_get_max_bus(IF_SCSI) > 0) {
115   - fprintf(stderr, "qemu: too many SCSI bus\n");
116   - exit(1);
117   - }
118   - scsi_hba = lsi_scsi_init(pci_bus, -1);
119   - for (n = 0; n < LSI_MAX_DEVS; n++) {
120   - index = drive_get_index(IF_SCSI, 0, n);
121   - if (index == -1)
122   - continue;
123   - lsi_scsi_attach(scsi_hba, drives_table[index].bdrv, n);
  113 + n = drive_get_max_bus(IF_SCSI);
  114 + while (n >= 0) {
  115 + pci_create_simple(pci_bus, -1, "lsi53c895a");
  116 + n--;
124 117 }
125 118 for(n = 0; n < nb_nics; n++) {
126 119 nd = &nd_table[n];
... ...
hw/versatilepb.c
... ... @@ -163,7 +163,6 @@ static void versatile_init(ram_addr_t ram_size,
163 163 ram_addr_t ram_offset;
164 164 qemu_irq *pic;
165 165 qemu_irq *sic;
166   - void *scsi_hba;
167 166 PCIBus *pci_bus;
168 167 NICInfo *nd;
169 168 int n;
... ... @@ -206,16 +205,10 @@ static void versatile_init(ram_addr_t ram_size,
206 205 if (usb_enabled) {
207 206 usb_ohci_init_pci(pci_bus, 3, -1);
208 207 }
209   - if (drive_get_max_bus(IF_SCSI) > 0) {
210   - fprintf(stderr, "qemu: too many SCSI bus\n");
211   - exit(1);
212   - }
213   - scsi_hba = lsi_scsi_init(pci_bus, -1);
214   - for (n = 0; n < LSI_MAX_DEVS; n++) {
215   - index = drive_get_index(IF_SCSI, 0, n);
216   - if (index == -1)
217   - continue;
218   - lsi_scsi_attach(scsi_hba, drives_table[index].bdrv, n);
  208 + n = drive_get_max_bus(IF_SCSI);
  209 + while (n >= 0) {
  210 + pci_create_simple(pci_bus, -1, "lsi53c895a");
  211 + n--;
219 212 }
220 213  
221 214 sysbus_create_simple("pl011", 0x101f1000, pic[12]);
... ...