--- tme/generic/bus-device.c 2018/04/24 16:37:52 1.1 +++ tme/generic/bus-device.c 2018/04/24 16:42:57 1.1.1.5 @@ -1,6 +1,6 @@ -/* $Id: bus-device.c,v 1.1 2018/04/24 16:37:52 root Exp $ */ +/* $Id: bus-device.c,v 1.1.1.5 2018/04/24 16:42:57 root Exp $ */ -/* bus/bus-device.c - implementation of a generic bus device support: */ +/* generic/bus-device.c - implementation of a generic bus device support: */ /* * Copyright (c) 2003 Matt Fredette @@ -34,11 +34,57 @@ */ #include -_TME_RCSID("$Id: bus-device.c,v 1.1 2018/04/24 16:37:52 root Exp $"); +_TME_RCSID("$Id: bus-device.c,v 1.1.1.5 2018/04/24 16:42:57 root Exp $"); /* includes: */ #include +/* include the automatically-generated bus-device functions: */ +#include "bus-device-auto.c" + +/* this adds a generic bus TLB set: */ +int +tme_bus_device_tlb_set_add(struct tme_bus_device *bus_device, + unsigned long tlb_count, + struct tme_bus_tlb *tlb) +{ + struct tme_bus_tlb_set_info tlb_set_info; + struct tme_token *token; + struct tme_bus_connection *conn_bus; + int rc; + + /* make the TLB set information, and allocate a token for each TLB + entry: */ + assert (tlb_count > 0); + memset(&tlb_set_info, 0, sizeof(tlb_set_info)); + tlb_set_info.tme_bus_tlb_set_info_token0 = tme_new(struct tme_token, tlb_count); + tlb_set_info.tme_bus_tlb_set_info_token_stride = sizeof(struct tme_token); + tlb_set_info.tme_bus_tlb_set_info_token_count = tlb_count; + tlb_set_info.tme_bus_tlb_set_info_bus_context = NULL; + + /* connect each TLB entry with its token: */ + token = tlb_set_info.tme_bus_tlb_set_info_token0; + do { + tme_token_init(token); + tlb->tme_bus_tlb_token = token; + tlb++; + token++; + } while (--tlb_count); + + /* get our bus connection: */ + conn_bus + = tme_memory_atomic_pointer_read(struct tme_bus_connection *, + bus_device->tme_bus_device_connection, + &bus_device->tme_bus_device_connection_rwlock); + + /* add the TLB set: */ + rc + = ((*conn_bus->tme_bus_tlb_set_add) + (conn_bus, + &tlb_set_info)); + return (rc); +} + /* this scores a connection: */ int tme_bus_device_connection_score(struct tme_connection *conn, unsigned int *_score) @@ -57,8 +103,10 @@ tme_bus_device_connection_score(struct t /* a simple bus device can have multiple connections, but they all must be from the same bus. the only way we check that is by comparing elements: */ - conn_bus_other_old = TME_ATOMIC_READ(struct tme_bus_connection *, - device->tme_bus_device_connection); + conn_bus_other_old + = tme_memory_atomic_pointer_read(struct tme_bus_connection *, + device->tme_bus_device_connection, + &device->tme_bus_device_connection_rwlock); conn_bus_other_new = (struct tme_bus_connection *) conn->tme_connection_other; if (conn_bus_other_old != NULL && (conn_bus_other_old->tme_bus_connection.tme_connection_element @@ -95,9 +143,10 @@ tme_bus_device_connection_make(struct tm if (state == TME_CONNECTION_FULL) { /* save our connection: */ - TME_ATOMIC_WRITE(struct tme_bus_connection *, - device->tme_bus_device_connection, - (struct tme_bus_connection *) conn->tme_connection_other); + tme_memory_atomic_pointer_write(struct tme_bus_connection *, + device->tme_bus_device_connection, + (struct tme_bus_connection *) conn->tme_connection_other, + &device->tme_bus_device_connection_rwlock); } return (TME_OK); @@ -161,7 +210,7 @@ tme_bus_device_connections_new(struct tm conn->tme_connection_break = tme_bus_device_connection_break; /* fill in the generic bus connection: */ - conn_bus->tme_bus_address_last = device->tme_bus_device_address_last; + conn_bus->tme_bus_subregions = device->tme_bus_device_subregions; if (device->tme_bus_device_signal != NULL) { conn_bus->tme_bus_signal = _tme_bus_device_signal; }