xref: /openbmc/qemu/include/system/ioport.h (revision fc524567087c2537b5103cdfc1d41e4f442892b6)
1*91a85383SRichard Henderson /*
2*91a85383SRichard Henderson  * defines ioport related functions
3*91a85383SRichard Henderson  *
4*91a85383SRichard Henderson  *  Copyright (c) 2003 Fabrice Bellard
5*91a85383SRichard Henderson  *
6*91a85383SRichard Henderson  * This library is free software; you can redistribute it and/or
7*91a85383SRichard Henderson  * modify it under the terms of the GNU Lesser General Public
8*91a85383SRichard Henderson  * License as published by the Free Software Foundation; either
9*91a85383SRichard Henderson  * version 2.1 of the License, or (at your option) any later version.
10*91a85383SRichard Henderson  *
11*91a85383SRichard Henderson  * This library is distributed in the hope that it will be useful,
12*91a85383SRichard Henderson  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*91a85383SRichard Henderson  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*91a85383SRichard Henderson  * Lesser General Public License for more details.
15*91a85383SRichard Henderson  *
16*91a85383SRichard Henderson  * You should have received a copy of the GNU Lesser General Public
17*91a85383SRichard Henderson  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18*91a85383SRichard Henderson  */
19*91a85383SRichard Henderson 
20*91a85383SRichard Henderson /**************************************************************************
21*91a85383SRichard Henderson  * IO ports API
22*91a85383SRichard Henderson  */
23*91a85383SRichard Henderson 
24*91a85383SRichard Henderson #ifndef SYSTEM_IOPORT_H
25*91a85383SRichard Henderson #define SYSTEM_IOPORT_H
26*91a85383SRichard Henderson 
27*91a85383SRichard Henderson #include "system/memory.h"
28*91a85383SRichard Henderson 
29*91a85383SRichard Henderson #define MAX_IOPORTS     (64 * 1024)
30*91a85383SRichard Henderson #define IOPORTS_MASK    (MAX_IOPORTS - 1)
31*91a85383SRichard Henderson 
32*91a85383SRichard Henderson typedef struct MemoryRegionPortio {
33*91a85383SRichard Henderson     uint32_t offset;
34*91a85383SRichard Henderson     uint32_t len;
35*91a85383SRichard Henderson     unsigned size;
36*91a85383SRichard Henderson     uint32_t (*read)(void *opaque, uint32_t address);
37*91a85383SRichard Henderson     void (*write)(void *opaque, uint32_t address, uint32_t data);
38*91a85383SRichard Henderson } MemoryRegionPortio;
39*91a85383SRichard Henderson 
40*91a85383SRichard Henderson #define PORTIO_END_OF_LIST() { }
41*91a85383SRichard Henderson 
42*91a85383SRichard Henderson extern const MemoryRegionOps unassigned_io_ops;
43*91a85383SRichard Henderson 
44*91a85383SRichard Henderson void cpu_outb(uint32_t addr, uint8_t val);
45*91a85383SRichard Henderson void cpu_outw(uint32_t addr, uint16_t val);
46*91a85383SRichard Henderson void cpu_outl(uint32_t addr, uint32_t val);
47*91a85383SRichard Henderson uint8_t cpu_inb(uint32_t addr);
48*91a85383SRichard Henderson uint16_t cpu_inw(uint32_t addr);
49*91a85383SRichard Henderson uint32_t cpu_inl(uint32_t addr);
50*91a85383SRichard Henderson 
51*91a85383SRichard Henderson typedef struct PortioList {
52*91a85383SRichard Henderson     const struct MemoryRegionPortio *ports;
53*91a85383SRichard Henderson     Object *owner;
54*91a85383SRichard Henderson     struct MemoryRegion *address_space;
55*91a85383SRichard Henderson     uint32_t addr;
56*91a85383SRichard Henderson     unsigned nr;
57*91a85383SRichard Henderson     struct MemoryRegion **regions;
58*91a85383SRichard Henderson     void *opaque;
59*91a85383SRichard Henderson     const char *name;
60*91a85383SRichard Henderson     bool flush_coalesced_mmio;
61*91a85383SRichard Henderson } PortioList;
62*91a85383SRichard Henderson 
63*91a85383SRichard Henderson void portio_list_init(PortioList *piolist, Object *owner,
64*91a85383SRichard Henderson                       const struct MemoryRegionPortio *callbacks,
65*91a85383SRichard Henderson                       void *opaque, const char *name);
66*91a85383SRichard Henderson void portio_list_set_flush_coalesced(PortioList *piolist);
67*91a85383SRichard Henderson void portio_list_destroy(PortioList *piolist);
68*91a85383SRichard Henderson void portio_list_add(PortioList *piolist,
69*91a85383SRichard Henderson                      struct MemoryRegion *address_space,
70*91a85383SRichard Henderson                      uint32_t addr);
71*91a85383SRichard Henderson void portio_list_del(PortioList *piolist);
72*91a85383SRichard Henderson void portio_list_set_enabled(PortioList *piolist, bool enabled);
73*91a85383SRichard Henderson void portio_list_set_address(PortioList *piolist, uint32_t addr);
74*91a85383SRichard Henderson 
75*91a85383SRichard Henderson #endif /* IOPORT_H */
76