2
0

microdrive.c 19 KB

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