microdrive.c 19 KB

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