Changeset 370f3c5 in libbsdport


Ignore:
Timestamp:
Aug 5, 2009, 9:41:20 PM (10 years ago)
Author:
Till Straumann <strauman@…>
Branches:
master
Children:
d8b6f64
Parents:
c47c1f8
Message:

2009-08-05 Till Straumann <Till.Straumann@…>

  • if_em/Makefile.am, if_em/e1000_osdep.h, if_em/if_em.c: Changed 'e1000_osdep.h' to provide stdalone I/O methods for select architectures (x86 and PPC -- others fall back on libbsdport/bus.h). This lets the low-level driver (everything except for 'if_em.c/if_em.h') API be independent of BSD networking and libbsdport which is desirable since certain applications may wish to just use the low-level API for implementing dedicated 'raw-ethernet' drivers for BSD-independent, proprietary GigE communication.
Location:
bsd_eth_drivers
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • bsd_eth_drivers/ChangeLog

    rc47c1f8 r370f3c5  
     12009-08-05  Till Straumann <Till.Straumann@TU-Berlin.de>
     2
     3        * if_em/Makefile.am, if_em/e1000_osdep.h, if_em/if_em.c:
     4        Changed 'e1000_osdep.h' to provide stdalone I/O methods for
     5        select architectures (x86 and PPC -- others fall back on
     6        libbsdport/bus.h). This lets the low-level driver (everything
     7        except for 'if_em.c/if_em.h') API be independent of
     8        BSD networking and libbsdport which is desirable since
     9        certain applications may wish to just use the low-level
     10        API for implementing dedicated 'raw-ethernet' drivers
     11        for BSD-independent, proprietary GigE communication.
     12
    1132009-08-05  Till Straumann <Till.Straumann@TU-Berlin.de>
    214
  • bsd_eth_drivers/if_em/Makefile.am

    rc47c1f8 r370f3c5  
    3232lib_LIBRARIES                    = libif_em.a
    3333
     34AM_CPPFLAGS                     += -D_KERNEL
    3435AM_CPPFLAGS                     += -I$(srcdir)
    3536AM_CPPFLAGS                     += -I$(srcdir)/../libbsdport -I../libbsdport  -I../libbsdport/dummyheaders
  • bsd_eth_drivers/if_em/e1000_osdep.h

    rc47c1f8 r370f3c5  
    3838
    3939#include <rtems.h>
    40 #define _KERNEL
     40#include <bsp.h>
     41#include <rtems/pci.h>
     42#include <vm/vm.h> /* for non-_KERNEL boolean_t :-( */
     43
     44#ifdef   _KERNEL
    4145#include <rtems/rtems_bsdnet_internal.h>
    42 #include <bsp.h>
    4346
    4447#include <sys/types.h>
     
    5154#include <sys/kernel.h>
    5255#include <sys/bus.h>
    53 #include <rtems/pci.h>
    5456
    5557#define ASSERT(x) if(!(x)) panic("EM: x")
     
    7072        #define DEBUGOUT7(S,A,B,C,D,E,F,G)
    7173
     74#include <devicet.h>
     75
     76struct e1000_osdep
     77{
     78        uint32_t mem_bus_space_handle;
     79        uint32_t io_bus_space_handle;
     80        uint32_t flash_bus_space_handle;
     81        /* these are currently unused; present for freebsd compatibility only */
     82        uint32_t mem_bus_space_tag;
     83        uint32_t io_bus_space_tag;
     84        uint32_t flash_bus_space_tag;
     85        device_t dev;   
     86};
     87
    7288#define STATIC                          static
     89#endif
     90
    7391#ifndef FALSE
    7492#define FALSE               0
     
    7795#define TRUE                1
    7896#endif
     97
    7998#define CMD_MEM_WRT_INVALIDATE          0x0010  /* BIT_4 */
    8099#define PCI_COMMAND_REGISTER            PCIR_COMMAND
     
    93112typedef int8_t          s8 ;
    94113
    95 #include <devicet.h>
    96 
    97 struct 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 
    109 typedef volatile uint32_t __attribute__((may_alias)) *__uint32_a_p_t;
    110 typedef volatile uint16_t __attribute__((may_alias)) *__uint16_a_p_t;
    111 typedef volatile uint8_t  __attribute__((may_alias)) * __uint8_a_p_t;
    112 
    113 #ifdef __PPC__
    114 #include <libcpu/io.h>
    115 static inline uint8_t __in_8(uint32_t base, uint32_t offset)
    116 {
    117 __uint8_a_p_t a = (__uint8_a_p_t)(base+offset);
    118 uint8_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 
    127 static 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 
    135 static inline uint16_t __in_le16(uint32_t base, uint32_t offset)
    136 {
    137 __uint16_a_p_t a = (__uint16_a_p_t)(base+offset);
    138 uint16_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 
    147 static 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 
    155 static inline uint32_t __in_le32(uint32_t base, uint32_t offset)
    156 {
    157 __uint32_a_p_t a = (__uint32_a_p_t)(base+offset);
    158 uint32_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 
    167 static 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
    176 static 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>
    186 static 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 
    192 static 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 
    198 static 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 
    204 static 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 
    210 static 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 
    216 static 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 
    223 static 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
     114typedef volatile uint32_t __uint32_va_t __attribute__((may_alias));
     115typedef volatile uint16_t __uint16_va_t __attribute__((may_alias));
    231116
    232117#ifdef NO_82542_SUPPORT
     
    238123
    239124#define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, E1000_STATUS)
     125
     126/* Provide our own I/O so that the low-level driver API can
     127 * be used independently from the BSD stuff.
     128 * This is useful for people who want to use an e1000 adapter
     129 * for special ethernet links that do not use BSD TCP/IP.
     130 */
     131#ifdef __PPC__
     132
     133#include <libcpu/io.h>
     134
     135static inline uint16_t __in_le16(uint8_t *base, uint32_t offset)
     136{
     137uint16_t     rval;
     138    __asm__ __volatile__(
     139        "lhbrx %0,%2,%1; eieio\n"
     140            : "=r" (rval)
     141            : "r"(base), "b"(offset), "m"(*(__uint16_va_t*)(base + offset))
     142    );
     143    return rval;
     144}
     145
     146static inline __out_le16(uint8_t *base, uint32_t offset, uint16_t val)
     147{
     148    __asm__ __volatile__(
     149        "sthbrx %1,%3,%2; eieio"
     150            : "=o"(*(__uint16_va_t*)(base+offset))
     151            : "r"(val), "r"(base), "b"(offset)
     152    );
     153}
     154
     155static inline uint32_t __in_le32(uint8_t *base, uint32_t offset)
     156{
     157uint32_t     rval;
     158    __asm__ __volatile__(
     159        "lwbrx %0,%2,%1; eieio\n"
     160            : "=r" (rval)
     161            : "r"(base), "b"(offset), "m"(*(__uint32_va_t*)(base + offset))
     162    );
     163    return rval;
     164}
     165
     166static inline __out_le32(uint8_t *base, uint32_t offset, uint32_t val)
     167{
     168    __asm__ __volatile__(
     169        "stwbrx %1,%3,%2; eieio"
     170            : "=o"(*(__uint32_va_t*)(base+offset))
     171            : "r"(val), "r"(base), "b"(offset)
     172    );
     173}
     174
     175#ifdef _IO_BASE
     176static inline void __outport_dword(unsigned long base, uint32_t off, uint32_t val)
     177{
     178        __out_le32((uint8_t*)(_IO_BASE+base), off, 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>
     186
     187static inline uint16_t __in_le16(uint8_t *base, uint32_t offset)
     188{
     189        return *(__uint16_va_t*)(base + offset);
     190}
     191
     192static inline void __out_le16(uint8_t *base, uint32_t offset, uint16_t val)
     193{
     194        *(__uint16_va_t*)(base + offset) = val;
     195}
     196
     197static inline uint32_t __in_le32(uint8_t *base, uint32_t offset)
     198{
     199        return *(__uint32_va_t*)(base + offset);
     200}
     201
     202static inline void __out_le32(uint8_t *base, uint32_t offset, uint32_t val)
     203{
     204        *(__uint32_va_t*)(base + offset) = val;
     205}
     206
     207static inline void __outport_dword(unsigned long base, uint32_t off, uint32_t val)
     208{
     209        i386_outport_long( (base + off), val );
     210}
     211
     212#else
     213#warning "not ported to this CPU architecture yet -- using libbsdport I/O"
     214#define  USE_LIBBSDPORT_IO
     215#endif
     216
     217#ifdef USE_LIBBSDPORT_IO
    240218
    241219#define USE_EXPLICIT_BUSTAGS
     
    394372#endif /* USE_EXPLICIT_BUSTAGS */
    395373
     374#else /* USE_LIBBSDPORT_IO */
     375
     376/* Read from an absolute offset in the adapter's memory space */
     377#define E1000_READ_OFFSET(hw, offset) \
     378        __in_le32((hw)->hw_addr, offset)
     379
     380/* Write to an absolute offset in the adapter's memory space */
     381#define E1000_WRITE_OFFSET(hw, offset, value) \
     382        __out_le32((hw)->hw_addr, offset, value)
     383
     384/* Register READ/WRITE macros */
     385
     386#define E1000_READ_REG(hw, reg) \
     387        __in_le32((hw)->hw_addr, E1000_REGISTER(hw, reg))
     388
     389#define E1000_WRITE_REG(hw, reg, value) \
     390        __out_le32((hw)->hw_addr, E1000_REGISTER(hw, reg), value)
     391
     392#define E1000_READ_REG_ARRAY(hw, reg, index) \
     393        __in_le32((hw)->hw_addr, E1000_REGISTER(hw, reg) + ((index)<< 2))
     394
     395#define E1000_WRITE_REG_ARRAY(hw, reg, index, value) \
     396        __out_le32((hw)->hw_addr, E1000_REGISTER(hw, reg) + ((index)<< 2), value)
     397
     398#define E1000_READ_REG_ARRAY_DWORD E1000_READ_REG_ARRAY
     399#define E1000_WRITE_REG_ARRAY_DWORD E1000_WRITE_REG_ARRAY
     400
     401#define E1000_WRITE_REG_IO(hw, reg, value) do { \
     402        __outport_dword((hw)->io_base, 0, reg);     \
     403        __outport_dword((hw)->io_base, 4, value);   \
     404        } while (0)
     405
     406#define E1000_READ_FLASH_REG(hw, reg) \
     407        __in_le32( (hw)->flash_address, reg )
     408
     409#define E1000_READ_FLASH_REG16(hw, reg) \
     410        __in_le16( (hw)->flash_address, reg )
     411
     412#define E1000_WRITE_FLASH_REG(hw, reg, value) \
     413        __out_le32( (hw)->flash_address, reg, value )
     414
     415#define E1000_WRITE_FLASH_REG16(hw, reg, value) \
     416        __out_le16( (hw)->flash_address, reg, value )
     417
     418#endif /* USE_LIBBSDPORT_IO */
     419
     420
    396421#endif  /* _FREEBSD_OS_H_ */
    397422
  • bsd_eth_drivers/if_em/if_em.c

    rc47c1f8 r370f3c5  
    26622662        adapter->osdep.mem_bus_space_handle =
    26632663            rman_get_bushandle(adapter->res_memory);
     2664#ifndef __rtems__
    26642665        adapter->hw.hw_addr = (uint8_t*)&adapter->osdep.mem_bus_space_handle;
     2666#else
     2667        adapter->hw.hw_addr = (uint8_t*)adapter->res_memory;
     2668#endif
    26652669
    26662670        /* Only older adapters use IO mapping */
     
    26902694                        return (ENXIO);
    26912695                }
     2696#ifndef __rtems__
    26922697                adapter->hw.io_base = 0;
     2698#else
     2699                adapter->hw.io_base =   (unsigned long)adapter->res_ioport
     2700                              & PCI_BASE_ADDRESS_IO_MASK;
     2701#endif
    26932702                adapter->osdep.io_bus_space_tag =
    26942703                    rman_get_bustag(adapter->res_ioport);
     
    32803289        E1000_WRITE_REG(&adapter->hw, E1000_TDH, 0);
    32813290
     3291#ifndef __rtems__
    32823292        HW_DEBUGOUT2("Base = %x, Length = %x\n",
    32833293            E1000_READ_REG(&adapter->hw, E1000_TDBAL),
    32843294            E1000_READ_REG(&adapter->hw, E1000_TDLEN));
     3295#else
     3296        HW_DEBUGOUT2("Base = %x, Length = %x\n",
     3297            (unsigned)E1000_READ_REG(&adapter->hw, E1000_TDBAL),
     3298            (unsigned)E1000_READ_REG(&adapter->hw, E1000_TDLEN));
     3299#endif
    32853300
    32863301        /* Set the default values for the Tx Inter Packet Gap timer */
Note: See TracChangeset for help on using the changeset viewer.