1 /************************************************************************** 2 3 Copyright (c) 2001-2003, Intel Corporation 4 All rights reserved. 5 6 Redistribution and use in source and binary forms, with or without 7 modification, 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 20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 POSSIBILITY OF SUCH DAMAGE. 31 32 ***************************************************************************/ 33 34 /*$FreeBSD: if_em_osdep.h,v 1.11 2003/05/02 21:17:08 pdeuskar Exp $*/ 35 /* $OpenBSD: if_em_osdep.h,v 1.3 2004/04/18 04:15:01 henric Exp $ */ 36 37 #ifndef _EM_OPENBSD_OS_H_ 38 #define _EM_OPENBSD_OS_H_ 39 40 #define ASSERT(x) if(!(x)) panic("EM: x") 41 42 /* The happy-fun DELAY macro is defined in /usr/src/sys/i386/include/clock.h */ 43 #define usec_delay(x) DELAY(x) 44 #define msec_delay(x) DELAY(1000*(x)) 45 46 #define MSGOUT(S, A, B) printf(S "\n", A, B) 47 #define DEBUGFUNC(F) DEBUGOUT(F); 48 #if DBG 49 #define DEBUGOUT(S) printf(S "\n") 50 #define DEBUGOUT1(S,A) printf(S "\n",A) 51 #define DEBUGOUT2(S,A,B) printf(S "\n",A,B) 52 #define DEBUGOUT3(S,A,B,C) printf(S "\n",A,B,C) 53 #define DEBUGOUT7(S,A,B,C,D,E,F,G) printf(S "\n",A,B,C,D,E,F,G) 54 #else 55 #define DEBUGOUT(S) 56 #define DEBUGOUT1(S,A) 57 #define DEBUGOUT2(S,A,B) 58 #define DEBUGOUT3(S,A,B,C) 59 #define DEBUGOUT7(S,A,B,C,D,E,F,G) 60 #endif 61 62 #define FALSE 0 63 #define TRUE 1 64 #define CMD_MEM_WRT_INVALIDATE 0x0010 /* BIT_4 */ 65 #define PCI_COMMAND_REGISTER PCI_COMMAND_STATUS_REG 66 67 struct em_osdep 68 { 69 bus_space_tag_t mem_bus_space_tag; 70 bus_space_handle_t mem_bus_space_handle; 71 struct device *dev; 72 73 struct pci_attach_args em_pa; 74 75 bus_size_t em_memsize; 76 bus_addr_t em_membase; 77 78 bus_space_handle_t em_iobhandle; 79 bus_space_tag_t em_iobtag; 80 bus_size_t em_iosize; 81 bus_addr_t em_iobase; 82 }; 83 84 #define E1000_WRITE_FLUSH(a) E1000_READ_REG(a, STATUS) 85 86 #define E1000_READ_REG(a, reg) \ 87 bus_space_read_4( ((struct em_osdep *)(a)->back)->mem_bus_space_tag, \ 88 ((struct em_osdep *)(a)->back)->mem_bus_space_handle, \ 89 ((a)->mac_type >= em_82543) ? E1000_##reg : E1000_82542_##reg) 90 91 #define E1000_WRITE_REG(a, reg, value) \ 92 bus_space_write_4( ((struct em_osdep *)(a)->back)->mem_bus_space_tag, \ 93 ((struct em_osdep *)(a)->back)->mem_bus_space_handle, \ 94 ((a)->mac_type >= em_82543) ? E1000_##reg : E1000_82542_##reg, \ 95 value) 96 97 #define E1000_READ_REG_ARRAY(a, reg, offset) \ 98 bus_space_read_4( ((struct em_osdep *)(a)->back)->mem_bus_space_tag, \ 99 ((struct em_osdep *)(a)->back)->mem_bus_space_handle, \ 100 ((a)->mac_type >= em_82543) ? \ 101 (E1000_##reg + ((offset) << 2)) : \ 102 (E1000_82542_##reg + ((offset) << 2)) ) 103 104 #define E1000_WRITE_REG_ARRAY(a, reg, offset, value) \ 105 bus_space_write_4( ((struct em_osdep *)(a)->back)->mem_bus_space_tag, \ 106 ((struct em_osdep *)(a)->back)->mem_bus_space_handle, \ 107 ((a)->mac_type >= em_82543) ? \ 108 (E1000_##reg + ((offset) << 2)) : \ 109 (E1000_82542_##reg + ((offset) << 2)), \ 110 value) 111 112 #define em_io_read(hw, port) \ 113 bus_space_read_4(((struct em_osdep *)(hw)->back)->em_iobtag, \ 114 ((struct em_osdep *)(hw)->back)->em_iobhandle, (port)) 115 116 #define em_io_write(hw, port, value) \ 117 bus_space_write_4(((struct em_osdep *)(hw)->back)->em_iobtag, \ 118 ((struct em_osdep *)(hw)->back)->em_iobhandle, \ 119 (port), (value)) 120 121 #ifdef DEBUG 122 #define EM_KASSERT(exp,msg) do { if (!(exp)) panic msg; } while (0) 123 #else 124 #define EM_KASSERT(exp,msg) 125 #endif 126 #define bus_dma_tag_destroy(tag) 127 #define mtx_assert(a, b) splassert(IPL_NET) 128 129 #endif /* _EM_OPENBSD_OS_H_ */ 130 131