2
0

pci.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /*
  2. * QEMU IDE Emulation: PCI Bus support.
  3. *
  4. * Copyright (c) 2003 Fabrice Bellard
  5. * Copyright (c) 2006 Openedhand Ltd.
  6. *
  7. * Permission is hereby granted, free of charge, to any person obtaining a copy
  8. * of this software and associated documentation files (the "Software"), to deal
  9. * in the Software without restriction, including without limitation the rights
  10. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. * copies of the Software, and to permit persons to whom the Software is
  12. * furnished to do so, subject to the following conditions:
  13. *
  14. * The above copyright notice and this permission notice shall be included in
  15. * all copies or substantial portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  20. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. * THE SOFTWARE.
  24. */
  25. #include "qemu/osdep.h"
  26. #include "hw/irq.h"
  27. #include "hw/pci/pci.h"
  28. #include "migration/vmstate.h"
  29. #include "system/dma.h"
  30. #include "qemu/error-report.h"
  31. #include "qemu/module.h"
  32. #include "hw/ide/pci.h"
  33. #include "ide-internal.h"
  34. #include "trace.h"
  35. #define BMDMA_PAGE_SIZE 4096
  36. #define BM_MIGRATION_COMPAT_STATUS_BITS \
  37. (IDE_RETRY_DMA | IDE_RETRY_PIO | \
  38. IDE_RETRY_READ | IDE_RETRY_FLUSH)
  39. static uint64_t pci_ide_status_read(void *opaque, hwaddr addr, unsigned size)
  40. {
  41. IDEBus *bus = opaque;
  42. if (addr != 2 || size != 1) {
  43. return ((uint64_t)1 << (size * 8)) - 1;
  44. }
  45. return ide_status_read(bus, addr + 2);
  46. }
  47. static void pci_ide_ctrl_write(void *opaque, hwaddr addr,
  48. uint64_t data, unsigned size)
  49. {
  50. IDEBus *bus = opaque;
  51. if (addr != 2 || size != 1) {
  52. return;
  53. }
  54. ide_ctrl_write(bus, addr + 2, data);
  55. }
  56. const MemoryRegionOps pci_ide_cmd_le_ops = {
  57. .read = pci_ide_status_read,
  58. .write = pci_ide_ctrl_write,
  59. .endianness = DEVICE_LITTLE_ENDIAN,
  60. };
  61. static uint64_t pci_ide_data_read(void *opaque, hwaddr addr, unsigned size)
  62. {
  63. IDEBus *bus = opaque;
  64. if (size == 1) {
  65. return ide_ioport_read(bus, addr);
  66. } else if (addr == 0) {
  67. if (size == 2) {
  68. return ide_data_readw(bus, addr);
  69. } else {
  70. return ide_data_readl(bus, addr);
  71. }
  72. }
  73. return ((uint64_t)1 << (size * 8)) - 1;
  74. }
  75. static void pci_ide_data_write(void *opaque, hwaddr addr,
  76. uint64_t data, unsigned size)
  77. {
  78. IDEBus *bus = opaque;
  79. if (size == 1) {
  80. ide_ioport_write(bus, addr, data);
  81. } else if (addr == 0) {
  82. if (size == 2) {
  83. ide_data_writew(bus, addr, data);
  84. } else {
  85. ide_data_writel(bus, addr, data);
  86. }
  87. }
  88. }
  89. const MemoryRegionOps pci_ide_data_le_ops = {
  90. .read = pci_ide_data_read,
  91. .write = pci_ide_data_write,
  92. .endianness = DEVICE_LITTLE_ENDIAN,
  93. };
  94. void pci_ide_update_mode(PCIIDEState *s)
  95. {
  96. PCIDevice *d = PCI_DEVICE(s);
  97. uint8_t mode = d->config[PCI_CLASS_PROG];
  98. /*
  99. * This function only configures the BARs/ioports for now: PCI IDE
  100. * controllers must manage their own IRQ routing
  101. */
  102. switch (mode & 0xf) {
  103. case 0xa:
  104. /* Both channels legacy mode */
  105. /*
  106. * TODO: according to the PCI IDE specification the BARs should
  107. * be completely disabled, however Linux for the pegasos2
  108. * machine stil accesses the BAR addresses after switching to legacy
  109. * mode. Hence we leave them active for now.
  110. */
  111. /* Clear interrupt pin */
  112. pci_config_set_interrupt_pin(d->config, 0);
  113. /* Add legacy IDE ports */
  114. if (!s->bus[0].portio_list.owner) {
  115. portio_list_init(&s->bus[0].portio_list, OBJECT(d),
  116. ide_portio_list, &s->bus[0], "ide");
  117. portio_list_add(&s->bus[0].portio_list,
  118. pci_address_space_io(d), 0x1f0);
  119. }
  120. if (!s->bus[0].portio2_list.owner) {
  121. portio_list_init(&s->bus[0].portio2_list, OBJECT(d),
  122. ide_portio2_list, &s->bus[0], "ide");
  123. portio_list_add(&s->bus[0].portio2_list,
  124. pci_address_space_io(d), 0x3f6);
  125. }
  126. if (!s->bus[1].portio_list.owner) {
  127. portio_list_init(&s->bus[1].portio_list, OBJECT(d),
  128. ide_portio_list, &s->bus[1], "ide");
  129. portio_list_add(&s->bus[1].portio_list,
  130. pci_address_space_io(d), 0x170);
  131. }
  132. if (!s->bus[1].portio2_list.owner) {
  133. portio_list_init(&s->bus[1].portio2_list, OBJECT(d),
  134. ide_portio2_list, &s->bus[1], "ide");
  135. portio_list_add(&s->bus[1].portio2_list,
  136. pci_address_space_io(d), 0x376);
  137. }
  138. break;
  139. case 0xf:
  140. /* Both channels native mode */
  141. /* Set interrupt pin */
  142. pci_config_set_interrupt_pin(d->config, 1);
  143. /* Remove legacy IDE ports */
  144. if (s->bus[0].portio_list.owner) {
  145. portio_list_del(&s->bus[0].portio_list);
  146. portio_list_destroy(&s->bus[0].portio_list);
  147. }
  148. if (s->bus[0].portio2_list.owner) {
  149. portio_list_del(&s->bus[0].portio2_list);
  150. portio_list_destroy(&s->bus[0].portio2_list);
  151. }
  152. if (s->bus[1].portio_list.owner) {
  153. portio_list_del(&s->bus[1].portio_list);
  154. portio_list_destroy(&s->bus[1].portio_list);
  155. }
  156. if (s->bus[1].portio2_list.owner) {
  157. portio_list_del(&s->bus[1].portio2_list);
  158. portio_list_destroy(&s->bus[1].portio2_list);
  159. }
  160. break;
  161. }
  162. }
  163. static IDEState *bmdma_active_if(BMDMAState *bmdma)
  164. {
  165. assert(bmdma->bus->retry_unit != (uint8_t)-1);
  166. return bmdma->bus->ifs + bmdma->bus->retry_unit;
  167. }
  168. static void bmdma_start_dma(const IDEDMA *dma, IDEState *s,
  169. BlockCompletionFunc *dma_cb)
  170. {
  171. BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma);
  172. bm->dma_cb = dma_cb;
  173. bm->cur_prd_last = 0;
  174. bm->cur_prd_addr = 0;
  175. bm->cur_prd_len = 0;
  176. if (bm->status & BM_STATUS_DMAING) {
  177. bm->dma_cb(bmdma_active_if(bm), 0);
  178. }
  179. }
  180. /**
  181. * Prepare an sglist based on available PRDs.
  182. * @limit: How many bytes to prepare total.
  183. *
  184. * Returns the number of bytes prepared, -1 on error.
  185. * IDEState.io_buffer_size will contain the number of bytes described
  186. * by the PRDs, whether or not we added them to the sglist.
  187. */
  188. static int32_t bmdma_prepare_buf(const IDEDMA *dma, int32_t limit)
  189. {
  190. BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma);
  191. IDEState *s = bmdma_active_if(bm);
  192. PCIDevice *pci_dev = PCI_DEVICE(bm->pci_dev);
  193. struct {
  194. uint32_t addr;
  195. uint32_t size;
  196. } prd;
  197. int l, len;
  198. pci_dma_sglist_init(&s->sg, pci_dev,
  199. s->nsector / (BMDMA_PAGE_SIZE / BDRV_SECTOR_SIZE) + 1);
  200. s->io_buffer_size = 0;
  201. for(;;) {
  202. if (bm->cur_prd_len == 0) {
  203. /* end of table (with a fail safe of one page) */
  204. if (bm->cur_prd_last ||
  205. (bm->cur_addr - bm->addr) >= BMDMA_PAGE_SIZE) {
  206. break;
  207. }
  208. pci_dma_read(pci_dev, bm->cur_addr, &prd, 8);
  209. bm->cur_addr += 8;
  210. prd.addr = le32_to_cpu(prd.addr);
  211. prd.size = le32_to_cpu(prd.size);
  212. len = prd.size & 0xfffe;
  213. if (len == 0)
  214. len = 0x10000;
  215. bm->cur_prd_len = len;
  216. bm->cur_prd_addr = prd.addr;
  217. bm->cur_prd_last = (prd.size & 0x80000000);
  218. }
  219. l = bm->cur_prd_len;
  220. if (l > 0) {
  221. uint64_t sg_len;
  222. /* Don't add extra bytes to the SGList; consume any remaining
  223. * PRDs from the guest, but ignore them. */
  224. sg_len = MIN(limit - s->sg.size, bm->cur_prd_len);
  225. if (sg_len) {
  226. qemu_sglist_add(&s->sg, bm->cur_prd_addr, sg_len);
  227. }
  228. bm->cur_prd_addr += l;
  229. bm->cur_prd_len -= l;
  230. s->io_buffer_size += l;
  231. }
  232. }
  233. return s->sg.size;
  234. }
  235. /* return 0 if buffer completed */
  236. static int bmdma_rw_buf(const IDEDMA *dma, bool is_write)
  237. {
  238. BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma);
  239. IDEState *s = bmdma_active_if(bm);
  240. PCIDevice *pci_dev = PCI_DEVICE(bm->pci_dev);
  241. struct {
  242. uint32_t addr;
  243. uint32_t size;
  244. } prd;
  245. int l, len;
  246. for(;;) {
  247. l = s->io_buffer_size - s->io_buffer_index;
  248. if (l <= 0)
  249. break;
  250. if (bm->cur_prd_len == 0) {
  251. /* end of table (with a fail safe of one page) */
  252. if (bm->cur_prd_last ||
  253. (bm->cur_addr - bm->addr) >= BMDMA_PAGE_SIZE)
  254. return 0;
  255. pci_dma_read(pci_dev, bm->cur_addr, &prd, 8);
  256. bm->cur_addr += 8;
  257. prd.addr = le32_to_cpu(prd.addr);
  258. prd.size = le32_to_cpu(prd.size);
  259. len = prd.size & 0xfffe;
  260. if (len == 0)
  261. len = 0x10000;
  262. bm->cur_prd_len = len;
  263. bm->cur_prd_addr = prd.addr;
  264. bm->cur_prd_last = (prd.size & 0x80000000);
  265. }
  266. if (l > bm->cur_prd_len)
  267. l = bm->cur_prd_len;
  268. if (l > 0) {
  269. if (is_write) {
  270. pci_dma_write(pci_dev, bm->cur_prd_addr,
  271. s->io_buffer + s->io_buffer_index, l);
  272. } else {
  273. pci_dma_read(pci_dev, bm->cur_prd_addr,
  274. s->io_buffer + s->io_buffer_index, l);
  275. }
  276. bm->cur_prd_addr += l;
  277. bm->cur_prd_len -= l;
  278. s->io_buffer_index += l;
  279. }
  280. }
  281. return 1;
  282. }
  283. static void bmdma_set_inactive(const IDEDMA *dma, bool more)
  284. {
  285. BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma);
  286. bm->dma_cb = NULL;
  287. if (more) {
  288. bm->status |= BM_STATUS_DMAING;
  289. } else {
  290. bm->status &= ~BM_STATUS_DMAING;
  291. }
  292. }
  293. static void bmdma_restart_dma(const IDEDMA *dma)
  294. {
  295. BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma);
  296. bm->cur_addr = bm->addr;
  297. }
  298. static void bmdma_cancel(BMDMAState *bm)
  299. {
  300. if (bm->status & BM_STATUS_DMAING) {
  301. /* cancel DMA request */
  302. bmdma_set_inactive(&bm->dma, false);
  303. }
  304. }
  305. static void bmdma_reset(const IDEDMA *dma)
  306. {
  307. BMDMAState *bm = DO_UPCAST(BMDMAState, dma, dma);
  308. trace_bmdma_reset();
  309. bmdma_cancel(bm);
  310. bm->cmd = 0;
  311. bm->status = 0;
  312. bm->addr = 0;
  313. bm->cur_addr = 0;
  314. bm->cur_prd_last = 0;
  315. bm->cur_prd_addr = 0;
  316. bm->cur_prd_len = 0;
  317. }
  318. static void bmdma_irq(void *opaque, int n, int level)
  319. {
  320. BMDMAState *bm = opaque;
  321. if (!level) {
  322. /* pass through lower */
  323. qemu_set_irq(bm->irq, level);
  324. return;
  325. }
  326. bm->status |= BM_STATUS_INT;
  327. /* trigger the real irq */
  328. qemu_set_irq(bm->irq, level);
  329. }
  330. void bmdma_cmd_writeb(BMDMAState *bm, uint32_t val)
  331. {
  332. trace_bmdma_cmd_writeb(val);
  333. /* Ignore writes to SSBM if it keeps the old value */
  334. if ((val & BM_CMD_START) != (bm->cmd & BM_CMD_START)) {
  335. if (!(val & BM_CMD_START)) {
  336. ide_cancel_dma_sync(ide_bus_active_if(bm->bus));
  337. bm->status &= ~BM_STATUS_DMAING;
  338. } else {
  339. bm->cur_addr = bm->addr;
  340. if (!(bm->status & BM_STATUS_DMAING)) {
  341. bm->status |= BM_STATUS_DMAING;
  342. /* start dma transfer if possible */
  343. if (bm->dma_cb)
  344. bm->dma_cb(bmdma_active_if(bm), 0);
  345. }
  346. }
  347. }
  348. bm->cmd = val & 0x09;
  349. }
  350. void bmdma_status_writeb(BMDMAState *bm, uint32_t val)
  351. {
  352. bm->status = (val & 0x60) | (bm->status & BM_STATUS_DMAING)
  353. | (bm->status & ~val & (BM_STATUS_ERROR | BM_STATUS_INT));
  354. }
  355. static uint64_t bmdma_addr_read(void *opaque, hwaddr addr,
  356. unsigned width)
  357. {
  358. BMDMAState *bm = opaque;
  359. uint32_t mask = (1ULL << (width * 8)) - 1;
  360. uint64_t data;
  361. data = (bm->addr >> (addr * 8)) & mask;
  362. trace_bmdma_addr_read(data);
  363. return data;
  364. }
  365. static void bmdma_addr_write(void *opaque, hwaddr addr,
  366. uint64_t data, unsigned width)
  367. {
  368. BMDMAState *bm = opaque;
  369. int shift = addr * 8;
  370. uint32_t mask = (1ULL << (width * 8)) - 1;
  371. trace_bmdma_addr_write(data);
  372. bm->addr &= ~(mask << shift);
  373. bm->addr |= ((data & mask) << shift) & ~3;
  374. }
  375. MemoryRegionOps bmdma_addr_ioport_ops = {
  376. .read = bmdma_addr_read,
  377. .write = bmdma_addr_write,
  378. .endianness = DEVICE_LITTLE_ENDIAN,
  379. };
  380. static bool ide_bmdma_current_needed(void *opaque)
  381. {
  382. BMDMAState *bm = opaque;
  383. return (bm->cur_prd_len != 0);
  384. }
  385. static bool ide_bmdma_status_needed(void *opaque)
  386. {
  387. BMDMAState *bm = opaque;
  388. /* Older versions abused some bits in the status register for internal
  389. * error state. If any of these bits are set, we must add a subsection to
  390. * transfer the real status register */
  391. uint8_t abused_bits = BM_MIGRATION_COMPAT_STATUS_BITS;
  392. return ((bm->status & abused_bits) != 0);
  393. }
  394. static int ide_bmdma_pre_save(void *opaque)
  395. {
  396. BMDMAState *bm = opaque;
  397. uint8_t abused_bits = BM_MIGRATION_COMPAT_STATUS_BITS;
  398. if (!(bm->status & BM_STATUS_DMAING) && bm->dma_cb) {
  399. bm->bus->error_status =
  400. ide_dma_cmd_to_retry(bmdma_active_if(bm)->dma_cmd);
  401. }
  402. bm->migration_retry_unit = bm->bus->retry_unit;
  403. bm->migration_retry_sector_num = bm->bus->retry_sector_num;
  404. bm->migration_retry_nsector = bm->bus->retry_nsector;
  405. bm->migration_compat_status =
  406. (bm->status & ~abused_bits) | (bm->bus->error_status & abused_bits);
  407. return 0;
  408. }
  409. /* This function accesses bm->bus->error_status which is loaded only after
  410. * BMDMA itself. This is why the function is called from ide_pci_post_load
  411. * instead of being registered with VMState where it would run too early. */
  412. static int ide_bmdma_post_load(void *opaque, int version_id)
  413. {
  414. BMDMAState *bm = opaque;
  415. uint8_t abused_bits = BM_MIGRATION_COMPAT_STATUS_BITS;
  416. if (bm->status == 0) {
  417. bm->status = bm->migration_compat_status & ~abused_bits;
  418. bm->bus->error_status |= bm->migration_compat_status & abused_bits;
  419. }
  420. if (bm->bus->error_status) {
  421. bm->bus->retry_sector_num = bm->migration_retry_sector_num;
  422. bm->bus->retry_nsector = bm->migration_retry_nsector;
  423. bm->bus->retry_unit = bm->migration_retry_unit;
  424. }
  425. return 0;
  426. }
  427. static const VMStateDescription vmstate_bmdma_current = {
  428. .name = "ide bmdma_current",
  429. .version_id = 1,
  430. .minimum_version_id = 1,
  431. .needed = ide_bmdma_current_needed,
  432. .fields = (const VMStateField[]) {
  433. VMSTATE_UINT32(cur_addr, BMDMAState),
  434. VMSTATE_UINT32(cur_prd_last, BMDMAState),
  435. VMSTATE_UINT32(cur_prd_addr, BMDMAState),
  436. VMSTATE_UINT32(cur_prd_len, BMDMAState),
  437. VMSTATE_END_OF_LIST()
  438. }
  439. };
  440. static const VMStateDescription vmstate_bmdma_status = {
  441. .name ="ide bmdma/status",
  442. .version_id = 1,
  443. .minimum_version_id = 1,
  444. .needed = ide_bmdma_status_needed,
  445. .fields = (const VMStateField[]) {
  446. VMSTATE_UINT8(status, BMDMAState),
  447. VMSTATE_END_OF_LIST()
  448. }
  449. };
  450. static const VMStateDescription vmstate_bmdma = {
  451. .name = "ide bmdma",
  452. .version_id = 3,
  453. .minimum_version_id = 0,
  454. .pre_save = ide_bmdma_pre_save,
  455. .fields = (const VMStateField[]) {
  456. VMSTATE_UINT8(cmd, BMDMAState),
  457. VMSTATE_UINT8(migration_compat_status, BMDMAState),
  458. VMSTATE_UINT32(addr, BMDMAState),
  459. VMSTATE_INT64(migration_retry_sector_num, BMDMAState),
  460. VMSTATE_UINT32(migration_retry_nsector, BMDMAState),
  461. VMSTATE_UINT8(migration_retry_unit, BMDMAState),
  462. VMSTATE_END_OF_LIST()
  463. },
  464. .subsections = (const VMStateDescription * const []) {
  465. &vmstate_bmdma_current,
  466. &vmstate_bmdma_status,
  467. NULL
  468. }
  469. };
  470. static int ide_pci_post_load(void *opaque, int version_id)
  471. {
  472. PCIIDEState *d = opaque;
  473. int i;
  474. for(i = 0; i < 2; i++) {
  475. /* current versions always store 0/1, but older version
  476. stored bigger values. We only need last bit */
  477. d->bmdma[i].migration_retry_unit &= 1;
  478. ide_bmdma_post_load(&d->bmdma[i], -1);
  479. }
  480. return 0;
  481. }
  482. const VMStateDescription vmstate_ide_pci = {
  483. .name = "ide",
  484. .version_id = 3,
  485. .minimum_version_id = 0,
  486. .post_load = ide_pci_post_load,
  487. .fields = (const VMStateField[]) {
  488. VMSTATE_PCI_DEVICE(parent_obj, PCIIDEState),
  489. VMSTATE_STRUCT_ARRAY(bmdma, PCIIDEState, 2, 0,
  490. vmstate_bmdma, BMDMAState),
  491. VMSTATE_IDE_BUS_ARRAY(bus, PCIIDEState, 2),
  492. VMSTATE_IDE_DRIVES(bus[0].ifs, PCIIDEState),
  493. VMSTATE_IDE_DRIVES(bus[1].ifs, PCIIDEState),
  494. VMSTATE_END_OF_LIST()
  495. }
  496. };
  497. /* hd_table must contain 4 block drivers */
  498. void pci_ide_create_devs(PCIDevice *dev)
  499. {
  500. PCIIDEState *d = PCI_IDE(dev);
  501. DriveInfo *hd_table[2 * MAX_IDE_DEVS];
  502. static const int bus[4] = { 0, 0, 1, 1 };
  503. static const int unit[4] = { 0, 1, 0, 1 };
  504. int i;
  505. ide_drive_get(hd_table, ARRAY_SIZE(hd_table));
  506. for (i = 0; i < 4; i++) {
  507. if (hd_table[i]) {
  508. ide_bus_create_drive(d->bus + bus[i], unit[i], hd_table[i]);
  509. }
  510. }
  511. }
  512. static const struct IDEDMAOps bmdma_ops = {
  513. .start_dma = bmdma_start_dma,
  514. .prepare_buf = bmdma_prepare_buf,
  515. .rw_buf = bmdma_rw_buf,
  516. .restart_dma = bmdma_restart_dma,
  517. .set_inactive = bmdma_set_inactive,
  518. .reset = bmdma_reset,
  519. };
  520. void bmdma_init(IDEBus *bus, BMDMAState *bm, PCIIDEState *d)
  521. {
  522. if (bus->dma == &bm->dma) {
  523. return;
  524. }
  525. bm->dma.ops = &bmdma_ops;
  526. bus->dma = &bm->dma;
  527. bm->irq = bus->irq;
  528. bus->irq = qemu_allocate_irq(bmdma_irq, bm, 0);
  529. bm->bus = bus;
  530. bm->pci_dev = d;
  531. }
  532. static void pci_ide_init(Object *obj)
  533. {
  534. PCIIDEState *d = PCI_IDE(obj);
  535. qdev_init_gpio_out_named(DEVICE(d), d->isa_irq, "isa-irq",
  536. ARRAY_SIZE(d->isa_irq));
  537. }
  538. static const TypeInfo pci_ide_type_info = {
  539. .name = TYPE_PCI_IDE,
  540. .parent = TYPE_PCI_DEVICE,
  541. .instance_size = sizeof(PCIIDEState),
  542. .instance_init = pci_ide_init,
  543. .abstract = true,
  544. .interfaces = (InterfaceInfo[]) {
  545. { INTERFACE_CONVENTIONAL_PCI_DEVICE },
  546. { },
  547. },
  548. };
  549. static void pci_ide_register_types(void)
  550. {
  551. type_register_static(&pci_ide_type_info);
  552. }
  553. type_init(pci_ide_register_types)