xref: /openbmc/qemu/include/hw/char/pl011.h (revision 2038f8c8)
1 /*
2  * This program is free software; you can redistribute it and/or modify it
3  * under the terms and conditions of the GNU General Public License,
4  * version 2 or later, as published by the Free Software Foundation.
5  *
6  * This program is distributed in the hope it will be useful, but WITHOUT
7  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
9  * more details.
10  *
11  * You should have received a copy of the GNU General Public License along with
12  * this program.  If not, see <http://www.gnu.org/licenses/>.
13  */
14 
15 #ifndef HW_PL011_H
16 #define HW_PL011_H
17 
18 #include "hw/qdev-properties.h"
19 #include "hw/sysbus.h"
20 #include "chardev/char-fe.h"
21 
22 #define TYPE_PL011 "pl011"
23 #define PL011(obj) OBJECT_CHECK(PL011State, (obj), TYPE_PL011)
24 
25 /* This shares the same struct (and cast macro) as the base pl011 device */
26 #define TYPE_PL011_LUMINARY "pl011_luminary"
27 
28 typedef struct PL011State {
29     SysBusDevice parent_obj;
30 
31     MemoryRegion iomem;
32     uint32_t readbuff;
33     uint32_t flags;
34     uint32_t lcr;
35     uint32_t rsr;
36     uint32_t cr;
37     uint32_t dmacr;
38     uint32_t int_enabled;
39     uint32_t int_level;
40     uint32_t read_fifo[16];
41     uint32_t ilpr;
42     uint32_t ibrd;
43     uint32_t fbrd;
44     uint32_t ifl;
45     int read_pos;
46     int read_count;
47     int read_trigger;
48     CharBackend chr;
49     qemu_irq irq[6];
50     const unsigned char *id;
51 } PL011State;
52 
53 static inline DeviceState *pl011_create(hwaddr addr,
54                                         qemu_irq irq,
55                                         Chardev *chr)
56 {
57     DeviceState *dev;
58     SysBusDevice *s;
59 
60     dev = qdev_create(NULL, "pl011");
61     s = SYS_BUS_DEVICE(dev);
62     qdev_prop_set_chr(dev, "chardev", chr);
63     qdev_init_nofail(dev);
64     sysbus_mmio_map(s, 0, addr);
65     sysbus_connect_irq(s, 0, irq);
66 
67     return dev;
68 }
69 
70 static inline DeviceState *pl011_luminary_create(hwaddr addr,
71                                                  qemu_irq irq,
72                                                  Chardev *chr)
73 {
74     DeviceState *dev;
75     SysBusDevice *s;
76 
77     dev = qdev_create(NULL, "pl011_luminary");
78     s = SYS_BUS_DEVICE(dev);
79     qdev_prop_set_chr(dev, "chardev", chr);
80     qdev_init_nofail(dev);
81     sysbus_mmio_map(s, 0, addr);
82     sysbus_connect_irq(s, 0, irq);
83 
84     return dev;
85 }
86 
87 #endif
88