--- tme/bus/multibus/sun-sc.c 2018/04/24 16:40:04 1.1.1.2 +++ tme/bus/multibus/sun-sc.c 2018/04/24 16:43:16 1.1.1.4 @@ -1,4 +1,4 @@ -/* $Id: sun-sc.c,v 1.1.1.2 2018/04/24 16:40:04 root Exp $ */ +/* $Id: sun-sc.c,v 1.1.1.4 2018/04/24 16:43:16 root Exp $ */ /* bus/multibus/sun-sc.c - implementation of Sun `sc' SCSI Multibus board emulation: */ @@ -34,7 +34,7 @@ */ #include -_TME_RCSID("$Id: sun-sc.c,v 1.1.1.2 2018/04/24 16:40:04 root Exp $"); +_TME_RCSID("$Id: sun-sc.c,v 1.1.1.4 2018/04/24 16:43:16 root Exp $"); /* includes: */ #include @@ -166,7 +166,8 @@ struct tme_sun_sc { int tme_sun_sc_cycle_tail; /* our DMA TLB set: */ - TME_ATOMIC(struct tme_bus_tlb *, tme_sun_sc_dma_tlb); + struct tme_bus_tlb tme_sun_sc_dma_tlb; + int tme_sun_sc_dma_tlb_added; /* the internal DMA buffer: */ tme_uint8_t tme_sun_sc_int_dma[2]; @@ -339,7 +340,7 @@ static int _tme_sun_sc_bus_cycle_dma(struct tme_sun_sc *sun_sc, struct tme_bus_tlb *tlb, tme_uint8_t cycle_type, - tme_bus_addr_t address, + tme_bus_addr32_t address, int word_mode) { struct tme_bus_cycle cycle_init; @@ -406,10 +407,10 @@ _tme_sun_sc_callout(struct tme_sun_sc *s int old_tail; struct tme_sun_sc_cycle *sun_sc_cycle; int callouts, later_callouts; - tme_bus_addr_t address; + tme_bus_addr32_t address; tme_uint16_t resid; tme_uint8_t cycle_type; - tme_bus_addr_t avail; + tme_bus_addr32_t avail; tme_uint8_t *emulator_off; tme_uint16_t icr; int rc; @@ -446,8 +447,9 @@ _tme_sun_sc_callout(struct tme_sun_sc *s /* get this card's bus and SCSI connections: */ conn_scsi = sun_sc->tme_sun_sc_scsi_connection; - conn_bus = TME_ATOMIC_READ(struct tme_bus_connection *, - sun_sc->tme_sun_sc_device.tme_bus_device_connection); + conn_bus = tme_memory_atomic_pointer_read(struct tme_bus_connection *, + sun_sc->tme_sun_sc_device.tme_bus_device_connection, + &sun_sc->tme_sun_sc_device.tme_bus_device_connection_rwlock); /* if we need to call out a SCSI bus cycle: */ if (callouts & TME_SUN_SC_CALLOUT_CYCLE) { @@ -549,13 +551,10 @@ _tme_sun_sc_callout(struct tme_sun_sc *s : sizeof(tme_uint8_t))); /* get the TLB entry: */ - tlb - = TME_ATOMIC_READ(struct tme_bus_tlb *, - sun_sc->tme_sun_sc_dma_tlb); + tlb = &sun_sc->tme_sun_sc_dma_tlb; - /* reserve this TLB entry: */ - tme_bus_tlb_reserve(tlb, &tlb_local); - tlb = &tlb_local; + /* pass this TLB's token: */ + tlb_local.tme_bus_tlb_token = tlb->tme_bus_tlb_token; /* unlock the mutex: */ tme_mutex_unlock(&sun_sc->tme_sun_sc_mutex); @@ -564,7 +563,7 @@ _tme_sun_sc_callout(struct tme_sun_sc *s rc = (conn_bus != NULL ? ((*conn_bus->tme_bus_tlb_fill) (conn_bus, - tlb, + &tlb_local, address, cycle_type)) : TME_OK); @@ -583,12 +582,11 @@ _tme_sun_sc_callout(struct tme_sun_sc *s else { /* store the TLB entry: */ - tme_bus_tlb_back(tlb); + *tlb = tlb_local; /* get the number of bytes available in this TLB entry: */ avail - = ((TME_ATOMIC_READ(tme_bus_addr_t, - tlb->tme_bus_tlb_addr_last) + = ((tlb->tme_bus_tlb_addr_last - address) + 1); if (avail == 0 @@ -611,8 +609,9 @@ _tme_sun_sc_callout(struct tme_sun_sc *s emulator_off = ((cycle_type == TME_BUS_CYCLE_READ) + /* XXX FIXME - this breaks volatile: */ ? (tme_uint8_t *) tlb->tme_bus_tlb_emulator_off_read - : tlb->tme_bus_tlb_emulator_off_write); + : (tme_uint8_t *) tlb->tme_bus_tlb_emulator_off_write); if (emulator_off != TME_EMULATOR_OFF_UNDEF) { @@ -1145,14 +1144,19 @@ _tme_sun_sc_bus_cycle_other(void *_sun_s static int _tme_sun_sc_tlb_fill(void *_sun_sc, struct tme_bus_tlb *tlb, - tme_bus_addr_t address, + tme_bus_addr_t address_wider, unsigned int cycles) { struct tme_sun_sc *sun_sc; + tme_bus_addr32_t address; /* recover our data structure: */ sun_sc = (struct tme_sun_sc *) _sun_sc; + /* get the normal-width address: */ + address = address_wider; + assert (address == address_wider); + /* the address must be within range: */ assert(address < TME_SUN_SC_SIZ_CARD); @@ -1170,14 +1174,8 @@ do { \ + (siz)))) { \ \ /* this TLB entry covers this register: */ \ - TME_ATOMIC_WRITE(tme_bus_addr_t, \ - tlb->tme_bus_tlb_addr_first,\ - (reg)); \ - TME_ATOMIC_WRITE(tme_bus_addr_t, \ - tlb->tme_bus_tlb_addr_last,\ - ((reg) \ - + (siz) \ - - 1)); \ + tlb->tme_bus_tlb_addr_first = (reg); \ + tlb->tme_bus_tlb_addr_last = (reg) + (siz) - 1;\ \ /* our bus cycle handler: */ \ tlb->tme_bus_tlb_cycle = (handler); \ @@ -1213,21 +1211,12 @@ do { \ if (address >= (TME_SUN_SC_REG_ICR + TME_SUN_SC_SIZ_ICR)) { - TME_ATOMIC_WRITE(tme_bus_addr_t, - tlb->tme_bus_tlb_addr_first, - (TME_SUN_SC_REG_ICR - + TME_SUN_SC_SIZ_ICR)); - TME_ATOMIC_WRITE(tme_bus_addr_t, - tlb->tme_bus_tlb_addr_last, - TME_SUN_SC_SIZ_CARD - 1); + tlb->tme_bus_tlb_addr_first = TME_SUN_SC_REG_ICR + TME_SUN_SC_SIZ_ICR; + tlb->tme_bus_tlb_addr_last = TME_SUN_SC_SIZ_CARD - 1; } else { - TME_ATOMIC_WRITE(tme_bus_addr_t, - tlb->tme_bus_tlb_addr_first, - address); - TME_ATOMIC_WRITE(tme_bus_addr_t, - tlb->tme_bus_tlb_addr_last, - address); + tlb->tme_bus_tlb_addr_first = address; + tlb->tme_bus_tlb_addr_last = address; } /* this TLB entry allows fast reading and writing: */ @@ -1362,9 +1351,7 @@ do { \ - sun_sc_cycle->tme_sun_sc_cycle_dma.tme_scsi_dma_out)); /* get the TLB entry: */ - tlb - = TME_ATOMIC_READ(struct tme_bus_tlb *, - sun_sc->tme_sun_sc_dma_tlb); + tlb = &sun_sc->tme_sun_sc_dma_tlb; /* get the DMA address: */ address @@ -1492,21 +1479,19 @@ _tme_sun_sc_connection_make_bus(struct t set yet, allocate it: */ if (rc == TME_OK && state == TME_CONNECTION_FULL - && TME_ATOMIC_READ(struct tme_bus_tlb *, - sun_sc->tme_sun_sc_dma_tlb) == NULL) { + && !sun_sc->tme_sun_sc_dma_tlb_added) { /* get our bus connection: */ - conn_bus - = TME_ATOMIC_READ(struct tme_bus_connection *, - sun_sc->tme_sun_sc_device.tme_bus_device_connection); + conn_bus = tme_memory_atomic_pointer_read(struct tme_bus_connection *, + sun_sc->tme_sun_sc_device.tme_bus_device_connection, + &sun_sc->tme_sun_sc_device.tme_bus_device_connection_rwlock); /* allocate the TLB set: */ - rc = ((*conn_bus->tme_bus_tlb_set_allocate) - (conn_bus, - 1, - sizeof(struct tme_bus_tlb), - TME_ATOMIC_POINTER(&sun_sc->tme_sun_sc_dma_tlb))); + rc = tme_bus_device_tlb_set_add(&sun_sc->tme_sun_sc_device, + 1, + &sun_sc->tme_sun_sc_dma_tlb); assert (rc == TME_OK); + sun_sc->tme_sun_sc_dma_tlb_added = TRUE; } return (rc);