source: libbsdport/bsd_eth_drivers/libbsdport/bus.h @ a8bf95d

B_20100615baselibbsdport-4-10-branch
Last change on this file since a8bf95d was a8bf95d, checked in by Till Straumann <strauman@…>, on Apr 22, 2009 at 10:06:58 PM
  • importing updated version from SLAC as of 20090422
  • Property mode set to 100644
File size: 6.6 KB
Line 
1#ifndef LIBBSDPORT_SYS_BUS_H
2#define LIBBSDPORT_SYS_BUS_H
3
4#include <rtems.h>
5#include <sys/errno.h>
6#include <bsp.h>
7#include <devicet.h>
8#include <sys/mbuf.h>
9
10typedef uint32_t bus_addr_t;
11typedef size_t   bus_size_t;
12
13typedef enum {
14        bus_space_mem = 0,
15        bus_space_io  = 1
16} bus_space_tag_t;
17
18struct resource;
19
20typedef bus_addr_t bus_space_handle_t;
21
22/* The 'bus_space_xxx()' inlines can be helped if the
23 * tag is hardcoded in the driver so that the compiler
24 * can optimize part of the implementation away.
25 */
26
27#define BUS_SPACE_BARRIER_WRITE 1
28#define BUS_SPACE_BARRIER_READ  2
29
30#if defined(__i386__)
31
32#include <rtems/score/cpu.h>
33
34static inline void
35bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, int width, int type)
36{
37}
38
39#define BUS_SPACE_DECL(type, width, nwidth) \
40static inline type \
41bus_space_read_##nwidth(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) \
42{ \
43type v; \
44        if ( bus_space_io == t ) { \
45                /* this is a macro setting the second argument */ \
46                inport_##width( h+o, v ); \
47        } else { \
48                v = *(volatile type __attribute__((may_alias)) *)(h+o); \
49        } \
50        return v; \
51} \
52  \
53static inline void \
54bus_space_write_##nwidth(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, type v) \
55{ \
56        if ( bus_space_io == t ) { \
57                outport_##width( h+o, v ); \
58        } else { \
59                *(volatile type __attribute__((may_alias)) *)(h+o) = v; \
60        }\
61}
62
63BUS_SPACE_DECL(u_int32_t, long, 4)
64BUS_SPACE_DECL(u_int16_t, word, 2)
65BUS_SPACE_DECL(u_int8_t,  byte, 1)
66
67#elif defined(__PPC__)
68
69#include <libcpu/io.h>
70
71#if defined(_IO_BASE) && _IO_BASE == 0
72#define BUS_SPACE_ALWAYS_MEM 1
73#else
74#define BUS_SPACE_ALWAYS_MEM 0
75#endif
76
77static inline void
78bus_space_barrier(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, int width, int type)
79{
80        asm volatile("eieio");
81}
82
83
84#define BUS_SPACE_DECL(type, width, nwidth, op) \
85static inline type \
86bus_space_read_##nwidth(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o) \
87{ \
88type v; \
89        if ( !BUS_SPACE_ALWAYS_MEM && bus_space_io == t ) { \
90                /* this is a macro setting the second argument */ \
91                v = in_##op((volatile type *)(_IO_BASE+h+o)); \
92        } else { \
93                v = in_##op((volatile type *)(h+o)); \
94        } \
95        return v; \
96} \
97  \
98static inline void \
99bus_space_write_##nwidth(bus_space_tag_t t, bus_space_handle_t h, bus_size_t o, type v) \
100{ \
101        if ( !BUS_SPACE_ALWAYS_MEM && bus_space_io == t ) { \
102                out_##op((volatile type *)(_IO_BASE+h+o), v); \
103        } else { \
104                out_##op((volatile type *)(h+o), v); \
105        }\
106}
107
108BUS_SPACE_DECL(u_int32_t, long, 4, le32)
109BUS_SPACE_DECL(u_int16_t, word, 2, le16)
110BUS_SPACE_DECL(u_int8_t,  byte, 1, 8)
111
112#undef BUS_SPACE_ALWAYS_MEM
113
114#else
115#error "Missing definitions of bus_space_XXX() for this CPU architecture"
116#endif
117
118
119#undef BUS_SPACE_DECL
120
121#ifndef BUS_PROBE_DEFAULT
122#define BUS_PROBE_DEFAULT 0
123#endif
124
125/* error codes are > 0 ; low priority says that probe
126 * was successful but another driver returning BUS_PROBE_DEFAULT
127 * is to be preferred...
128 */
129#ifndef BUS_PROBE_LOW_PRIORITY
130#define BUS_PROBE_LOW_PRIORITY (-1)
131#endif
132
133
134
135/* types -> -1 means unsupported */
136#define SYS_RES_IOPORT  1
137#define SYS_RES_MEMORY  2
138#define SYS_RES_IRQ     3
139
140/* flags (1<<31) means unsupported */
141#define RF_ACTIVE       (1<<1)
142#define RF_SHAREABLE    (1<<2)
143
144struct resource *
145bus_alloc_resource_any(device_t dev, int type, int *prid, unsigned flags);
146
147#define FILTER_STRAY 1
148#define FILTER_HANDLED 0
149
150typedef void (*driver_intr_t)(void *);
151typedef int  (*driver_filter_t)(void *);
152
153int
154bus_setup_intr(device_t dev, struct resource *r, int flags, driver_filter_t filter, driver_intr_t handler, void *arg, void **cookiep);
155
156/* Flags currently ignored... */
157#define INTR_MPSAFE         0
158#define INTR_TYPE_NET   0
159
160int
161bus_teardown_intr(device_t dev, struct resource *r, void *cookiep);
162
163static inline int
164bus_release_resource(device_t dev, int type, int rid, struct resource *r)
165{
166        return 0;
167}
168
169#define bus_generic_detach(dev) do {} while (0)
170
171#define bus_generic_suspend(dev) (0)
172#define bus_generic_resume(dev)  (0)
173
174bus_space_handle_t
175rman_get_bushandle(struct resource *r);
176
177bus_space_tag_t
178rman_get_bustag(struct resource *r);
179
180#ifndef BUS_DMA_NOWAIT 
181/* ignored anyways */
182#define BUS_DMA_NOWAIT 0
183#endif
184
185#ifndef BUS_DMA_WAITOK 
186/* ignored anyways */
187#define BUS_DMA_WAITOK 0
188#endif
189
190#ifndef BUS_DMA_COHERENT       
191/* ignored anyways */
192#define BUS_DMA_COHERENT 0
193#endif
194
195/* unused */
196#ifndef BUS_SPACE_MAXADDR
197#define BUS_SPACE_MAXADDR 0xdeadbeef
198#endif
199
200/* unused */
201#ifndef BUS_SPACE_MAXADDR_32BIT
202#define BUS_SPACE_MAXADDR_32BIT 0xdeadbeef
203#endif
204
205/* unused */
206#ifndef BUS_SPACE_MAXSIZE_32BIT
207#define BUS_SPACE_MAXSIZE_32BIT 0x10000000
208#endif
209
210typedef struct _bus_dma_tag_t {
211        unsigned alignment;
212        unsigned maxsize;
213        unsigned maxsegs;
214} * bus_dma_tag_t;
215
216typedef struct _bus_dma_segment_t {
217        bus_addr_t      ds_addr;
218        bus_size_t  ds_len;
219} bus_dma_segment_t;
220
221typedef void *bus_dmamap_t;
222
223int
224bus_dma_tag_create(void *parent, unsigned alignment, unsigned bounds, uint32_t lowadd, uint32_t hiaddr, void (*filter)(void*), void *filterarg, unsigned maxsize, int nsegs, unsigned maxsegsize, unsigned flags, void (*lockfunc)(void*), void *lockarg, bus_dma_tag_t *ptag);
225
226void
227bus_dma_tag_destroy(bus_dma_tag_t tag);
228
229int
230bus_dmamem_alloc(bus_dma_tag_t tag, void **p_vaddr, unsigned flags, bus_dmamap_t *p_map);
231
232void
233bus_dmamem_free(bus_dma_tag_t tag, void *vaddr, bus_dmamap_t map);
234       
235#ifndef CPU2BUSADDR
236#ifndef PCI_DRAM_OFFSET
237#define PCI_DRAM_OFFSET 0
238#endif
239#define CPU2BUSADDR(x) ((uint32_t)(x) + (PCI_DRAM_OFFSET))
240#endif
241
242#define kvtop(a)                        CPU2BUSADDR((bus_addr_t)(a))
243#define vtophys(a)                      CPU2BUSADDR((bus_addr_t)(a))
244
245
246static inline int
247bus_dmamap_load_mbuf_sg(bus_dma_tag_t tag, bus_dmamap_t map, struct mbuf *m_head, bus_dma_segment_t *segs, int *pnsegs, unsigned flags)
248{
249struct mbuf *m;
250int          n;
251        for ( m=m_head, n=0; m; m=m->m_next, n++ ) {
252                if ( n >= tag->maxsegs ) {
253                        return EFBIG;
254                }
255                segs[n].ds_addr = CPU2BUSADDR(mtod(m, unsigned));
256                segs[n].ds_len  = m->m_len;
257        }
258        *pnsegs = n;
259        return 0;
260}
261
262static inline bus_dma_tag_t
263bus_get_dma_tag(device_t dev)
264{
265        return 0;
266}
267
268typedef void bus_dmamap_callback_t (void *, bus_dma_segment_t *, int, int);
269
270static inline int
271bus_dmamap_load(bus_dma_tag_t tag, bus_dmamap_t map, caddr_t vaddr, bus_size_t size, void (*cb)(void *arg, bus_dma_segment_t *segs, int nseg, int error), void *arg, unsigned flags)
272{
273bus_dma_segment_t segs[1];
274        segs[0].ds_addr = CPU2BUSADDR(vaddr);
275        segs[0].ds_len  = size;
276        cb(arg, segs, 1, 0);
277        return 0;
278}
279
280#define bus_dmamap_unload(tag, map) do {} while (0)
281
282/* should we do something if we have no HW snooping ? */
283#define bus_dmamap_sync(tag, map, flags) do { membarrier_rw(); } while (0)
284
285#define bus_dmamap_create(tag, flags, pmap) ( *(pmap) = 0, 0 )
286#define bus_dmamap_destroy(tag, map) do {} while (0)
287
288#endif
Note: See TracBrowser for help on using the repository browser.