|
|
1.1.1.3 ! root 1: /* $Id: bus-device.c,v 1.8 2004/04/30 12:11:35 fredette Exp $ */ 1.1 root 2: 1.1.1.2 root 3: /* generic/bus-device.c - implementation of a generic bus device support: */ 1.1 root 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: #include <tme/common.h> 1.1.1.3 ! root 37: _TME_RCSID("$Id: bus-device.c,v 1.8 2004/04/30 12:11:35 fredette Exp $"); 1.1 root 38: 39: /* includes: */ 40: #include <tme/generic/bus-device.h> 41: 1.1.1.3 ! root 42: /* include the automatically-generated bus-device functions: */ ! 43: #include "bus-device-auto.c" ! 44: 1.1 root 45: /* this scores a connection: */ 46: int 47: tme_bus_device_connection_score(struct tme_connection *conn, unsigned int *_score) 48: { 49: struct tme_bus_device *device; 50: struct tme_bus_connection *conn_bus_other_old; 51: struct tme_bus_connection *conn_bus_other_new; 52: 53: /* recover our device: */ 54: device = conn->tme_connection_element->tme_element_private; 55: 56: /* both sides must be generic bus connections: */ 57: assert(conn->tme_connection_type == TME_CONNECTION_BUS_GENERIC); 58: assert(conn->tme_connection_other->tme_connection_type == TME_CONNECTION_BUS_GENERIC); 59: 60: /* a simple bus device can have multiple connections, but they all 61: must be from the same bus. the only way we check that is by 62: comparing elements: */ 63: conn_bus_other_old = TME_ATOMIC_READ(struct tme_bus_connection *, 64: device->tme_bus_device_connection); 65: conn_bus_other_new = (struct tme_bus_connection *) conn->tme_connection_other; 66: if (conn_bus_other_old != NULL 67: && (conn_bus_other_old->tme_bus_connection.tme_connection_element 68: != conn_bus_other_new->tme_bus_connection.tme_connection_element)) { 69: *_score = 0; 70: return (TME_OK); 71: } 72: 73: /* otherwise, this is our first connection or another connection to 74: the same element. note that there's no good way to differentiate 75: a connection to a bus from a connection to just another chip, so 76: we always return a nonzero score here: */ 77: *_score = 1; 78: return (TME_OK); 79: } 80: 81: /* this makes a new connection: */ 82: int 83: tme_bus_device_connection_make(struct tme_connection *conn, unsigned int state) 84: { 85: struct tme_bus_device *device; 86: 87: /* recover our device: */ 88: device = conn->tme_connection_element->tme_element_private; 89: 90: /* both sides must be generic bus connections: */ 91: assert(conn->tme_connection_type == TME_CONNECTION_BUS_GENERIC); 92: assert(conn->tme_connection_other->tme_connection_type == TME_CONNECTION_BUS_GENERIC); 93: 94: /* simple bus devices are always set up to answer calls across the 95: connection, so we only have to do work when the connection 96: has gone full, namely taking the other side of the 97: connection: */ 98: if (state == TME_CONNECTION_FULL) { 99: 100: /* save our connection: */ 101: TME_ATOMIC_WRITE(struct tme_bus_connection *, 102: device->tme_bus_device_connection, 103: (struct tme_bus_connection *) conn->tme_connection_other); 104: } 105: 106: return (TME_OK); 107: } 108: 109: /* this breaks a connection: */ 110: int 111: tme_bus_device_connection_break(struct tme_connection *conn, unsigned int state) 112: { 113: abort(); 114: } 115: 116: static int 117: _tme_bus_device_signal(struct tme_bus_connection *conn_bus, unsigned int signal) 118: { 119: struct tme_bus_device *device; 120: device = conn_bus->tme_bus_connection.tme_connection_element->tme_element_private; 121: return ((*device->tme_bus_device_signal)(device, signal)); 122: } 123: 124: static int 125: _tme_bus_device_intack(struct tme_bus_connection *conn_bus, unsigned int signal, int *vector) 126: { 127: struct tme_bus_device *device; 128: device = conn_bus->tme_bus_connection.tme_connection_element->tme_element_private; 129: return ((*device->tme_bus_device_intack)(device, signal, vector)); 130: } 131: 132: static int 133: _tme_bus_device_tlb_fill(struct tme_bus_connection *conn_bus, struct tme_bus_tlb *tlb, 134: tme_bus_addr_t address, unsigned int cycles) 135: { 136: struct tme_bus_device *device; 137: device = conn_bus->tme_bus_connection.tme_connection_element->tme_element_private; 138: return ((*device->tme_bus_device_tlb_fill)(device, tlb, address, cycles)); 139: } 140: 141: /* this makes a new connection side for a simple bus device: */ 142: int 143: tme_bus_device_connections_new(struct tme_element *element, 144: const char * const *args, 145: struct tme_connection **_conns, 146: char **_output) 147: { 148: struct tme_bus_device *device; 149: struct tme_bus_connection *conn_bus; 150: struct tme_connection *conn; 151: 152: /* recover our device: */ 153: device = (struct tme_bus_device *) element->tme_element_private; 154: 155: /* create our side of a generic bus connection: */ 156: conn_bus = tme_new0(struct tme_bus_connection, 1); 157: conn = &conn_bus->tme_bus_connection; 158: 159: /* fill in the generic connection: */ 160: conn->tme_connection_next = *_conns; 161: conn->tme_connection_type = TME_CONNECTION_BUS_GENERIC; 162: conn->tme_connection_score = tme_bus_device_connection_score; 163: conn->tme_connection_make = tme_bus_device_connection_make; 164: conn->tme_connection_break = tme_bus_device_connection_break; 165: 166: /* fill in the generic bus connection: */ 1.1.1.2 root 167: conn_bus->tme_bus_subregions = device->tme_bus_device_subregions; 1.1 root 168: if (device->tme_bus_device_signal != NULL) { 169: conn_bus->tme_bus_signal = _tme_bus_device_signal; 170: } 171: if (device->tme_bus_device_intack != NULL) { 172: conn_bus->tme_bus_intack = _tme_bus_device_intack; 173: } 174: conn_bus->tme_bus_tlb_fill = _tme_bus_device_tlb_fill; 175: 176: /* return the connection side possibility: */ 177: *_conns = conn; 178: return (TME_OK); 179: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.