1 | /*
|
---|
2 | * Copyright (c) 2006 Jakub Jermar
|
---|
3 | * All rights reserved.
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * - Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * - Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * - The name of the author may not be used to endorse or promote products
|
---|
15 | * derived from this software without specific prior written permission.
|
---|
16 | *
|
---|
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
27 | */
|
---|
28 |
|
---|
29 | /** @addtogroup libc
|
---|
30 | * @{
|
---|
31 | */
|
---|
32 | /** @file
|
---|
33 | */
|
---|
34 |
|
---|
35 | #ifndef LIBC_DDI_H_
|
---|
36 | #define LIBC_DDI_H_
|
---|
37 |
|
---|
38 | #include <stdbool.h>
|
---|
39 | #include <stddef.h>
|
---|
40 | #include <stdint.h>
|
---|
41 | #include <sys/time.h>
|
---|
42 | #include <byteorder.h>
|
---|
43 | #include <abi/ddi/irq.h>
|
---|
44 | #include <device/hw_res.h>
|
---|
45 | #include <device/hw_res_parsed.h>
|
---|
46 | #include <device/pio_window.h>
|
---|
47 | #include <task.h>
|
---|
48 |
|
---|
49 | #define DMAMEM_16MiB ((uintptr_t) UINT64_C(0xffffffffff000000))
|
---|
50 | #define DMAMEM_4GiB ((uintptr_t) UINT64_C(0xffffffff00000000))
|
---|
51 |
|
---|
52 | typedef volatile uint8_t ioport8_t;
|
---|
53 | typedef volatile uint16_t ioport16_t;
|
---|
54 | typedef volatile uint32_t ioport32_t;
|
---|
55 | typedef volatile uint64_t ioport64_t;
|
---|
56 |
|
---|
57 | extern errno_t physmem_map(uintptr_t, size_t, unsigned int, void **);
|
---|
58 | extern errno_t physmem_unmap(void *);
|
---|
59 |
|
---|
60 | extern errno_t dmamem_map(void *, size_t, unsigned int, unsigned int, uintptr_t *);
|
---|
61 | extern errno_t dmamem_map_anonymous(size_t, uintptr_t, unsigned int, unsigned int,
|
---|
62 | uintptr_t *, void **);
|
---|
63 | extern errno_t dmamem_unmap(void *, size_t);
|
---|
64 | extern errno_t dmamem_unmap_anonymous(void *);
|
---|
65 |
|
---|
66 | extern errno_t pio_enable_range(addr_range_t *, void **);
|
---|
67 | extern errno_t pio_enable_resource(pio_window_t *, hw_resource_t *, void **,
|
---|
68 | uintptr_t *, size_t *);
|
---|
69 | extern errno_t pio_enable(void *, size_t, void **);
|
---|
70 | extern errno_t pio_disable(void *, size_t);
|
---|
71 |
|
---|
72 | typedef void (*trace_fnc)(const volatile void *place, uint64_t val,
|
---|
73 | volatile void *base, size_t size, void *data, bool write);
|
---|
74 |
|
---|
75 | extern errno_t pio_trace_enable(void *, size_t, trace_fnc, void *);
|
---|
76 | extern void pio_trace_log(const volatile void *, uint64_t val, bool write);
|
---|
77 | extern void pio_trace_disable(void *);
|
---|
78 |
|
---|
79 | extern void pio_write_8(ioport8_t *, uint8_t);
|
---|
80 | extern void pio_write_16(ioport16_t *, uint16_t);
|
---|
81 | extern void pio_write_32(ioport32_t *, uint32_t);
|
---|
82 | extern void pio_write_64(ioport64_t *, uint64_t);
|
---|
83 |
|
---|
84 | extern uint8_t pio_read_8(const ioport8_t *);
|
---|
85 | extern uint16_t pio_read_16(const ioport16_t *);
|
---|
86 | extern uint32_t pio_read_32(const ioport32_t *);
|
---|
87 | extern uint64_t pio_read_64(const ioport64_t *);
|
---|
88 |
|
---|
89 | static inline void pio_write_le16(ioport16_t *reg, uint16_t val)
|
---|
90 | {
|
---|
91 | pio_write_16(reg, host2uint16_t_le(val));
|
---|
92 | }
|
---|
93 | static inline void pio_write_be16(ioport16_t *reg, uint16_t val)
|
---|
94 | {
|
---|
95 | pio_write_16(reg, host2uint16_t_be(val));
|
---|
96 | }
|
---|
97 | static inline void pio_write_le32(ioport32_t *reg, uint32_t val)
|
---|
98 | {
|
---|
99 | pio_write_32(reg, host2uint32_t_le(val));
|
---|
100 | }
|
---|
101 | static inline void pio_write_be32(ioport32_t *reg, uint32_t val)
|
---|
102 | {
|
---|
103 | pio_write_32(reg, host2uint32_t_be(val));
|
---|
104 | }
|
---|
105 | static inline void pio_write_le64(ioport64_t *reg, uint64_t val)
|
---|
106 | {
|
---|
107 | pio_write_64(reg, host2uint64_t_le(val));
|
---|
108 | }
|
---|
109 | static inline void pio_write_be64(ioport64_t *reg, uint64_t val)
|
---|
110 | {
|
---|
111 | pio_write_64(reg, host2uint64_t_be(val));
|
---|
112 | }
|
---|
113 |
|
---|
114 | static inline uint16_t pio_read_le16(const ioport16_t *reg)
|
---|
115 | {
|
---|
116 | return uint16_t_le2host(pio_read_16(reg));
|
---|
117 | }
|
---|
118 | static inline uint16_t pio_read_be16(const ioport16_t *reg)
|
---|
119 | {
|
---|
120 | return uint16_t_be2host(pio_read_16(reg));
|
---|
121 | }
|
---|
122 | static inline uint32_t pio_read_le32(const ioport32_t *reg)
|
---|
123 | {
|
---|
124 | return uint32_t_le2host(pio_read_32(reg));
|
---|
125 | }
|
---|
126 | static inline uint32_t pio_read_be32(const ioport32_t *reg)
|
---|
127 | {
|
---|
128 | return uint32_t_be2host(pio_read_32(reg));
|
---|
129 | }
|
---|
130 | static inline uint64_t pio_read_le64(const ioport64_t *reg)
|
---|
131 | {
|
---|
132 | return uint64_t_le2host(pio_read_64(reg));
|
---|
133 | }
|
---|
134 | static inline uint64_t pio_read_be64(const ioport64_t *reg)
|
---|
135 | {
|
---|
136 | return uint64_t_be2host(pio_read_64(reg));
|
---|
137 | }
|
---|
138 |
|
---|
139 | static inline uint8_t pio_change_8(ioport8_t *reg, uint8_t val, uint8_t mask,
|
---|
140 | useconds_t delay)
|
---|
141 | {
|
---|
142 | uint8_t v = pio_read_8(reg);
|
---|
143 | udelay(delay);
|
---|
144 | pio_write_8(reg, (v & ~mask) | val);
|
---|
145 | return v;
|
---|
146 | }
|
---|
147 |
|
---|
148 | static inline uint16_t pio_change_16(ioport16_t *reg, uint16_t val,
|
---|
149 | uint16_t mask, useconds_t delay)
|
---|
150 | {
|
---|
151 | uint16_t v = pio_read_16(reg);
|
---|
152 | udelay(delay);
|
---|
153 | pio_write_16(reg, (v & ~mask) | val);
|
---|
154 | return v;
|
---|
155 | }
|
---|
156 |
|
---|
157 | static inline uint32_t pio_change_32(ioport32_t *reg, uint32_t val,
|
---|
158 | uint32_t mask, useconds_t delay)
|
---|
159 | {
|
---|
160 | uint32_t v = pio_read_32(reg);
|
---|
161 | udelay(delay);
|
---|
162 | pio_write_32(reg, (v & ~mask) | val);
|
---|
163 | return v;
|
---|
164 | }
|
---|
165 |
|
---|
166 | static inline uint64_t pio_change_64(ioport64_t *reg, uint64_t val,
|
---|
167 | uint64_t mask, useconds_t delay)
|
---|
168 | {
|
---|
169 | uint64_t v = pio_read_64(reg);
|
---|
170 | udelay(delay);
|
---|
171 | pio_write_64(reg, (v & ~mask) | val);
|
---|
172 | return v;
|
---|
173 | }
|
---|
174 |
|
---|
175 | static inline uint8_t pio_set_8(ioport8_t *r, uint8_t v, useconds_t d)
|
---|
176 | {
|
---|
177 | return pio_change_8(r, v, 0, d);
|
---|
178 | }
|
---|
179 | static inline uint16_t pio_set_16(ioport16_t *r, uint16_t v, useconds_t d)
|
---|
180 | {
|
---|
181 | return pio_change_16(r, v, 0, d);
|
---|
182 | }
|
---|
183 | static inline uint32_t pio_set_32(ioport32_t *r, uint32_t v, useconds_t d)
|
---|
184 | {
|
---|
185 | return pio_change_32(r, v, 0, d);
|
---|
186 | }
|
---|
187 | static inline uint64_t pio_set_64(ioport64_t *r, uint64_t v, useconds_t d)
|
---|
188 | {
|
---|
189 | return pio_change_64(r, v, 0, d);
|
---|
190 | }
|
---|
191 |
|
---|
192 | static inline uint8_t pio_clear_8(ioport8_t *r, uint8_t v, useconds_t d)
|
---|
193 | {
|
---|
194 | return pio_change_8(r, 0, v, d);
|
---|
195 | }
|
---|
196 | static inline uint16_t pio_clear_16(ioport16_t *r, uint16_t v, useconds_t d)
|
---|
197 | {
|
---|
198 | return pio_change_16(r, 0, v, d);
|
---|
199 | }
|
---|
200 | static inline uint32_t pio_clear_32(ioport32_t *r, uint32_t v, useconds_t d)
|
---|
201 | {
|
---|
202 | return pio_change_32(r, 0, v, d);
|
---|
203 | }
|
---|
204 | static inline uint64_t pio_clear_64(ioport64_t *r, uint64_t v, useconds_t d)
|
---|
205 | {
|
---|
206 | return pio_change_64(r, 0, v, d);
|
---|
207 | }
|
---|
208 |
|
---|
209 | #endif
|
---|
210 |
|
---|
211 | /** @}
|
---|
212 | */
|
---|