parallel.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. /*
  2. * QEMU Parallel PORT emulation
  3. *
  4. * Copyright (c) 2003-2005 Fabrice Bellard
  5. * Copyright (c) 2007 Marko Kohtala
  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 "hw.h"
  26. #include "qemu-char.h"
  27. #include "isa.h"
  28. #include "pc.h"
  29. #include "sysemu.h"
  30. //#define DEBUG_PARALLEL
  31. #ifdef DEBUG_PARALLEL
  32. #define pdebug(fmt, ...) printf("pp: " fmt, ## __VA_ARGS__)
  33. #else
  34. #define pdebug(fmt, ...) ((void)0)
  35. #endif
  36. #define PARA_REG_DATA 0
  37. #define PARA_REG_STS 1
  38. #define PARA_REG_CTR 2
  39. #define PARA_REG_EPP_ADDR 3
  40. #define PARA_REG_EPP_DATA 4
  41. /*
  42. * These are the definitions for the Printer Status Register
  43. */
  44. #define PARA_STS_BUSY 0x80 /* Busy complement */
  45. #define PARA_STS_ACK 0x40 /* Acknowledge */
  46. #define PARA_STS_PAPER 0x20 /* Out of paper */
  47. #define PARA_STS_ONLINE 0x10 /* Online */
  48. #define PARA_STS_ERROR 0x08 /* Error complement */
  49. #define PARA_STS_TMOUT 0x01 /* EPP timeout */
  50. /*
  51. * These are the definitions for the Printer Control Register
  52. */
  53. #define PARA_CTR_DIR 0x20 /* Direction (1=read, 0=write) */
  54. #define PARA_CTR_INTEN 0x10 /* IRQ Enable */
  55. #define PARA_CTR_SELECT 0x08 /* Select In complement */
  56. #define PARA_CTR_INIT 0x04 /* Initialize Printer complement */
  57. #define PARA_CTR_AUTOLF 0x02 /* Auto linefeed complement */
  58. #define PARA_CTR_STROBE 0x01 /* Strobe complement */
  59. #define PARA_CTR_SIGNAL (PARA_CTR_SELECT|PARA_CTR_INIT|PARA_CTR_AUTOLF|PARA_CTR_STROBE)
  60. typedef struct ParallelState {
  61. MemoryRegion iomem;
  62. uint8_t dataw;
  63. uint8_t datar;
  64. uint8_t status;
  65. uint8_t control;
  66. qemu_irq irq;
  67. int irq_pending;
  68. CharDriverState *chr;
  69. int hw_driver;
  70. int epp_timeout;
  71. uint32_t last_read_offset; /* For debugging */
  72. /* Memory-mapped interface */
  73. int it_shift;
  74. } ParallelState;
  75. typedef struct ISAParallelState {
  76. ISADevice dev;
  77. uint32_t index;
  78. uint32_t iobase;
  79. uint32_t isairq;
  80. ParallelState state;
  81. } ISAParallelState;
  82. static void parallel_update_irq(ParallelState *s)
  83. {
  84. if (s->irq_pending)
  85. qemu_irq_raise(s->irq);
  86. else
  87. qemu_irq_lower(s->irq);
  88. }
  89. static void
  90. parallel_ioport_write_sw(void *opaque, uint32_t addr, uint32_t val)
  91. {
  92. ParallelState *s = opaque;
  93. pdebug("write addr=0x%02x val=0x%02x\n", addr, val);
  94. addr &= 7;
  95. switch(addr) {
  96. case PARA_REG_DATA:
  97. s->dataw = val;
  98. parallel_update_irq(s);
  99. break;
  100. case PARA_REG_CTR:
  101. val |= 0xc0;
  102. if ((val & PARA_CTR_INIT) == 0 ) {
  103. s->status = PARA_STS_BUSY;
  104. s->status |= PARA_STS_ACK;
  105. s->status |= PARA_STS_ONLINE;
  106. s->status |= PARA_STS_ERROR;
  107. }
  108. else if (val & PARA_CTR_SELECT) {
  109. if (val & PARA_CTR_STROBE) {
  110. s->status &= ~PARA_STS_BUSY;
  111. if ((s->control & PARA_CTR_STROBE) == 0)
  112. qemu_chr_fe_write(s->chr, &s->dataw, 1);
  113. } else {
  114. if (s->control & PARA_CTR_INTEN) {
  115. s->irq_pending = 1;
  116. }
  117. }
  118. }
  119. parallel_update_irq(s);
  120. s->control = val;
  121. break;
  122. }
  123. }
  124. static void parallel_ioport_write_hw(void *opaque, uint32_t addr, uint32_t val)
  125. {
  126. ParallelState *s = opaque;
  127. uint8_t parm = val;
  128. int dir;
  129. /* Sometimes programs do several writes for timing purposes on old
  130. HW. Take care not to waste time on writes that do nothing. */
  131. s->last_read_offset = ~0U;
  132. addr &= 7;
  133. switch(addr) {
  134. case PARA_REG_DATA:
  135. if (s->dataw == val)
  136. return;
  137. pdebug("wd%02x\n", val);
  138. qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_WRITE_DATA, &parm);
  139. s->dataw = val;
  140. break;
  141. case PARA_REG_STS:
  142. pdebug("ws%02x\n", val);
  143. if (val & PARA_STS_TMOUT)
  144. s->epp_timeout = 0;
  145. break;
  146. case PARA_REG_CTR:
  147. val |= 0xc0;
  148. if (s->control == val)
  149. return;
  150. pdebug("wc%02x\n", val);
  151. if ((val & PARA_CTR_DIR) != (s->control & PARA_CTR_DIR)) {
  152. if (val & PARA_CTR_DIR) {
  153. dir = 1;
  154. } else {
  155. dir = 0;
  156. }
  157. qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_DATA_DIR, &dir);
  158. parm &= ~PARA_CTR_DIR;
  159. }
  160. qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_WRITE_CONTROL, &parm);
  161. s->control = val;
  162. break;
  163. case PARA_REG_EPP_ADDR:
  164. if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
  165. /* Controls not correct for EPP address cycle, so do nothing */
  166. pdebug("wa%02x s\n", val);
  167. else {
  168. struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
  169. if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE_ADDR, &ioarg)) {
  170. s->epp_timeout = 1;
  171. pdebug("wa%02x t\n", val);
  172. }
  173. else
  174. pdebug("wa%02x\n", val);
  175. }
  176. break;
  177. case PARA_REG_EPP_DATA:
  178. if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT)
  179. /* Controls not correct for EPP data cycle, so do nothing */
  180. pdebug("we%02x s\n", val);
  181. else {
  182. struct ParallelIOArg ioarg = { .buffer = &parm, .count = 1 };
  183. if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg)) {
  184. s->epp_timeout = 1;
  185. pdebug("we%02x t\n", val);
  186. }
  187. else
  188. pdebug("we%02x\n", val);
  189. }
  190. break;
  191. }
  192. }
  193. static void
  194. parallel_ioport_eppdata_write_hw2(void *opaque, uint32_t addr, uint32_t val)
  195. {
  196. ParallelState *s = opaque;
  197. uint16_t eppdata = cpu_to_le16(val);
  198. int err;
  199. struct ParallelIOArg ioarg = {
  200. .buffer = &eppdata, .count = sizeof(eppdata)
  201. };
  202. if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
  203. /* Controls not correct for EPP data cycle, so do nothing */
  204. pdebug("we%04x s\n", val);
  205. return;
  206. }
  207. err = qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
  208. if (err) {
  209. s->epp_timeout = 1;
  210. pdebug("we%04x t\n", val);
  211. }
  212. else
  213. pdebug("we%04x\n", val);
  214. }
  215. static void
  216. parallel_ioport_eppdata_write_hw4(void *opaque, uint32_t addr, uint32_t val)
  217. {
  218. ParallelState *s = opaque;
  219. uint32_t eppdata = cpu_to_le32(val);
  220. int err;
  221. struct ParallelIOArg ioarg = {
  222. .buffer = &eppdata, .count = sizeof(eppdata)
  223. };
  224. if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != PARA_CTR_INIT) {
  225. /* Controls not correct for EPP data cycle, so do nothing */
  226. pdebug("we%08x s\n", val);
  227. return;
  228. }
  229. err = qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_WRITE, &ioarg);
  230. if (err) {
  231. s->epp_timeout = 1;
  232. pdebug("we%08x t\n", val);
  233. }
  234. else
  235. pdebug("we%08x\n", val);
  236. }
  237. static uint32_t parallel_ioport_read_sw(void *opaque, uint32_t addr)
  238. {
  239. ParallelState *s = opaque;
  240. uint32_t ret = 0xff;
  241. addr &= 7;
  242. switch(addr) {
  243. case PARA_REG_DATA:
  244. if (s->control & PARA_CTR_DIR)
  245. ret = s->datar;
  246. else
  247. ret = s->dataw;
  248. break;
  249. case PARA_REG_STS:
  250. ret = s->status;
  251. s->irq_pending = 0;
  252. if ((s->status & PARA_STS_BUSY) == 0 && (s->control & PARA_CTR_STROBE) == 0) {
  253. /* XXX Fixme: wait 5 microseconds */
  254. if (s->status & PARA_STS_ACK)
  255. s->status &= ~PARA_STS_ACK;
  256. else {
  257. /* XXX Fixme: wait 5 microseconds */
  258. s->status |= PARA_STS_ACK;
  259. s->status |= PARA_STS_BUSY;
  260. }
  261. }
  262. parallel_update_irq(s);
  263. break;
  264. case PARA_REG_CTR:
  265. ret = s->control;
  266. break;
  267. }
  268. pdebug("read addr=0x%02x val=0x%02x\n", addr, ret);
  269. return ret;
  270. }
  271. static uint32_t parallel_ioport_read_hw(void *opaque, uint32_t addr)
  272. {
  273. ParallelState *s = opaque;
  274. uint8_t ret = 0xff;
  275. addr &= 7;
  276. switch(addr) {
  277. case PARA_REG_DATA:
  278. qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_DATA, &ret);
  279. if (s->last_read_offset != addr || s->datar != ret)
  280. pdebug("rd%02x\n", ret);
  281. s->datar = ret;
  282. break;
  283. case PARA_REG_STS:
  284. qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &ret);
  285. ret &= ~PARA_STS_TMOUT;
  286. if (s->epp_timeout)
  287. ret |= PARA_STS_TMOUT;
  288. if (s->last_read_offset != addr || s->status != ret)
  289. pdebug("rs%02x\n", ret);
  290. s->status = ret;
  291. break;
  292. case PARA_REG_CTR:
  293. /* s->control has some bits fixed to 1. It is zero only when
  294. it has not been yet written to. */
  295. if (s->control == 0) {
  296. qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_CONTROL, &ret);
  297. if (s->last_read_offset != addr)
  298. pdebug("rc%02x\n", ret);
  299. s->control = ret;
  300. }
  301. else {
  302. ret = s->control;
  303. if (s->last_read_offset != addr)
  304. pdebug("rc%02x\n", ret);
  305. }
  306. break;
  307. case PARA_REG_EPP_ADDR:
  308. if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
  309. /* Controls not correct for EPP addr cycle, so do nothing */
  310. pdebug("ra%02x s\n", ret);
  311. else {
  312. struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
  313. if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ_ADDR, &ioarg)) {
  314. s->epp_timeout = 1;
  315. pdebug("ra%02x t\n", ret);
  316. }
  317. else
  318. pdebug("ra%02x\n", ret);
  319. }
  320. break;
  321. case PARA_REG_EPP_DATA:
  322. if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT))
  323. /* Controls not correct for EPP data cycle, so do nothing */
  324. pdebug("re%02x s\n", ret);
  325. else {
  326. struct ParallelIOArg ioarg = { .buffer = &ret, .count = 1 };
  327. if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg)) {
  328. s->epp_timeout = 1;
  329. pdebug("re%02x t\n", ret);
  330. }
  331. else
  332. pdebug("re%02x\n", ret);
  333. }
  334. break;
  335. }
  336. s->last_read_offset = addr;
  337. return ret;
  338. }
  339. static uint32_t
  340. parallel_ioport_eppdata_read_hw2(void *opaque, uint32_t addr)
  341. {
  342. ParallelState *s = opaque;
  343. uint32_t ret;
  344. uint16_t eppdata = ~0;
  345. int err;
  346. struct ParallelIOArg ioarg = {
  347. .buffer = &eppdata, .count = sizeof(eppdata)
  348. };
  349. if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
  350. /* Controls not correct for EPP data cycle, so do nothing */
  351. pdebug("re%04x s\n", eppdata);
  352. return eppdata;
  353. }
  354. err = qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
  355. ret = le16_to_cpu(eppdata);
  356. if (err) {
  357. s->epp_timeout = 1;
  358. pdebug("re%04x t\n", ret);
  359. }
  360. else
  361. pdebug("re%04x\n", ret);
  362. return ret;
  363. }
  364. static uint32_t
  365. parallel_ioport_eppdata_read_hw4(void *opaque, uint32_t addr)
  366. {
  367. ParallelState *s = opaque;
  368. uint32_t ret;
  369. uint32_t eppdata = ~0U;
  370. int err;
  371. struct ParallelIOArg ioarg = {
  372. .buffer = &eppdata, .count = sizeof(eppdata)
  373. };
  374. if ((s->control & (PARA_CTR_DIR|PARA_CTR_SIGNAL)) != (PARA_CTR_DIR|PARA_CTR_INIT)) {
  375. /* Controls not correct for EPP data cycle, so do nothing */
  376. pdebug("re%08x s\n", eppdata);
  377. return eppdata;
  378. }
  379. err = qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_EPP_READ, &ioarg);
  380. ret = le32_to_cpu(eppdata);
  381. if (err) {
  382. s->epp_timeout = 1;
  383. pdebug("re%08x t\n", ret);
  384. }
  385. else
  386. pdebug("re%08x\n", ret);
  387. return ret;
  388. }
  389. static void parallel_ioport_ecp_write(void *opaque, uint32_t addr, uint32_t val)
  390. {
  391. pdebug("wecp%d=%02x\n", addr & 7, val);
  392. }
  393. static uint32_t parallel_ioport_ecp_read(void *opaque, uint32_t addr)
  394. {
  395. uint8_t ret = 0xff;
  396. pdebug("recp%d:%02x\n", addr & 7, ret);
  397. return ret;
  398. }
  399. static void parallel_reset(void *opaque)
  400. {
  401. ParallelState *s = opaque;
  402. s->datar = ~0;
  403. s->dataw = ~0;
  404. s->status = PARA_STS_BUSY;
  405. s->status |= PARA_STS_ACK;
  406. s->status |= PARA_STS_ONLINE;
  407. s->status |= PARA_STS_ERROR;
  408. s->status |= PARA_STS_TMOUT;
  409. s->control = PARA_CTR_SELECT;
  410. s->control |= PARA_CTR_INIT;
  411. s->control |= 0xc0;
  412. s->irq_pending = 0;
  413. s->hw_driver = 0;
  414. s->epp_timeout = 0;
  415. s->last_read_offset = ~0U;
  416. }
  417. static const int isa_parallel_io[MAX_PARALLEL_PORTS] = { 0x378, 0x278, 0x3bc };
  418. static const MemoryRegionPortio isa_parallel_portio_hw_list[] = {
  419. { 0, 8, 1,
  420. .read = parallel_ioport_read_hw,
  421. .write = parallel_ioport_write_hw },
  422. { 4, 1, 2,
  423. .read = parallel_ioport_eppdata_read_hw2,
  424. .write = parallel_ioport_eppdata_write_hw2 },
  425. { 4, 1, 4,
  426. .read = parallel_ioport_eppdata_read_hw4,
  427. .write = parallel_ioport_eppdata_write_hw4 },
  428. { 0x400, 8, 1,
  429. .read = parallel_ioport_ecp_read,
  430. .write = parallel_ioport_ecp_write },
  431. PORTIO_END_OF_LIST(),
  432. };
  433. static const MemoryRegionPortio isa_parallel_portio_sw_list[] = {
  434. { 0, 8, 1,
  435. .read = parallel_ioport_read_sw,
  436. .write = parallel_ioport_write_sw },
  437. PORTIO_END_OF_LIST(),
  438. };
  439. static int parallel_isa_initfn(ISADevice *dev)
  440. {
  441. static int index;
  442. ISAParallelState *isa = DO_UPCAST(ISAParallelState, dev, dev);
  443. ParallelState *s = &isa->state;
  444. int base;
  445. uint8_t dummy;
  446. if (!s->chr) {
  447. fprintf(stderr, "Can't create parallel device, empty char device\n");
  448. exit(1);
  449. }
  450. if (isa->index == -1)
  451. isa->index = index;
  452. if (isa->index >= MAX_PARALLEL_PORTS)
  453. return -1;
  454. if (isa->iobase == -1)
  455. isa->iobase = isa_parallel_io[isa->index];
  456. index++;
  457. base = isa->iobase;
  458. isa_init_irq(dev, &s->irq, isa->isairq);
  459. qemu_register_reset(parallel_reset, s);
  460. if (qemu_chr_fe_ioctl(s->chr, CHR_IOCTL_PP_READ_STATUS, &dummy) == 0) {
  461. s->hw_driver = 1;
  462. s->status = dummy;
  463. }
  464. isa_register_portio_list(dev, base,
  465. (s->hw_driver
  466. ? &isa_parallel_portio_hw_list[0]
  467. : &isa_parallel_portio_sw_list[0]),
  468. s, "parallel");
  469. return 0;
  470. }
  471. /* Memory mapped interface */
  472. static uint32_t parallel_mm_readb (void *opaque, target_phys_addr_t addr)
  473. {
  474. ParallelState *s = opaque;
  475. return parallel_ioport_read_sw(s, addr >> s->it_shift) & 0xFF;
  476. }
  477. static void parallel_mm_writeb (void *opaque,
  478. target_phys_addr_t addr, uint32_t value)
  479. {
  480. ParallelState *s = opaque;
  481. parallel_ioport_write_sw(s, addr >> s->it_shift, value & 0xFF);
  482. }
  483. static uint32_t parallel_mm_readw (void *opaque, target_phys_addr_t addr)
  484. {
  485. ParallelState *s = opaque;
  486. return parallel_ioport_read_sw(s, addr >> s->it_shift) & 0xFFFF;
  487. }
  488. static void parallel_mm_writew (void *opaque,
  489. target_phys_addr_t addr, uint32_t value)
  490. {
  491. ParallelState *s = opaque;
  492. parallel_ioport_write_sw(s, addr >> s->it_shift, value & 0xFFFF);
  493. }
  494. static uint32_t parallel_mm_readl (void *opaque, target_phys_addr_t addr)
  495. {
  496. ParallelState *s = opaque;
  497. return parallel_ioport_read_sw(s, addr >> s->it_shift);
  498. }
  499. static void parallel_mm_writel (void *opaque,
  500. target_phys_addr_t addr, uint32_t value)
  501. {
  502. ParallelState *s = opaque;
  503. parallel_ioport_write_sw(s, addr >> s->it_shift, value);
  504. }
  505. static const MemoryRegionOps parallel_mm_ops = {
  506. .old_mmio = {
  507. .read = { parallel_mm_readb, parallel_mm_readw, parallel_mm_readl },
  508. .write = { parallel_mm_writeb, parallel_mm_writew, parallel_mm_writel },
  509. },
  510. .endianness = DEVICE_NATIVE_ENDIAN,
  511. };
  512. /* If fd is zero, it means that the parallel device uses the console */
  513. bool parallel_mm_init(MemoryRegion *address_space,
  514. target_phys_addr_t base, int it_shift, qemu_irq irq,
  515. CharDriverState *chr)
  516. {
  517. ParallelState *s;
  518. s = g_malloc0(sizeof(ParallelState));
  519. s->irq = irq;
  520. s->chr = chr;
  521. s->it_shift = it_shift;
  522. qemu_register_reset(parallel_reset, s);
  523. memory_region_init_io(&s->iomem, &parallel_mm_ops, s,
  524. "parallel", 8 << it_shift);
  525. memory_region_add_subregion(address_space, base, &s->iomem);
  526. return true;
  527. }
  528. static Property parallel_isa_properties[] = {
  529. DEFINE_PROP_UINT32("index", ISAParallelState, index, -1),
  530. DEFINE_PROP_HEX32("iobase", ISAParallelState, iobase, -1),
  531. DEFINE_PROP_UINT32("irq", ISAParallelState, isairq, 7),
  532. DEFINE_PROP_CHR("chardev", ISAParallelState, state.chr),
  533. DEFINE_PROP_END_OF_LIST(),
  534. };
  535. static void parallel_isa_class_initfn(ObjectClass *klass, void *data)
  536. {
  537. DeviceClass *dc = DEVICE_CLASS(klass);
  538. ISADeviceClass *ic = ISA_DEVICE_CLASS(klass);
  539. ic->init = parallel_isa_initfn;
  540. dc->props = parallel_isa_properties;
  541. }
  542. static TypeInfo parallel_isa_info = {
  543. .name = "isa-parallel",
  544. .parent = TYPE_ISA_DEVICE,
  545. .instance_size = sizeof(ISAParallelState),
  546. .class_init = parallel_isa_class_initfn,
  547. };
  548. static void parallel_register_types(void)
  549. {
  550. type_register_static(&parallel_isa_info);
  551. }
  552. type_init(parallel_register_types)