1#ifndef RTEMS_COMPAT_BSD_NET_H
2#define RTEMS_COMPAT_BSD_NET_H
19#define ISMINVERSION(ma,mi,re) \
20 ( __RTEMS_MAJOR__ > (ma) \
21 || (__RTEMS_MAJOR__ == (ma) && __RTEMS_MINOR__ > (mi)) \
22 || (__RTEMS_MAJOR__ == (ma) && __RTEMS_MINOR__ == (mi) && __RTEMS_REVISION__ >= (re)) \
26#define _DO_ALIGN(addr, align) (((uint32_t)(addr) + (align) - 1) & ~((align)-1))
30static inline void *the_real_malloc(
size_t n)
35static inline void the_real_free(
void *
p)
40#include <machine/rtems-bsd-kernel-space.h>
41#include <rtems/rtems_bsdnet.h>
42#include <rtems/rtems_bsdnet_internal.h>
44#include <libcpu/cpu.h>
48#error "dunno what IO ops to use on this architecture"
52#define NET_EMB(x,y,z) x ## y ## z
53#define NET_EMBEMB(x,y,z) NET_EMB(x,y,z)
55#define NET_STR(arg) #arg
56#define NET_STRSTR(arg) NET_STR(arg)
58#define NET_SOFTC NET_EMBEMB(,NETDRIVER_PREFIX,_softc)
60#define METHODS NET_EMBEMB(rtems_,NETDRIVER_PREFIX,_methods)
64#define METHODSPTR NET_EMBEMB(rtems_,NETDRIVER_PREFIX,_methods_p)
67#define METHODSPTR (&METHODS)
70#if defined(__LITTLE_ENDIAN__) || (__i386__)
71static inline uint16_t htole16(uint16_t
v) {
return v; }
72static inline uint32_t htole32(uint32_t
v) {
return v; }
73static inline uint64_t htole64(uint64_t
v) {
return v; }
74static inline uint16_t le16toh(uint16_t
v) {
return v; }
75static inline uint32_t le32toh(uint32_t
v) {
return v; }
76static inline uint64_t le64toh(uint64_t
v) {
return v; }
77#elif defined(__BIG_ENDIAN__)
79#include <libcpu/byteorder.h>
87#if ISMINVERSION(4,8,0)
88typedef uint32_t rtemscompat_32_t;
90typedef unsigned rtemscompat_32_t;
101static inline uint16_t
104 return ld_le16((
unsigned short*)&
v);
107static inline uint32_t
110rtemscompat_32_t rval;
115static inline uint32_t
118rtemscompat_32_t vv =
v;
126static inline uint64_t
130 rtemscompat_32_t tmp[2];
134 st_le32( &u.tmp[0], (
unsigned)(
v&0xffffffff) );
135 st_le32( &u.tmp[1], (
unsigned)((
v>>32)&0xffffffff) );
141#error "need htoleXX() implementation for this CPU arch"
145#error "Unknown CPU endianness"
151#define _out_byte(a,v) out_8((volatile uint8_t*)(a),(v))
152#define _inp_byte(a) in_8((volatile uint8_t*)(a))
154#define _out_word(a,v) out_le16((volatile uint16_t*)(a),(v))
155#define _out_long(a,v) out_le32((volatile uint32_t *)(a),(v))
156#define _inp_word(a) in_le16((volatile uint16_t*)(a))
157#define _inp_long(a) in_le32((volatile uint32_t *)(a))
158#elif defined(NET_CHIP_BE)
159#define _out_word(a,v) out_be16((volatile uint16_t*)(a),(v))
160#define _out_long(a,v) out_be32((volatile uint32_t *)(a),(v))
161#define _inp_word(a) in_be16((volatile uint16_t*)(a))
162#define _inp_long(a) in_be32((volatile uint32_t *)(a))
164#error rtemscompat_defs.h must define either NET_CHIP_LE or NET_CHIP_BE
166static inline void wrle32(
unsigned *a,
unsigned v)
168 asm volatile(
"stwbrx %1,0,%2":
"=m"(*a):
"r"(
v),
"r"(a));
170static inline unsigned rdle32(
unsigned *a)
172 asm volatile(
"lwbrx %0,0,%0":
"=r"(a):
"0"(a),
"m"(*a));
175static inline void orle32(
unsigned *a,
unsigned v) { wrle32(a, rdle32(a) |
v); }
176static inline void anle32(
unsigned *a,
unsigned v) { wrle32(a, rdle32(a) &
v); }
178static inline void wrle16(
unsigned short *a,
unsigned short v)
180 asm volatile(
"sthbrx %1,0,%2":
"=m"(*a):
"r"(
v),
"r"(a));
182static inline unsigned short rdle16(
unsigned short *a)
184 asm volatile(
"lhbrx %0,0,%0":
"=r"(a):
"0"(a),
"m"(*a));
185 return (
unsigned short)(unsigned)a;
187static inline void orle16(
unsigned short *a,
unsigned short v) { wrle16(a, rdle16(a) |
v); }
188static inline void anle16(
unsigned short *a,
unsigned short v) { wrle16(a, rdle16(a) &
v); }
193#error dunno how to output BE data
196static inline void wrle32(
volatile unsigned *
p,
unsigned v) { *
p =
v; }
197static inline void orle32(
volatile unsigned *
p,
unsigned v) { *
p |=
v; }
198static inline void anle32(
volatile unsigned *
p,
unsigned v) { *
p &=
v; }
199static inline unsigned rdle32(
volatile unsigned *
p) {
return *
p; }
201static inline void wrle16(
volatile unsigned short *
p,
unsigned short v) { *
p =
v; }
202static inline void orle16(
volatile unsigned short *
p,
unsigned short v) { *
p |=
v; }
203static inline void anle16(
volatile unsigned short *
p,
unsigned short v) { *
p &=
v; }
204static inline unsigned short rdle16(
volatile unsigned short *
p) {
return *
p; }
206#ifdef NET_CHIP_MEM_IO
209static inline void _out_byte(
unsigned a,
unsigned char v) { *(
volatile unsigned char*)a =
v; }
210static inline unsigned char _inp_byte(
unsigned a) {
return *(
volatile unsigned char*)a; }
212static inline void _out_word(
unsigned a,
unsigned short v) { *(
volatile unsigned short*)a =
v; }
213static inline unsigned short _inp_word(
unsigned a) {
return *(
volatile unsigned short*)a; }
214static inline void _out_long(
unsigned a,
unsigned v) { *(
volatile unsigned *)a =
v; }
215static inline unsigned _inp_long(
unsigned a) {
return *(
volatile unsigned *)a; }
216#elif defined(NET_CHIP_BE)
217#error "BE memory IO not implemented for i386 yet"
219#error rtemscompat_defs.h must define either NET_CHIP_LE or NET_CHIP_BE
223#error "Memory IO not implemented for this CPU architecture yet"
226#elif defined(NET_CHIP_PORT_IO)
227#define _out_byte(addr,val) outport_byte((addr),(val))
228#define _out_word(addr,val) outport_word((addr),(val))
229#define _out_long(addr,val) outport_long((addr),(val))
231static inline u_int8_t _inp_byte(
volatile unsigned char *a)
233register u_int8_t rval;
234 inport_byte((
unsigned short)(
unsigned)a,rval);
237static inline u_int16_t _inp_word(
volatile unsigned short *a)
239register u_int16_t rval;
240 inport_word((
unsigned short)(
unsigned)a,rval);
243static inline u_int32_t _inp_long(
volatile unsigned *a)
245register u_int32_t rval;
246 inport_long((
unsigned short)(
unsigned)a,rval);
250#error either NET_CHIP_MEM_IO or NET_CHIP_PORT_IO must be defined
258#define device_printf(device,format,args...) printk(format,## args)
260static inline u_int8_t bus_space_do_read_1(u_long handle,
unsigned reg)
262 return _inp_byte((
volatile unsigned char*)((handle)+(reg)));
265static inline u_int16_t bus_space_do_read_2(u_long handle,
unsigned reg)
267 return _inp_word((
volatile unsigned short*)((handle)+(reg)));
270static inline u_int32_t bus_space_do_read_4(u_long handle,
unsigned reg)
272 return _inp_long((
volatile unsigned *)((handle)+(reg)));
275#define bus_space_read_1(tag,handle,reg) bus_space_do_read_1((handle),(reg))
276#define bus_space_read_2(tag,handle,reg) bus_space_do_read_2((handle),(reg))
277#define bus_space_read_4(tag,handle,reg) bus_space_do_read_4((handle),(reg))
279static inline void bus_space_do_write_multi_1(u_long handle,
unsigned reg,
unsigned char *addr,
int cnt)
281 int i;
for (i=0; i<cnt; i++) _out_byte( (handle) + (reg), (addr)[i]);
284static inline void bus_space_do_write_multi_2(u_long handle,
unsigned reg,
unsigned short *addr,
int cnt)
286 int i;
for (i=0; i<cnt; i++) _out_word( (handle) + (reg), (addr)[i]);
289static inline void bus_space_do_write_multi_4(u_long handle,
unsigned reg,
unsigned long *addr,
int cnt)
291 int i;
for (i=0; i<cnt; i++) _out_long( (handle) + (reg), (addr)[i]);
295#define bus_space_write_multi_1(tag, handle, reg, addr, cnt) \
296 bus_space_do_write_multi_1(handle, reg, addr, cnt)
297#define bus_space_write_multi_2(tag, handle, reg, addr, cnt) \
298 bus_space_do_write_multi_2(handle, reg, addr, cnt)
299#define bus_space_write_multi_4(tag, handle, reg, addr, cnt) \
300 bus_space_do_write_multi_4(handle, reg, addr, cnt)
302static inline void bus_space_do_read_multi_1(u_long handle,
unsigned reg,
unsigned char *addr,
int cnt)
304 int i;
for (i=0; i<cnt; i++)
305 (addr)[i] = _inp_byte((
volatile unsigned char*)((handle)+(reg)));
308static inline void bus_space_do_read_multi_2(u_long handle,
unsigned reg,
unsigned short *addr,
int cnt)
310 int i;
for (i=0; i<cnt; i++)
311 (addr)[i] = _inp_word((
volatile unsigned short*)((handle)+(reg)));
314static inline void bus_space_do_read_multi_4(u_long handle,
unsigned reg,
unsigned long *addr,
int cnt)
316 int i;
for (i=0; i<cnt; i++)
317 (addr)[i] = _inp_long((
volatile unsigned *)((handle)+(reg)));
320#define bus_space_read_multi_1(tag, handle, reg, addr, cnt) \
321 bus_space_do_read_multi_1(handle, reg, addr, cnt)
322#define bus_space_read_multi_2(tag, handle, reg, addr, cnt) \
323 bus_space_do_read_multi_2(handle, reg, addr, cnt)
324#define bus_space_read_multi_4(tag, handle, reg, addr, cnt) \
325 bus_space_do_read_multi_4(handle, reg, addr, cnt)
329#define bus_space_write_1(tag, handle, reg, val) \
330 do { _out_byte( (handle) + (reg), (val)); } while (0)
332#define bus_space_write_2(tag, handle, reg, val) \
333 do { _out_word( (handle) + (reg), (val)); } while (0)
335#define bus_space_write_4(tag, handle, reg, val) \
336 do { _out_long( (handle) + (reg), (val)); } while (0)
338#define BPF_MTAP(a,b) do { } while (0)
340extern unsigned net_driver_ticks_per_sec;
344#define DELAY(n) do { \
346 rtems_task_wake_after((((n)*net_driver_ticks_per_sec)/1000000) + 1); \
348 rtems_bsp_delay(n); \
351#warning "Have no good usec delay implementation"
352#define DELAY(n) do { \
353 rtems_task_wake_after((((n)*net_driver_ticks_per_sec)/1000000) + 1); \
358#define IRQ_LOCKED(code) \
359 do { unsigned long _xtre_irq_flags; \
360 rtems_interrupt_disable(_xtre_irq_flags); \
361 do { code } while(0); \
362 rtems_interrupt_enable(_xtre_irq_flags); \
365typedef void (driver_intr_t)(
void *);
367#define if_xname if_name
372#ifndef PCI_DRAM_OFFSET
373#define PCI_DRAM_OFFSET 0
377#define PCI_MEM_BASE 0
380#define kvtop(a) ((unsigned long)(a) + PCI_DRAM_OFFSET)
381#define vtophys(a) ((unsigned long)(a) + PCI_DRAM_OFFSET)
383#define PCI2LOCAL(a,bus) ((unsigned long)(a) + PCI_MEM_BASE)
386#define PCI_IO_2LOCAL(a,bus) ((unsigned long)(a) + PCI0_IO_BASE)
387#elif defined(PCI_IO_BASE)
388#define PCI_IO_2LOCAL(a,bus) ((unsigned long)(a) + PCI_IO_BASE)
389#elif defined(_IO_BASE)
390#define PCI_IO_2LOCAL(a,bus) ((unsigned long)(a) + _IO_BASE)
392#warning "Unable to determine base address of PCI IO space; using ZERO"
393#define PCI_IO_2LOCAL(a,bus) ((unsigned long)(a))
396#define if_printf(if,fmt,args...) printf("%s:"fmt,(if)->if_name,args)
398#ifndef BUS_PROBE_DEFAULT
399#define BUS_PROBE_DEFAULT 0
412void *ptr = rtems_bsdnet_malloc(
size +
sizeof(ptr) + align-1, type, flags);
415 unsigned tmp = (unsigned)ptr + align - 1;
419 *(
void**)(rval+
size) = ptr;
425contigfree(
void *ptr,
size_t size,
int type)
427 rtems_bsdnet_free( *(
void**)((
unsigned)ptr +
size), type);
431#define callout_init(args...) do {} while (0);
432#define callout_reset(args...) do {} while (0);
433#define callout_stop(args...) do {} while (0);
435#define IFQ_DRV_IS_EMPTY(q) (0 == (q)->ifq_head)
436#define IFQ_DRV_DEQUEUE(q,m) IF_DEQUEUE((q),(m))
437#define IFQ_DRV_PREPEND(q,m) IF_PREPEND((q),(m))
439#define DO_ETHER_INPUT_SKIPPING_ETHER_HEADER(ifp,m) \
440 { struct ether_header *eh; \
441 eh = mtod(m, struct ether_header*); \
442 m->m_data += sizeof(struct ether_header); \
443 m->m_len -= sizeof(struct ether_header); \
444 m->m_pkthdr.len -= sizeof(struct ether_header); \
445 m->m_pkthdr.rcvif = ifp; \
446 ether_input(ifp, eh, m); \
450#ifndef __KERNEL_RCSID
451#define __KERNEL_RCSID(arg...)
Interface to Kernel Print Methods.
Definition: rtemscompat1.h:32
unsigned v
Definition: tte.h:0
unsigned size
Definition: tte.h:1
unsigned p
Definition: tte.h:17