2 * CFE boot loader OS Abstraction Layer.
4 * Copyright 2004, Broadcom Corporation
7 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Broadcom Corporation;
8 * the contents of this file may not be disclosed to third parties, copied
9 * or duplicated in any form, in whole or in part, without the prior
10 * written permission of Broadcom Corporation.
18 #include <lib_types.h>
19 #include <lib_string.h>
20 #include <lib_printf.h>
21 #include <lib_malloc.h>
22 #include <cpu_config.h>
23 #include <cfe_timer.h>
25 #include <cfe_devfuncs.h>
26 #include <addrspace.h>
30 /* pick up osl required snprintf/vsnprintf */
31 #include <bcmstdlib.h>
34 extern int (*xprinthook
)(const char *str
);
35 #define puts(str) do { if (xprinthook) xprinthook(str); } while (0)
37 /* assert and panic */
40 do { if (!(exp)) osl_assert(#exp, __FILE__, __LINE__); } while (0)
41 extern void osl_assert(char *exp
, char *file
, int line
);
42 #else /* BCMDBG_ASSERT */
43 #define ASSERT(exp) do {} while (0)
44 #endif /* BCMDBG_ASSERT */
46 /* PCMCIA attribute space access macros */
47 #define OSL_PCMCIA_READ_ATTR(osh, offset, buf, size) \
49 #define OSL_PCMCIA_WRITE_ATTR(osh, offset, buf, size) \
52 /* PCI configuration space access macros */
53 #define OSL_PCI_READ_CONFIG(loc, offset, size) \
54 (offset == 8 ? 0 : 0xffffffff)
55 #define OSL_PCI_WRITE_CONFIG(loc, offset, size, val) \
58 /* PCI device bus # and slot # */
59 #define OSL_PCI_BUS(osh) (0)
60 #define OSL_PCI_SLOT(osh) (0)
62 /* register access macros */
63 #define wreg32(r, v) (*(volatile uint32*)(r) = (uint32)(v))
64 #define rreg32(r) (*(volatile uint32*)(r))
66 #define wreg16(r, v) (*(volatile uint16*)((ulong)(r)^2) = (uint16)(v))
67 #define rreg16(r) (*(volatile uint16*)((ulong)(r)^2))
68 #define wreg8(r, v) (*(volatile uint8*)((ulong)(r)^3) = (uint8)(v))
69 #define rreg8(r) (*(volatile uint8*)((ulong)(r)^3))
71 #define wreg16(r, v) (*(volatile uint16*)(r) = (uint16)(v))
72 #define rreg16(r) (*(volatile uint16*)(r))
73 #define wreg8(r, v) (*(volatile uint8*)(r) = (uint8)(v))
74 #define rreg8(r) (*(volatile uint8*)(r))
76 #define R_REG(osh, r) ({ \
77 __typeof(*(r)) __osl_v; \
78 switch (sizeof(*(r))) { \
79 case sizeof(uint8): __osl_v = rreg8((r)); break; \
80 case sizeof(uint16): __osl_v = rreg16((r)); break; \
81 case sizeof(uint32): __osl_v = rreg32((r)); break; \
85 #define W_REG(osh, r, v) do { \
86 switch (sizeof(*(r))) { \
87 case sizeof(uint8): wreg8((r), (v)); break; \
88 case sizeof(uint16): wreg16((r), (v)); break; \
89 case sizeof(uint32): wreg32((r), (v)); break; \
92 #define AND_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) & (v))
93 #define OR_REG(osh, r, v) W_REG(osh, (r), R_REG(osh, r) | (v))
95 /* bcopy, bcmp, and bzero */
96 #define bcmp(b1, b2, len) lib_memcmp((b1), (b2), (len))
100 pktfree_cb_fn_t tx_fn
;
104 extern osl_t
*osl_attach(void *pdev
);
105 extern void osl_detach(osl_t
*osh
);
107 #define PKTFREESETCB(osh, _tx_fn, _tx_ctx) \
109 osh->tx_fn = _tx_fn; \
110 osh->tx_ctx = _tx_ctx; \
113 /* general purpose memory allocation */
114 #define MALLOC(osh, size) KMALLOC((size), 0)
115 #define MFREE(osh, addr, size) KFREE((addr))
116 #define MALLOCED(osh) (0)
117 #define MALLOC_DUMP(osh, b)
118 #define MALLOC_FAILED(osh) (0)
120 /* uncached virtual address */
121 #define OSL_UNCACHED(va) ((void*)UNCADDR((ulong)(va)))
123 /* host/bus architecture-specific address byte swap */
124 #define BUS_SWAP32(v) (v)
126 /* get processor cycle count */
127 #define OSL_GETCYCLES(x) ((x) = 0)
129 /* microsecond delay */
130 #define OSL_DELAY(usec) cfe_usleep((cfe_cpu_speed/CPUCFG_CYCLESPERCPUTICK/1000000*(usec)))
132 #define OSL_ERROR(bcmerror) osl_error(bcmerror)
134 /* map/unmap physical to virtual I/O */
135 #define REG_MAP(pa, size) ((void*)UNCADDR((ulong)(pa)))
136 #define REG_UNMAP(va) do {} while (0)
138 /* dereference an address that may cause a bus exception */
139 #define BUSPROBE(val, addr) osl_busprobe(&(val), (uint32)(addr))
140 extern int osl_busprobe(uint32
*val
, uint32 addr
);
142 /* allocate/free shared (dma-able) consistent (uncached) memory */
143 #define DMA_CONSISTENT_ALIGN 4096 /* 4k alignment */
144 #define DMA_ALLOC_CONSISTENT(osh, size, pap, dmah) \
145 osl_dma_alloc_consistent((size), (pap))
146 #define DMA_FREE_CONSISTENT(osh, va, size, pa, dmah) \
147 osl_dma_free_consistent((void*)(va))
148 extern void *osl_dma_alloc_consistent(uint size
, ulong
*pap
);
149 extern void osl_dma_free_consistent(void *va
);
151 /* map/unmap direction */
152 #define DMA_TX 1 /* TX direction for DMA */
153 #define DMA_RX 2 /* RX direction for DMA */
155 /* map/unmap shared (dma-able) memory */
156 #define DMA_MAP(osh, va, size, direction, lb, dmah) ({ \
157 cfe_flushcache(CFE_CACHE_FLUSH_D); \
158 PHYSADDR((ulong)(va)); \
160 #define DMA_UNMAP(osh, pa, size, direction, p, dmah) \
163 /* API for DMA addressing capability */
164 #define OSL_DMADDRWIDTH(osh, addrwidth) do {} while (0)
166 /* shared (dma-able) memory access macros */
168 #define W_SM(r, v) (*(r) = (v))
169 #define BZERO_SM(r, len) lib_memset((r), '\0', (len))
171 /* generic packet structure */
172 #define LBUFSZ 4096 /* Size of Lbuf - 4k */
173 #define LBDATASZ (LBUFSZ - sizeof(struct lbuf))
175 struct lbuf
*next
; /* pointer to next lbuf if in a chain */
176 struct lbuf
*link
; /* pointer to next lbuf if in a list */
177 uchar
*head
; /* start of buffer */
178 uchar
*end
; /* end of buffer */
179 uchar
*data
; /* start of data */
180 uchar
*tail
; /* end of data */
181 uint len
; /* nbytes of data */
182 uchar pkttag
[OSL_PKTTAG_SZ
]; /* pkttag area */
185 #define PKTBUFSZ 2048 /* largest reasonable packet buffer, driver uses for ethernet MTU */
187 /* packet primitives */
188 #define PKTGET(osh, len, send) ((void*)osl_pktget((len)))
189 #define PKTFREE(osh, lb, send) osl_pktfree((osh), (struct lbuf*)(lb), (send))
190 #define PKTDATA(osh, lb) (((struct lbuf*)(lb))->data)
191 #define PKTLEN(osh, lb) (((struct lbuf*)(lb))->len)
192 #define PKTHEADROOM(osh, lb) (PKTDATA(osh, lb)-(((struct lbuf*)(lb))->head))
193 #define PKTTAILROOM(osh, lb) ((((struct lbuf*)(lb))->end)-(((struct lbuf*)(lb))->tail))
194 #define PKTNEXT(osh, lb) (((struct lbuf*)(lb))->next)
195 #define PKTSETNEXT(osh, lb, x) (((struct lbuf*)(lb))->next = (struct lbuf*)(x))
196 #define PKTSETLEN(osh, lb, len) osl_pktsetlen((struct lbuf*)(lb), (len))
197 #define PKTPUSH(osh, lb, bytes) osl_pktpush((struct lbuf*)(lb), (bytes))
198 #define PKTPULL(osh, lb, bytes) osl_pktpull((struct lbuf*)(lb), (bytes))
199 #define PKTDUP(osh, lb) osl_pktdup((struct lbuf*)(lb))
200 #define PKTTAG(lb) (((void *) ((struct lbuf *)(lb))->pkttag))
201 #define PKTLINK(lb) (((struct lbuf*)(lb))->link)
202 #define PKTSETLINK(lb, x) (((struct lbuf*)(lb))->link = (struct lbuf*)(x))
203 #define PKTPRIO(lb) (0)
204 #define PKTSETPRIO(lb, x) do {} while (0)
205 #define PKTFRMNATIVE(buffer, lb) osl_pkt_frmnative((buffer), (struct lbuf *)(lb))
206 #define PKTTONATIVE(lb, buffer) osl_pkt_tonative((lb), (buffer))
207 #define PKTSHARED(lb) (1)
208 #define PKTALLOCED(osh) (0)
209 #define PKTLIST_DUMP(osh, buf)
211 extern void osl_pkt_frmnative(iocb_buffer_t
*buffer
, struct lbuf
*lb
);
212 extern void osl_pkt_tonative(struct lbuf
* lb
, iocb_buffer_t
*buffer
);
213 extern struct lbuf
*osl_pktget(uint len
);
214 extern void osl_pktfree(osl_t
*osh
, struct lbuf
*lb
, bool send
);
215 extern void osl_pktsetlen(struct lbuf
*lb
, uint len
);
216 extern uchar
*osl_pktpush(struct lbuf
*lb
, uint bytes
);
217 extern uchar
*osl_pktpull(struct lbuf
*lb
, uint bytes
);
218 extern struct lbuf
*osl_pktdup(struct lbuf
*lb
);
219 extern int osl_error(int bcmerror
);
221 #endif /* _cfe_osl_h_ */