1 /* $Id: bus-device.h,v 1.9 2009/08/29 17:48:27 fredette Exp $ */ 2 3 /* tme/generic/bus-device.h - header file for generic bus device support: */ 4 5 /* 6 * Copyright (c) 2003 Matt Fredette 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by Matt Fredette. 20 * 4. The name of the author may not be used to endorse or promote products 21 * derived from this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, 27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 * POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 #ifndef _TME_GENERIC_BUS_DEVICE_H 37 #define _TME_GENERIC_BUS_DEVICE_H 38 39 #include <tme/common.h> 40 _TME_RCSID("$Id: bus-device.h,v 1.9 2009/08/29 17:48:27 fredette Exp $"); 41 42 /* includes: */ 43 #include <tme/element.h> 44 #include <tme/generic/bus.h> 45 46 /* macros: */ 47 48 /* this indexes an initiator bus router array for a device with a port size 49 of 8 * (2 ^ siz_lg2) bits: */ 50 #define TME_BUS_ROUTER_INIT_INDEX(siz_lg2, cycle_size, address) \ 51 ((( \ 52 /* by the maximum cycle size: */ \ 53 ((cycle_size) - 1) \ 54 \ 55 /* by the address alignment: */ \ 56 << siz_lg2) \ 57 + ((address) & ((1 << (siz_lg2)) - 1))) \ 58 \ 59 /* factor in the size of the generic bus router array: */ \ 60 * TME_BUS_ROUTER_SIZE(siz_lg2)) 61 62 /* structures: */ 63 64 /* a bus device: */ 65 struct tme_bus_device { 66 67 /* backpointer to the device's element: */ 68 struct tme_element *tme_bus_device_element; 69 70 /* this device's bus connection: */ 71 struct tme_bus_connection * tme_shared tme_bus_device_connection; 72 tme_rwlock_t tme_bus_device_connection_rwlock; 73 74 /* the subregions for this device. for some backwards compatibility 75 for older sources, we define tme_bus_device_address_last: */ 76 struct tme_bus_subregion tme_bus_device_subregions; 77 #define tme_bus_device_address_last tme_bus_device_subregions.tme_bus_subregion_address_last 78 79 /* the bus signal handler: */ 80 int (*tme_bus_device_signal) _TME_P((void *, unsigned int)); 81 82 /* the bus interrupt acknowledge handler: */ 83 int (*tme_bus_device_intack) _TME_P((void *, unsigned int, int *)); 84 85 /* the bus TLB entry filler: */ 86 int (*tme_bus_device_tlb_fill) _TME_P((void *, struct tme_bus_tlb *, tme_bus_addr_t, unsigned int)); 87 88 /* the device lock and unlock functions: */ 89 void (*tme_bus_device_lock) _TME_P((void *, unsigned int)); 90 void (*tme_bus_device_unlock) _TME_P((void *, unsigned int)); 91 92 /* the bus master TLB entry hasher: */ 93 struct tme_bus_tlb *(*tme_bus_device_tlb_hash) _TME_P((void *, tme_bus_addr_t, unsigned int)); 94 95 /* the bus master bus router: */ 96 _tme_const tme_bus_lane_t *tme_bus_device_router; 97 }; 98 99 /* globals: */ 100 101 /* the 16-bit big-endian bus master bus router: */ 102 extern _tme_const tme_bus_lane_t tme_bus_device_router_16eb[]; 103 104 /* the 16-bit little-endian bus master bus router: */ 105 extern _tme_const tme_bus_lane_t tme_bus_device_router_16el[]; 106 107 /* the 32-bit big-endian bus master bus router: */ 108 extern _tme_const tme_bus_lane_t tme_bus_device_router_32eb[]; 109 110 /* the 32-bit little-endian bus master bus router: */ 111 extern _tme_const tme_bus_lane_t tme_bus_device_router_32el[]; 112 113 /* prototypes: */ 114 int tme_bus_device_connection_score _TME_P((struct tme_connection *, unsigned int *)); 115 int tme_bus_device_connection_make _TME_P((struct tme_connection *, unsigned int)); 116 int tme_bus_device_connection_break _TME_P((struct tme_connection *, unsigned int)); 117 int tme_bus_device_connections_new _TME_P((struct tme_element *, _tme_const char * _tme_const *, struct tme_connection **, char **)); 118 119 /* this adds a bus device generic TLB set: */ 120 int tme_bus_device_tlb_set_add _TME_P((struct tme_bus_device *, 121 unsigned long, 122 struct tme_bus_tlb *)); 123 124 /* the 16-bit bus master DMA read function: */ 125 int tme_bus_device_dma_read_16 _TME_P((struct tme_bus_device *, 126 tme_bus_addr_t, 127 tme_bus_addr_t, 128 tme_uint8_t *, 129 unsigned int)); 130 131 /* the 16-bit bus master DMA write function: */ 132 int tme_bus_device_dma_write_16 _TME_P((struct tme_bus_device *, 133 tme_bus_addr_t, 134 tme_bus_addr_t, 135 _tme_const tme_uint8_t *, 136 unsigned int)); 137 138 /* the 32-bit bus master DMA read function: */ 139 int tme_bus_device_dma_read_32 _TME_P((struct tme_bus_device *, 140 tme_bus_addr_t, 141 tme_bus_addr_t, 142 tme_uint8_t *, 143 unsigned int)); 144 145 /* the 32-bit bus master DMA write function: */ 146 int tme_bus_device_dma_write_32 _TME_P((struct tme_bus_device *, 147 tme_bus_addr_t, 148 tme_bus_addr_t, 149 _tme_const tme_uint8_t *, 150 unsigned int)); 151 152 #endif /* !_TME_GENERIC_BUS_DEVICE_H */ 153