microdrive.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644
  1. /*
  2. * QEMU IDE Emulation: microdrive (CF / PCMCIA)
  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/pcmcia.h"
  27. #include "migration/vmstate.h"
  28. #include "qapi/error.h"
  29. #include "qemu/module.h"
  30. #include "sysemu/dma.h"
  31. #include "hw/irq.h"
  32. #include "hw/ide/internal.h"
  33. #include "qom/object.h"
  34. #define TYPE_MICRODRIVE "microdrive"
  35. OBJECT_DECLARE_SIMPLE_TYPE(MicroDriveState, MICRODRIVE)
  36. /***********************************************************/
  37. /* CF-ATA Microdrive */
  38. #define METADATA_SIZE 0x20
  39. /* DSCM-1XXXX Microdrive hard disk with CF+ II / PCMCIA interface. */
  40. struct MicroDriveState {
  41. /*< private >*/
  42. PCMCIACardState parent_obj;
  43. /*< public >*/
  44. IDEBus bus;
  45. uint32_t attr_base;
  46. uint32_t io_base;
  47. /* Card state */
  48. uint8_t opt;
  49. uint8_t stat;
  50. uint8_t pins;
  51. uint8_t ctrl;
  52. uint16_t io;
  53. uint8_t cycle;
  54. };
  55. /* Register bitfields */
  56. enum md_opt {
  57. OPT_MODE_MMAP = 0,
  58. OPT_MODE_IOMAP16 = 1,
  59. OPT_MODE_IOMAP1 = 2,
  60. OPT_MODE_IOMAP2 = 3,
  61. OPT_MODE = 0x3f,
  62. OPT_LEVIREQ = 0x40,
  63. OPT_SRESET = 0x80,
  64. };
  65. enum md_cstat {
  66. STAT_INT = 0x02,
  67. STAT_PWRDWN = 0x04,
  68. STAT_XE = 0x10,
  69. STAT_IOIS8 = 0x20,
  70. STAT_SIGCHG = 0x40,
  71. STAT_CHANGED = 0x80,
  72. };
  73. enum md_pins {
  74. PINS_MRDY = 0x02,
  75. PINS_CRDY = 0x20,
  76. };
  77. enum md_ctrl {
  78. CTRL_IEN = 0x02,
  79. CTRL_SRST = 0x04,
  80. };
  81. static inline void md_interrupt_update(MicroDriveState *s)
  82. {
  83. PCMCIACardState *card = PCMCIA_CARD(s);
  84. if (card->slot == NULL) {
  85. return;
  86. }
  87. qemu_set_irq(card->slot->irq,
  88. !(s->stat & STAT_INT) && /* Inverted */
  89. !(s->ctrl & (CTRL_IEN | CTRL_SRST)) &&
  90. !(s->opt & OPT_SRESET));
  91. }
  92. static void md_set_irq(void *opaque, int irq, int level)
  93. {
  94. MicroDriveState *s = opaque;
  95. if (level) {
  96. s->stat |= STAT_INT;
  97. } else {
  98. s->stat &= ~STAT_INT;
  99. }
  100. md_interrupt_update(s);
  101. }
  102. static void md_reset(DeviceState *dev)
  103. {
  104. MicroDriveState *s = MICRODRIVE(dev);
  105. s->opt = OPT_MODE_MMAP;
  106. s->stat = 0;
  107. s->pins = 0;
  108. s->cycle = 0;
  109. s->ctrl = 0;
  110. ide_bus_reset(&s->bus);
  111. }
  112. static uint8_t md_attr_read(PCMCIACardState *card, uint32_t at)
  113. {
  114. MicroDriveState *s = MICRODRIVE(card);
  115. PCMCIACardClass *pcc = PCMCIA_CARD_GET_CLASS(card);
  116. if (at < s->attr_base) {
  117. if (at < pcc->cis_len) {
  118. return pcc->cis[at];
  119. } else {
  120. return 0x00;
  121. }
  122. }
  123. at -= s->attr_base;
  124. switch (at) {
  125. case 0x00: /* Configuration Option Register */
  126. return s->opt;
  127. case 0x02: /* Card Configuration Status Register */
  128. if (s->ctrl & CTRL_IEN) {
  129. return s->stat & ~STAT_INT;
  130. } else {
  131. return s->stat;
  132. }
  133. case 0x04: /* Pin Replacement Register */
  134. return (s->pins & PINS_CRDY) | 0x0c;
  135. case 0x06: /* Socket and Copy Register */
  136. return 0x00;
  137. #ifdef VERBOSE
  138. default:
  139. printf("%s: Bad attribute space register %02x\n", __func__, at);
  140. #endif
  141. }
  142. return 0;
  143. }
  144. static void md_attr_write(PCMCIACardState *card, uint32_t at, uint8_t value)
  145. {
  146. MicroDriveState *s = MICRODRIVE(card);
  147. at -= s->attr_base;
  148. switch (at) {
  149. case 0x00: /* Configuration Option Register */
  150. s->opt = value & 0xcf;
  151. if (value & OPT_SRESET) {
  152. device_cold_reset(DEVICE(s));
  153. }
  154. md_interrupt_update(s);
  155. break;
  156. case 0x02: /* Card Configuration Status Register */
  157. if ((s->stat ^ value) & STAT_PWRDWN) {
  158. s->pins |= PINS_CRDY;
  159. }
  160. s->stat &= 0x82;
  161. s->stat |= value & 0x74;
  162. md_interrupt_update(s);
  163. /* Word 170 in Identify Device must be equal to STAT_XE */
  164. break;
  165. case 0x04: /* Pin Replacement Register */
  166. s->pins &= PINS_CRDY;
  167. s->pins |= value & PINS_MRDY;
  168. break;
  169. case 0x06: /* Socket and Copy Register */
  170. break;
  171. default:
  172. printf("%s: Bad attribute space register %02x\n", __func__, at);
  173. }
  174. }
  175. static uint16_t md_common_read(PCMCIACardState *card, uint32_t at)
  176. {
  177. MicroDriveState *s = MICRODRIVE(card);
  178. IDEState *ifs;
  179. uint16_t ret;
  180. at -= s->io_base;
  181. switch (s->opt & OPT_MODE) {
  182. case OPT_MODE_MMAP:
  183. if ((at & ~0x3ff) == 0x400) {
  184. at = 0;
  185. }
  186. break;
  187. case OPT_MODE_IOMAP16:
  188. at &= 0xf;
  189. break;
  190. case OPT_MODE_IOMAP1:
  191. if ((at & ~0xf) == 0x3f0) {
  192. at -= 0x3e8;
  193. } else if ((at & ~0xf) == 0x1f0) {
  194. at -= 0x1f0;
  195. }
  196. break;
  197. case OPT_MODE_IOMAP2:
  198. if ((at & ~0xf) == 0x370) {
  199. at -= 0x368;
  200. } else if ((at & ~0xf) == 0x170) {
  201. at -= 0x170;
  202. }
  203. }
  204. switch (at) {
  205. case 0x0: /* Even RD Data */
  206. case 0x8:
  207. return ide_data_readw(&s->bus, 0);
  208. /* TODO: 8-bit accesses */
  209. if (s->cycle) {
  210. ret = s->io >> 8;
  211. } else {
  212. s->io = ide_data_readw(&s->bus, 0);
  213. ret = s->io & 0xff;
  214. }
  215. s->cycle = !s->cycle;
  216. return ret;
  217. case 0x9: /* Odd RD Data */
  218. return s->io >> 8;
  219. case 0xd: /* Error */
  220. return ide_ioport_read(&s->bus, 0x1);
  221. case 0xe: /* Alternate Status */
  222. ifs = ide_bus_active_if(&s->bus);
  223. if (ifs->blk) {
  224. return ifs->status;
  225. } else {
  226. return 0;
  227. }
  228. case 0xf: /* Device Address */
  229. ifs = ide_bus_active_if(&s->bus);
  230. return 0xc2 | ((~ifs->select << 2) & 0x3c);
  231. default:
  232. return ide_ioport_read(&s->bus, at);
  233. }
  234. return 0;
  235. }
  236. static void md_common_write(PCMCIACardState *card, uint32_t at, uint16_t value)
  237. {
  238. MicroDriveState *s = MICRODRIVE(card);
  239. at -= s->io_base;
  240. switch (s->opt & OPT_MODE) {
  241. case OPT_MODE_MMAP:
  242. if ((at & ~0x3ff) == 0x400) {
  243. at = 0;
  244. }
  245. break;
  246. case OPT_MODE_IOMAP16:
  247. at &= 0xf;
  248. break;
  249. case OPT_MODE_IOMAP1:
  250. if ((at & ~0xf) == 0x3f0) {
  251. at -= 0x3e8;
  252. } else if ((at & ~0xf) == 0x1f0) {
  253. at -= 0x1f0;
  254. }
  255. break;
  256. case OPT_MODE_IOMAP2:
  257. if ((at & ~0xf) == 0x370) {
  258. at -= 0x368;
  259. } else if ((at & ~0xf) == 0x170) {
  260. at -= 0x170;
  261. }
  262. }
  263. switch (at) {
  264. case 0x0: /* Even WR Data */
  265. case 0x8:
  266. ide_data_writew(&s->bus, 0, value);
  267. break;
  268. /* TODO: 8-bit accesses */
  269. if (s->cycle) {
  270. ide_data_writew(&s->bus, 0, s->io | (value << 8));
  271. } else {
  272. s->io = value & 0xff;
  273. }
  274. s->cycle = !s->cycle;
  275. break;
  276. case 0x9:
  277. s->io = value & 0xff;
  278. s->cycle = !s->cycle;
  279. break;
  280. case 0xd: /* Features */
  281. ide_ioport_write(&s->bus, 0x1, value);
  282. break;
  283. case 0xe: /* Device Control */
  284. s->ctrl = value;
  285. if (value & CTRL_SRST) {
  286. device_cold_reset(DEVICE(s));
  287. }
  288. md_interrupt_update(s);
  289. break;
  290. default:
  291. if (s->stat & STAT_PWRDWN) {
  292. s->pins |= PINS_CRDY;
  293. s->stat &= ~STAT_PWRDWN;
  294. }
  295. ide_ioport_write(&s->bus, at, value);
  296. }
  297. }
  298. static const VMStateDescription vmstate_microdrive = {
  299. .name = "microdrive",
  300. .version_id = 3,
  301. .minimum_version_id = 0,
  302. .fields = (VMStateField[]) {
  303. VMSTATE_UINT8(opt, MicroDriveState),
  304. VMSTATE_UINT8(stat, MicroDriveState),
  305. VMSTATE_UINT8(pins, MicroDriveState),
  306. VMSTATE_UINT8(ctrl, MicroDriveState),
  307. VMSTATE_UINT16(io, MicroDriveState),
  308. VMSTATE_UINT8(cycle, MicroDriveState),
  309. VMSTATE_IDE_BUS(bus, MicroDriveState),
  310. VMSTATE_IDE_DRIVES(bus.ifs, MicroDriveState),
  311. VMSTATE_END_OF_LIST()
  312. }
  313. };
  314. static const uint8_t dscm1xxxx_cis[0x14a] = {
  315. [0x000] = CISTPL_DEVICE, /* 5V Device Information */
  316. [0x002] = 0x03, /* Tuple length = 4 bytes */
  317. [0x004] = 0xdb, /* ID: DTYPE_FUNCSPEC, non WP, DSPEED_150NS */
  318. [0x006] = 0x01, /* Size = 2K bytes */
  319. [0x008] = CISTPL_ENDMARK,
  320. [0x00a] = CISTPL_DEVICE_OC, /* Additional Device Information */
  321. [0x00c] = 0x04, /* Tuple length = 4 byest */
  322. [0x00e] = 0x03, /* Conditions: Ext = 0, Vcc 3.3V, MWAIT = 1 */
  323. [0x010] = 0xdb, /* ID: DTYPE_FUNCSPEC, non WP, DSPEED_150NS */
  324. [0x012] = 0x01, /* Size = 2K bytes */
  325. [0x014] = CISTPL_ENDMARK,
  326. [0x016] = CISTPL_JEDEC_C, /* JEDEC ID */
  327. [0x018] = 0x02, /* Tuple length = 2 bytes */
  328. [0x01a] = 0xdf, /* PC Card ATA with no Vpp required */
  329. [0x01c] = 0x01,
  330. [0x01e] = CISTPL_MANFID, /* Manufacture ID */
  331. [0x020] = 0x04, /* Tuple length = 4 bytes */
  332. [0x022] = 0xa4, /* TPLMID_MANF = 00a4 (IBM) */
  333. [0x024] = 0x00,
  334. [0x026] = 0x00, /* PLMID_CARD = 0000 */
  335. [0x028] = 0x00,
  336. [0x02a] = CISTPL_VERS_1, /* Level 1 Version */
  337. [0x02c] = 0x12, /* Tuple length = 23 bytes */
  338. [0x02e] = 0x04, /* Major Version = JEIDA 4.2 / PCMCIA 2.1 */
  339. [0x030] = 0x01, /* Minor Version = 1 */
  340. [0x032] = 'I',
  341. [0x034] = 'B',
  342. [0x036] = 'M',
  343. [0x038] = 0x00,
  344. [0x03a] = 'm',
  345. [0x03c] = 'i',
  346. [0x03e] = 'c',
  347. [0x040] = 'r',
  348. [0x042] = 'o',
  349. [0x044] = 'd',
  350. [0x046] = 'r',
  351. [0x048] = 'i',
  352. [0x04a] = 'v',
  353. [0x04c] = 'e',
  354. [0x04e] = 0x00,
  355. [0x050] = CISTPL_ENDMARK,
  356. [0x052] = CISTPL_FUNCID, /* Function ID */
  357. [0x054] = 0x02, /* Tuple length = 2 bytes */
  358. [0x056] = 0x04, /* TPLFID_FUNCTION = Fixed Disk */
  359. [0x058] = 0x01, /* TPLFID_SYSINIT: POST = 1, ROM = 0 */
  360. [0x05a] = CISTPL_FUNCE, /* Function Extension */
  361. [0x05c] = 0x02, /* Tuple length = 2 bytes */
  362. [0x05e] = 0x01, /* TPLFE_TYPE = Disk Device Interface */
  363. [0x060] = 0x01, /* TPLFE_DATA = PC Card ATA Interface */
  364. [0x062] = CISTPL_FUNCE, /* Function Extension */
  365. [0x064] = 0x03, /* Tuple length = 3 bytes */
  366. [0x066] = 0x02, /* TPLFE_TYPE = Basic PC Card ATA Interface */
  367. [0x068] = 0x08, /* TPLFE_DATA: Rotating, Unique, Single */
  368. [0x06a] = 0x0f, /* TPLFE_DATA: Sleep, Standby, Idle, Auto */
  369. [0x06c] = CISTPL_CONFIG, /* Configuration */
  370. [0x06e] = 0x05, /* Tuple length = 5 bytes */
  371. [0x070] = 0x01, /* TPCC_RASZ = 2 bytes, TPCC_RMSZ = 1 byte */
  372. [0x072] = 0x07, /* TPCC_LAST = 7 */
  373. [0x074] = 0x00, /* TPCC_RADR = 0200 */
  374. [0x076] = 0x02,
  375. [0x078] = 0x0f, /* TPCC_RMSK = 200, 202, 204, 206 */
  376. [0x07a] = CISTPL_CFTABLE_ENTRY, /* 16-bit PC Card Configuration */
  377. [0x07c] = 0x0b, /* Tuple length = 11 bytes */
  378. [0x07e] = 0xc0, /* TPCE_INDX = Memory Mode, Default, Iface */
  379. [0x080] = 0xc0, /* TPCE_IF = Memory, no BVDs, no WP, READY */
  380. [0x082] = 0xa1, /* TPCE_FS = Vcc only, no I/O, Memory, Misc */
  381. [0x084] = 0x27, /* NomV = 1, MinV = 1, MaxV = 1, Peakl = 1 */
  382. [0x086] = 0x55, /* NomV: 5.0 V */
  383. [0x088] = 0x4d, /* MinV: 4.5 V */
  384. [0x08a] = 0x5d, /* MaxV: 5.5 V */
  385. [0x08c] = 0x4e, /* Peakl: 450 mA */
  386. [0x08e] = 0x08, /* TPCE_MS = 1 window, 1 byte, Host address */
  387. [0x090] = 0x00, /* Window descriptor: Window length = 0 */
  388. [0x092] = 0x20, /* TPCE_MI: support power down mode, RW */
  389. [0x094] = CISTPL_CFTABLE_ENTRY, /* 16-bit PC Card Configuration */
  390. [0x096] = 0x06, /* Tuple length = 6 bytes */
  391. [0x098] = 0x00, /* TPCE_INDX = Memory Mode, no Default */
  392. [0x09a] = 0x01, /* TPCE_FS = Vcc only, no I/O, no Memory */
  393. [0x09c] = 0x21, /* NomV = 1, MinV = 0, MaxV = 0, Peakl = 1 */
  394. [0x09e] = 0xb5, /* NomV: 3.3 V */
  395. [0x0a0] = 0x1e,
  396. [0x0a2] = 0x3e, /* Peakl: 350 mA */
  397. [0x0a4] = CISTPL_CFTABLE_ENTRY, /* 16-bit PC Card Configuration */
  398. [0x0a6] = 0x0d, /* Tuple length = 13 bytes */
  399. [0x0a8] = 0xc1, /* TPCE_INDX = I/O and Memory Mode, Default */
  400. [0x0aa] = 0x41, /* TPCE_IF = I/O and Memory, no BVD, no WP */
  401. [0x0ac] = 0x99, /* TPCE_FS = Vcc only, I/O, Interrupt, Misc */
  402. [0x0ae] = 0x27, /* NomV = 1, MinV = 1, MaxV = 1, Peakl = 1 */
  403. [0x0b0] = 0x55, /* NomV: 5.0 V */
  404. [0x0b2] = 0x4d, /* MinV: 4.5 V */
  405. [0x0b4] = 0x5d, /* MaxV: 5.5 V */
  406. [0x0b6] = 0x4e, /* Peakl: 450 mA */
  407. [0x0b8] = 0x64, /* TPCE_IO = 16-byte boundary, 16/8 accesses */
  408. [0x0ba] = 0xf0, /* TPCE_IR = MASK, Level, Pulse, Share */
  409. [0x0bc] = 0xff, /* IRQ0..IRQ7 supported */
  410. [0x0be] = 0xff, /* IRQ8..IRQ15 supported */
  411. [0x0c0] = 0x20, /* TPCE_MI = support power down mode */
  412. [0x0c2] = CISTPL_CFTABLE_ENTRY, /* 16-bit PC Card Configuration */
  413. [0x0c4] = 0x06, /* Tuple length = 6 bytes */
  414. [0x0c6] = 0x01, /* TPCE_INDX = I/O and Memory Mode */
  415. [0x0c8] = 0x01, /* TPCE_FS = Vcc only, no I/O, no Memory */
  416. [0x0ca] = 0x21, /* NomV = 1, MinV = 0, MaxV = 0, Peakl = 1 */
  417. [0x0cc] = 0xb5, /* NomV: 3.3 V */
  418. [0x0ce] = 0x1e,
  419. [0x0d0] = 0x3e, /* Peakl: 350 mA */
  420. [0x0d2] = CISTPL_CFTABLE_ENTRY, /* 16-bit PC Card Configuration */
  421. [0x0d4] = 0x12, /* Tuple length = 18 bytes */
  422. [0x0d6] = 0xc2, /* TPCE_INDX = I/O Primary Mode */
  423. [0x0d8] = 0x41, /* TPCE_IF = I/O and Memory, no BVD, no WP */
  424. [0x0da] = 0x99, /* TPCE_FS = Vcc only, I/O, Interrupt, Misc */
  425. [0x0dc] = 0x27, /* NomV = 1, MinV = 1, MaxV = 1, Peakl = 1 */
  426. [0x0de] = 0x55, /* NomV: 5.0 V */
  427. [0x0e0] = 0x4d, /* MinV: 4.5 V */
  428. [0x0e2] = 0x5d, /* MaxV: 5.5 V */
  429. [0x0e4] = 0x4e, /* Peakl: 450 mA */
  430. [0x0e6] = 0xea, /* TPCE_IO = 1K boundary, 16/8 access, Range */
  431. [0x0e8] = 0x61, /* Range: 2 fields, 2 bytes addr, 1 byte len */
  432. [0x0ea] = 0xf0, /* Field 1 address = 0x01f0 */
  433. [0x0ec] = 0x01,
  434. [0x0ee] = 0x07, /* Address block length = 8 */
  435. [0x0f0] = 0xf6, /* Field 2 address = 0x03f6 */
  436. [0x0f2] = 0x03,
  437. [0x0f4] = 0x01, /* Address block length = 2 */
  438. [0x0f6] = 0xee, /* TPCE_IR = IRQ E, Level, Pulse, Share */
  439. [0x0f8] = 0x20, /* TPCE_MI = support power down mode */
  440. [0x0fa] = CISTPL_CFTABLE_ENTRY, /* 16-bit PC Card Configuration */
  441. [0x0fc] = 0x06, /* Tuple length = 6 bytes */
  442. [0x0fe] = 0x02, /* TPCE_INDX = I/O Primary Mode, no Default */
  443. [0x100] = 0x01, /* TPCE_FS = Vcc only, no I/O, no Memory */
  444. [0x102] = 0x21, /* NomV = 1, MinV = 0, MaxV = 0, Peakl = 1 */
  445. [0x104] = 0xb5, /* NomV: 3.3 V */
  446. [0x106] = 0x1e,
  447. [0x108] = 0x3e, /* Peakl: 350 mA */
  448. [0x10a] = CISTPL_CFTABLE_ENTRY, /* 16-bit PC Card Configuration */
  449. [0x10c] = 0x12, /* Tuple length = 18 bytes */
  450. [0x10e] = 0xc3, /* TPCE_INDX = I/O Secondary Mode, Default */
  451. [0x110] = 0x41, /* TPCE_IF = I/O and Memory, no BVD, no WP */
  452. [0x112] = 0x99, /* TPCE_FS = Vcc only, I/O, Interrupt, Misc */
  453. [0x114] = 0x27, /* NomV = 1, MinV = 1, MaxV = 1, Peakl = 1 */
  454. [0x116] = 0x55, /* NomV: 5.0 V */
  455. [0x118] = 0x4d, /* MinV: 4.5 V */
  456. [0x11a] = 0x5d, /* MaxV: 5.5 V */
  457. [0x11c] = 0x4e, /* Peakl: 450 mA */
  458. [0x11e] = 0xea, /* TPCE_IO = 1K boundary, 16/8 access, Range */
  459. [0x120] = 0x61, /* Range: 2 fields, 2 byte addr, 1 byte len */
  460. [0x122] = 0x70, /* Field 1 address = 0x0170 */
  461. [0x124] = 0x01,
  462. [0x126] = 0x07, /* Address block length = 8 */
  463. [0x128] = 0x76, /* Field 2 address = 0x0376 */
  464. [0x12a] = 0x03,
  465. [0x12c] = 0x01, /* Address block length = 2 */
  466. [0x12e] = 0xee, /* TPCE_IR = IRQ E, Level, Pulse, Share */
  467. [0x130] = 0x20, /* TPCE_MI = support power down mode */
  468. [0x132] = CISTPL_CFTABLE_ENTRY, /* 16-bit PC Card Configuration */
  469. [0x134] = 0x06, /* Tuple length = 6 bytes */
  470. [0x136] = 0x03, /* TPCE_INDX = I/O Secondary Mode */
  471. [0x138] = 0x01, /* TPCE_FS = Vcc only, no I/O, no Memory */
  472. [0x13a] = 0x21, /* NomV = 1, MinV = 0, MaxV = 0, Peakl = 1 */
  473. [0x13c] = 0xb5, /* NomV: 3.3 V */
  474. [0x13e] = 0x1e,
  475. [0x140] = 0x3e, /* Peakl: 350 mA */
  476. [0x142] = CISTPL_NO_LINK, /* No Link */
  477. [0x144] = 0x00, /* Tuple length = 0 bytes */
  478. [0x146] = CISTPL_END, /* Tuple End */
  479. };
  480. #define TYPE_DSCM1XXXX "dscm1xxxx"
  481. static int dscm1xxxx_attach(PCMCIACardState *card)
  482. {
  483. MicroDriveState *md = MICRODRIVE(card);
  484. PCMCIACardClass *pcc = PCMCIA_CARD_GET_CLASS(card);
  485. md->attr_base = pcc->cis[0x74] | (pcc->cis[0x76] << 8);
  486. md->io_base = 0x0;
  487. device_cold_reset(DEVICE(md));
  488. md_interrupt_update(md);
  489. return 0;
  490. }
  491. static int dscm1xxxx_detach(PCMCIACardState *card)
  492. {
  493. MicroDriveState *md = MICRODRIVE(card);
  494. device_cold_reset(DEVICE(md));
  495. return 0;
  496. }
  497. PCMCIACardState *dscm1xxxx_init(DriveInfo *dinfo)
  498. {
  499. MicroDriveState *md;
  500. md = MICRODRIVE(object_new(TYPE_DSCM1XXXX));
  501. qdev_realize(DEVICE(md), NULL, &error_fatal);
  502. if (dinfo != NULL) {
  503. ide_bus_create_drive(&md->bus, 0, dinfo);
  504. }
  505. md->bus.ifs[0].drive_kind = IDE_CFATA;
  506. md->bus.ifs[0].mdata_size = METADATA_SIZE;
  507. md->bus.ifs[0].mdata_storage = g_malloc0(METADATA_SIZE);
  508. return PCMCIA_CARD(md);
  509. }
  510. static void dscm1xxxx_class_init(ObjectClass *oc, void *data)
  511. {
  512. PCMCIACardClass *pcc = PCMCIA_CARD_CLASS(oc);
  513. DeviceClass *dc = DEVICE_CLASS(oc);
  514. pcc->cis = dscm1xxxx_cis;
  515. pcc->cis_len = sizeof(dscm1xxxx_cis);
  516. pcc->attach = dscm1xxxx_attach;
  517. pcc->detach = dscm1xxxx_detach;
  518. /* Reason: Needs to be wired-up in code, see dscm1xxxx_init() */
  519. dc->user_creatable = false;
  520. }
  521. static const TypeInfo dscm1xxxx_type_info = {
  522. .name = TYPE_DSCM1XXXX,
  523. .parent = TYPE_MICRODRIVE,
  524. .class_init = dscm1xxxx_class_init,
  525. };
  526. static void microdrive_realize(DeviceState *dev, Error **errp)
  527. {
  528. MicroDriveState *md = MICRODRIVE(dev);
  529. ide_bus_init_output_irq(&md->bus, qemu_allocate_irq(md_set_irq, md, 0));
  530. }
  531. static void microdrive_init(Object *obj)
  532. {
  533. MicroDriveState *md = MICRODRIVE(obj);
  534. ide_bus_init(&md->bus, sizeof(md->bus), DEVICE(obj), 0, 1);
  535. }
  536. static void microdrive_class_init(ObjectClass *oc, void *data)
  537. {
  538. DeviceClass *dc = DEVICE_CLASS(oc);
  539. PCMCIACardClass *pcc = PCMCIA_CARD_CLASS(oc);
  540. pcc->attr_read = md_attr_read;
  541. pcc->attr_write = md_attr_write;
  542. pcc->common_read = md_common_read;
  543. pcc->common_write = md_common_write;
  544. pcc->io_read = md_common_read;
  545. pcc->io_write = md_common_write;
  546. dc->realize = microdrive_realize;
  547. dc->reset = md_reset;
  548. dc->vmsd = &vmstate_microdrive;
  549. }
  550. static const TypeInfo microdrive_type_info = {
  551. .name = TYPE_MICRODRIVE,
  552. .parent = TYPE_PCMCIA_CARD,
  553. .instance_size = sizeof(MicroDriveState),
  554. .instance_init = microdrive_init,
  555. .abstract = true,
  556. .class_init = microdrive_class_init,
  557. };
  558. static void microdrive_register_types(void)
  559. {
  560. type_register_static(&microdrive_type_info);
  561. type_register_static(&dscm1xxxx_type_info);
  562. }
  563. type_init(microdrive_register_types)