2
0

microdrive.c 19 KB

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