cadence_uart.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Device model for Cadence UART
  3. *
  4. * Copyright (c) 2010 Xilinx Inc.
  5. * Copyright (c) 2012 Peter A.G. Crosthwaite (peter.crosthwaite@petalogix.com)
  6. * Copyright (c) 2012 PetaLogix Pty Ltd.
  7. * Written by Haibing Ma
  8. * M.Habib
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef CADENCE_UART_H
  19. #include "hw/sysbus.h"
  20. #include "chardev/char-fe.h"
  21. #include "qemu/timer.h"
  22. #define CADENCE_UART_RX_FIFO_SIZE 16
  23. #define CADENCE_UART_TX_FIFO_SIZE 16
  24. #define CADENCE_UART_R_MAX (0x48/4)
  25. #define TYPE_CADENCE_UART "cadence_uart"
  26. #define CADENCE_UART(obj) OBJECT_CHECK(CadenceUARTState, (obj), \
  27. TYPE_CADENCE_UART)
  28. typedef struct {
  29. /*< private >*/
  30. SysBusDevice parent_obj;
  31. /*< public >*/
  32. MemoryRegion iomem;
  33. uint32_t r[CADENCE_UART_R_MAX];
  34. uint8_t rx_fifo[CADENCE_UART_RX_FIFO_SIZE];
  35. uint8_t tx_fifo[CADENCE_UART_TX_FIFO_SIZE];
  36. uint32_t rx_wpos;
  37. uint32_t rx_count;
  38. uint32_t tx_count;
  39. uint64_t char_tx_time;
  40. CharBackend chr;
  41. qemu_irq irq;
  42. QEMUTimer *fifo_trigger_handle;
  43. } CadenceUARTState;
  44. static inline DeviceState *cadence_uart_create(hwaddr addr,
  45. qemu_irq irq,
  46. Chardev *chr)
  47. {
  48. DeviceState *dev;
  49. SysBusDevice *s;
  50. dev = qdev_create(NULL, TYPE_CADENCE_UART);
  51. s = SYS_BUS_DEVICE(dev);
  52. qdev_prop_set_chr(dev, "chardev", chr);
  53. qdev_init_nofail(dev);
  54. sysbus_mmio_map(s, 0, addr);
  55. sysbus_connect_irq(s, 0, irq);
  56. return dev;
  57. }
  58. #define CADENCE_UART_H
  59. #endif