1 /*
2  * xen/include/asm-arm/mmio.h
3  *
4  * ARM I/O handlers
5  *
6  * Copyright (c) 2011 Citrix Systems.
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  */
18 
19 #ifndef __ASM_ARM_MMIO_H__
20 #define __ASM_ARM_MMIO_H__
21 
22 #include <xen/lib.h>
23 #include <xen/rwlock.h>
24 
25 #include <asm/hsr.h>
26 
27 #define MAX_IO_HANDLER  16
28 
29 enum instr_decode_state
30 {
31     INSTR_ERROR,                    /* Error encountered while decoding instr */
32     INSTR_VALID,                    /* ISS is valid, so no need to decode */
33     /*
34      * Instruction is decoded successfully. It is a ldr/str post indexing
35      * instruction.
36      */
37     INSTR_LDR_STR_POSTINDEXING,
38     INSTR_CACHE,                    /* Cache Maintenance instr */
39 };
40 
41 typedef struct
42 {
43     struct hsr_dabt dabt;
44     struct instr_details {
45         unsigned long rn:5;
46         signed int imm9:9;
47         enum instr_decode_state state;
48     } dabt_instr;
49     paddr_t gpa;
50 } mmio_info_t;
51 
52 enum io_state
53 {
54     IO_ABORT,       /* The IO was handled by the helper and led to an abort. */
55     IO_HANDLED,     /* The IO was successfully handled by the helper. */
56     IO_UNHANDLED,   /* The IO was not handled by the helper. */
57     IO_RETRY,       /* Retry the emulation for some reason */
58 };
59 
60 typedef int (*mmio_read_t)(struct vcpu *v, mmio_info_t *info,
61                            register_t *r, void *priv);
62 typedef int (*mmio_write_t)(struct vcpu *v, mmio_info_t *info,
63                             register_t r, void *priv);
64 
65 struct mmio_handler_ops {
66     mmio_read_t read;
67     mmio_write_t write;
68 };
69 
70 struct mmio_handler {
71     paddr_t addr;
72     paddr_t size;
73     const struct mmio_handler_ops *ops;
74     void *priv;
75 };
76 
77 struct vmmio {
78     unsigned int num_entries;
79     unsigned int max_num_entries;
80     rwlock_t lock;
81     struct mmio_handler *handlers;
82 };
83 
84 enum io_state try_handle_mmio(struct cpu_user_regs *regs,
85                               mmio_info_t *info);
86 void register_mmio_handler(struct domain *d,
87                            const struct mmio_handler_ops *ops,
88                            paddr_t addr, paddr_t size, void *priv);
89 int domain_io_init(struct domain *d, unsigned int max_count);
90 void domain_io_free(struct domain *d);
91 
92 void try_decode_instruction(const struct cpu_user_regs *regs,
93                             mmio_info_t *info);
94 
95 #endif  /* __ASM_ARM_MMIO_H__ */
96 
97 /*
98  * Local variables:
99  * mode: C
100  * c-file-style: "BSD"
101  * c-basic-offset: 4
102  * indent-tabs-mode: nil
103  * End:
104  */
105