source: libbsdport/bsd_eth_drivers/if_em/e1000_osdep.h @ 89376b7

B_20100615baselibbsdport-4-10-branch initial
Last change on this file since 89376b7 was 89376b7, checked in by Joel Sherrill <joel.sherrill@…>, on Feb 19, 2009 at 7:55:40 PM

Initial import.

  • Property mode set to 100644
File size: 13.2 KB
Line 
1/**************************************************************************
2
3Copyright (c) 2001-2007, Intel Corporation
4All rights reserved.
5
6Redistribution and use in source and binary forms, with or without
7modification, are permitted provided that the following conditions are met:
8
9 1. Redistributions of source code must retain the above copyright notice,
10    this list of conditions and the following disclaimer.
11
12 2. Redistributions in binary form must reproduce the above copyright
13    notice, this list of conditions and the following disclaimer in the
14    documentation and/or other materials provided with the distribution.
15
16 3. Neither the name of the Intel Corporation nor the names of its
17    contributors may be used to endorse or promote products derived from
18    this software without specific prior written permission.
19
20THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30POSSIBILITY OF SUCH DAMAGE.
31
32***************************************************************************/
33/*$FreeBSD: src/sys/dev/em/e1000_osdep.h,v 1.3 2007/05/16 00:14:23 jfv Exp $*/
34
35
36#ifndef _FREEBSD_OS_H_
37#define _FREEBSD_OS_H_
38
39#include <rtems.h>
40#define _KERNEL
41#include <rtems/rtems_bsdnet_internal.h>
42#include <bsp.h>
43
44#include <sys/types.h>
45#include <sys/param.h>
46#include <sys/systm.h>
47#include <sys/mbuf.h>
48#include <sys/protosw.h>
49#include <sys/socket.h>
50#include <sys/malloc.h>
51#include <sys/kernel.h>
52#include <sys/bus.h>
53#include <rtems/pci.h>
54
55#define ASSERT(x) if(!(x)) panic("EM: x")
56
57/* The happy-fun DELAY macro is defined in /usr/src/sys/i386/include/clock.h */
58#define usec_delay(x) DELAY(x)
59#define msec_delay(x) DELAY(1000*(x))
60/* TODO: Should we be paranoid about delaying in interrupt context? */
61#define msec_delay_irq(x) DELAY(1000*(x))
62#include <rtems_udelay.h>
63
64#define MSGOUT(S, A, B)     printf(S "\n", A, B)
65#define DEBUGFUNC(F)        DEBUGOUT(F);
66        #define DEBUGOUT(S)
67        #define DEBUGOUT1(S,A)
68        #define DEBUGOUT2(S,A,B)
69        #define DEBUGOUT3(S,A,B,C)
70        #define DEBUGOUT7(S,A,B,C,D,E,F,G)
71
72#define STATIC                          static
73#ifndef FALSE
74#define FALSE               0
75#endif
76#ifndef TRUE
77#define TRUE                1
78#endif
79#define CMD_MEM_WRT_INVALIDATE          0x0010  /* BIT_4 */
80#define PCI_COMMAND_REGISTER            PCIR_COMMAND
81
82/*
83** These typedefs are necessary due to the new
84** shared code, they are native to Linux.
85*/
86typedef uint64_t        u64;
87typedef uint32_t        u32;
88typedef uint16_t        u16;
89typedef uint8_t         u8 ;
90typedef int64_t         s64;
91typedef int32_t         s32;
92typedef int16_t         s16;
93typedef int8_t          s8 ;
94
95#include <devicet.h>
96
97struct e1000_osdep
98{
99        uint32_t mem_bus_space_handle;
100        uint32_t io_bus_space_handle;
101        uint32_t flash_bus_space_handle;
102        /* these are currently unused; present for freebsd compatibility only */
103        uint32_t mem_bus_space_tag;
104        uint32_t io_bus_space_tag;
105        uint32_t flash_bus_space_tag;
106        device_t dev;   
107};
108
109typedef volatile uint32_t __attribute__((may_alias)) *__uint32_a_p_t;
110typedef volatile uint16_t __attribute__((may_alias)) *__uint16_a_p_t;
111typedef volatile uint8_t  __attribute__((may_alias)) * __uint8_a_p_t;
112
113#ifdef __PPC__
114#include <libcpu/io.h>
115static inline uint8_t __in_8(uint32_t base, uint32_t offset)
116{
117__uint8_a_p_t a = (__uint8_a_p_t)(base+offset);
118uint8_t     rval;
119        __asm__ __volatile__(
120                "sync;\n"
121                "lbz%U1%X1 %0,%1;\n"
122                "twi 0,%0,0;\n"
123                "isync" : "=r" (rval) : "m"(*a));
124        return rval;
125}
126
127static inline void __out_8(uint32_t base, uint32_t offset, uint8_t val)
128{
129__uint8_a_p_t a = (__uint8_a_p_t)(base+offset);
130        __asm__ __volatile__(
131                "stb%U0%X0 %1,%0; eieio" : "=m" (*a) : "r"(val)
132        );
133}
134
135static inline uint16_t __in_le16(uint32_t base, uint32_t offset)
136{
137__uint16_a_p_t a = (__uint16_a_p_t)(base+offset);
138uint16_t     rval;
139        __asm__ __volatile__(
140                "sync;\n"
141                "lhbrx %0,0,%1;\n"
142                "twi 0,%0,0;\n"
143                "isync" : "=r" (rval) : "r"(a), "m"(*a));
144        return rval;
145}
146
147static inline void __out_le16(uint32_t base, uint32_t offset, uint16_t val)
148{
149__uint16_a_p_t a = (__uint16_a_p_t)(base+offset);
150        __asm__ __volatile__(
151                "sync; sthbrx %1,0,%2" : "=m" (*a) : "r"(val), "r"(a)
152        );
153}
154
155static inline uint32_t __in_le32(uint32_t base, uint32_t offset)
156{
157__uint32_a_p_t a = (__uint32_a_p_t)(base+offset);
158uint32_t     rval;
159        __asm__ __volatile__(
160                "sync;\n"
161                "lwbrx %0,0,%1;\n"
162                "twi 0,%0,0;\n"
163                "isync" : "=r" (rval) : "r"(a), "m"(*a));
164        return rval;
165}
166
167static inline void __out_le32(uint32_t base, uint32_t offset, uint32_t val)
168{
169__uint32_a_p_t a = (__uint32_a_p_t)(base+offset);
170        __asm__ __volatile__(
171                "sync; stwbrx %1,0,%2" : "=m" (*a) : "r"(val), "r"(a)
172        );
173}
174
175#ifdef _IO_BASE
176static inline void __outport_dword(uint32_t base, uint32_t off, uint32_t val)
177{
178        __out_le32(_IO_BASE+base+off,0,val);
179}
180#else
181#error "_IO_BASE needs to be defined by BSP (bsp.h)"
182#endif
183
184#elif defined(__i386__)
185#include <libcpu/cpu.h>
186static inline uint8_t __in_8(uint32_t base, uint32_t offset)
187{
188__uint8_a_p_t a = (__uint8_a_p_t)(base+offset);
189        return *a;
190}
191
192static inline void __out_8(uint32_t base, uint32_t offset, uint8_t val)
193{
194__uint8_a_p_t a = (__uint8_a_p_t)(base+offset);
195        *a = val;
196}
197
198static inline uint16_t __in_le16(uint32_t base, uint32_t offset)
199{
200__uint16_a_p_t a = (__uint16_a_p_t)(base+offset);
201        return *a;
202}
203
204static inline void __out_le16(uint32_t base, uint32_t offset, uint16_t val)
205{
206__uint16_a_p_t a = (__uint16_a_p_t)(base+offset);
207        *a = val;
208}
209
210static inline uint32_t __in_le32(uint32_t base, uint32_t offset)
211{
212__uint32_a_p_t a = (__uint32_a_p_t)(base+offset);
213        return *a;
214}
215
216static inline void __out_le32(uint32_t base, uint32_t offset, uint32_t val)
217{
218__uint32_a_p_t a = (__uint32_a_p_t)(base+offset);
219        *a = val;
220}
221
222
223static inline void __outport_dword(uint32_t base, uint32_t off, uint32_t val)
224{
225        i386_outport_long( (base + off), val );
226}
227
228#else
229#error "not ported to this CPU architecture yet"
230#endif
231
232#ifdef NO_82542_SUPPORT
233#define E1000_REGISTER(hw, reg) reg
234#else
235#define E1000_REGISTER(hw, reg) (((hw)->mac.type >= e1000_82543) \
236    ? reg : e1000_translate_register_82542(reg))
237#endif
238
239#define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, E1000_STATUS)
240
241#define USE_EXPLICIT_BUSTAGS
242
243#ifdef USE_EXPLICIT_BUSTAGS /* Help compiler by specifying explicit bus tags */
244
245/* Read from an absolute offset in the adapter's memory space */
246#define E1000_READ_OFFSET(hw, offset) \
247    bus_space_read_4(bus_space_mem, \
248    ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset)
249
250/* Write to an absolute offset in the adapter's memory space */
251#define E1000_WRITE_OFFSET(hw, offset, value) \
252    bus_space_write_4(bus_space_mem, \
253    ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset, value)
254
255/* Register READ/WRITE macros */
256
257#define E1000_READ_REG(hw, reg) \
258    bus_space_read_4(bus_space_mem, \
259        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
260        E1000_REGISTER(hw, reg))
261
262#define E1000_WRITE_REG(hw, reg, value) \
263    bus_space_write_4(bus_space_mem, \
264        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
265        E1000_REGISTER(hw, reg), value)
266
267#define E1000_READ_REG_ARRAY(hw, reg, index) \
268    bus_space_read_4(bus_space_mem, \
269        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
270        E1000_REGISTER(hw, reg) + ((index)<< 2))
271
272#define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \
273    bus_space_write_4(bus_space_mem, \
274        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
275        E1000_REGISTER(hw, reg) + ((index)<< 2), value)
276
277#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
278#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
279
280#define E1000_READ_REG_ARRAY_BYTE(hw, reg, index) \
281    bus_space_read_1(bus_space_mem, \
282        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
283        E1000_REGISTER(hw, reg) + index)
284
285#define E1000_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \
286    bus_space_write_1(bus_space_mem, \
287        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
288        E1000_REGISTER(hw, reg) + index, value)
289
290#define E1000_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \
291    bus_space_write_2(bus_space_mem, \
292        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
293        E1000_REGISTER(hw, reg) + (index << 1), value)
294
295#define E1000_WRITE_REG_IO(hw, reg, value) do {\
296    bus_space_write_4(bus_space_io, \
297        ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
298        (hw)->io_base, reg); \
299    bus_space_write_4(bus_space_io, \
300        ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
301        (hw)->io_base + 4, value); } while (0)
302
303#define E1000_READ_FLASH_REG(hw, reg) \
304    bus_space_read_4(bus_space_mem, \
305        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
306
307#define E1000_READ_FLASH_REG16(hw, reg) \
308    bus_space_read_2(bus_space_mem, \
309        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
310
311#define E1000_WRITE_FLASH_REG(hw, reg, value) \
312    bus_space_write_4(bus_space_mem, \
313        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
314
315#define E1000_WRITE_FLASH_REG16(hw, reg, value) \
316    bus_space_write_2(bus_space_mem, \
317        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
318
319#else /* USE_EXPLICIT_BUSTAGS */
320
321/* Read from an absolute offset in the adapter's memory space */
322#define E1000_READ_OFFSET(hw, offset) \
323    bus_space_read_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
324    ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset)
325
326/* Write to an absolute offset in the adapter's memory space */
327#define E1000_WRITE_OFFSET(hw, offset, value) \
328    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
329    ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, offset, value)
330
331/* Register READ/WRITE macros */
332
333#define E1000_READ_REG(hw, reg) \
334    bus_space_read_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
335        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
336        E1000_REGISTER(hw, reg))
337
338#define E1000_WRITE_REG(hw, reg, value) \
339    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
340        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
341        E1000_REGISTER(hw, reg), value)
342
343#define E1000_READ_REG_ARRAY(hw, reg, index) \
344    bus_space_read_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
345        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
346        E1000_REGISTER(hw, reg) + ((index)<< 2))
347
348#define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \
349    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
350        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
351        E1000_REGISTER(hw, reg) + ((index)<< 2), value)
352
353#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
354#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
355
356#define E1000_READ_REG_ARRAY_BYTE(hw, reg, index) \
357    bus_space_read_1(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
358        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
359        E1000_REGISTER(hw, reg) + index)
360
361#define E1000_WRITE_REG_ARRAY_BYTE(hw, reg, index, value) \
362    bus_space_write_1(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
363        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
364        E1000_REGISTER(hw, reg) + index, value)
365
366#define E1000_WRITE_REG_ARRAY_WORD(hw, reg, index, value) \
367    bus_space_write_2(((struct e1000_osdep *)(hw)->back)->mem_bus_space_tag, \
368        ((struct e1000_osdep *)(hw)->back)->mem_bus_space_handle, \
369        E1000_REGISTER(hw, reg) + (index << 1), value)
370
371#define E1000_WRITE_REG_IO(hw, reg, value) do {\
372    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->io_bus_space_tag, \
373        ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
374        (hw)->io_base, reg); \
375    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->io_bus_space_tag, \
376        ((struct e1000_osdep *)(hw)->back)->io_bus_space_handle, \
377        (hw)->io_base + 4, value); } while (0)
378
379#define E1000_READ_FLASH_REG(hw, reg) \
380    bus_space_read_4(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
381        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
382
383#define E1000_READ_FLASH_REG16(hw, reg) \
384    bus_space_read_2(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
385        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg)
386
387#define E1000_WRITE_FLASH_REG(hw, reg, value) \
388    bus_space_write_4(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
389        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
390
391#define E1000_WRITE_FLASH_REG16(hw, reg, value) \
392    bus_space_write_2(((struct e1000_osdep *)(hw)->back)->flash_bus_space_tag, \
393        ((struct e1000_osdep *)(hw)->back)->flash_bus_space_handle, reg, value)
394#endif /* USE_EXPLICIT_BUSTAGS */
395
396#endif  /* _FREEBSD_OS_H_ */
397
Note: See TracBrowser for help on using the repository browser.