ohci_sbus.c revision 1.4
1/* $NetBSD: ohci_sbus.c,v 1.4 2003/07/15 02:54:36 lukem Exp $ */ 2 3/*- 4 * Copyright (c) 2001 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <sys/cdefs.h> 40__KERNEL_RCSID(0, "$NetBSD: ohci_sbus.c,v 1.4 2003/07/15 02:54:36 lukem Exp $"); 41 42#include <sys/param.h> 43 44/* bus_dma */ 45#include <sys/mbuf.h> 46#include <uvm/uvm_extern.h> 47 48#define _PLAYSTATION2_BUS_DMA_PRIVATE 49#include <machine/bus.h> 50#include <machine/autoconf.h> 51 52#include <dev/usb/usb.h> 53#include <dev/usb/usbdi.h> 54#include <dev/usb/usbdivar.h> 55 56#include <dev/usb/ohcireg.h> 57#include <dev/usb/ohcivar.h> 58 59#include <playstation2/ee/sifvar.h> /* DMA staff */ 60#include <playstation2/ee/dmacvar.h> 61#include <playstation2/dev/sbusvar.h> 62 63#ifdef DEBUG 64#define STATIC 65#else 66#define STATIC static 67#endif 68 69#define SBUS_OHCI_REGBASE MIPS_PHYS_TO_KSEG1(0x1f801600) 70#define SBUS_OHCI_REGSIZE 0x1000 71 72STATIC int ohci_sbus_match(struct device *, struct cfdata *, void *); 73STATIC void ohci_sbus_attach(struct device *, struct device *, void *); 74 75STATIC void _ohci_sbus_map_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, 76 bus_size_t, int); 77STATIC int _ohci_sbus_mem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t, 78 bus_size_t, bus_dma_segment_t *, int, int *, int); 79STATIC void _ohci_sbus_mem_free(bus_dma_tag_t, bus_dma_segment_t *, int); 80STATIC int _ohci_sbus_mem_map(bus_dma_tag_t, bus_dma_segment_t *, int, size_t, 81 caddr_t *, int); 82STATIC void _ohci_sbus_mem_unmap(bus_dma_tag_t, caddr_t, size_t); 83 84struct playstation2_bus_dma_tag ohci_bus_dma_tag = { 85 _bus_dmamap_create, 86 _bus_dmamap_destroy, 87 _bus_dmamap_load, 88 _bus_dmamap_load_mbuf, 89 _bus_dmamap_load_uio, 90 _bus_dmamap_load_raw, 91 _bus_dmamap_unload, 92 _ohci_sbus_map_sync, 93 _ohci_sbus_mem_alloc, 94 _ohci_sbus_mem_free, 95 _ohci_sbus_mem_map, 96 _ohci_sbus_mem_unmap, 97 _bus_dmamem_mmap, 98}; 99 100struct ohci_dma_segment { 101 struct iopdma_segment ds_iopdma_seg; 102 103 LIST_ENTRY(ohci_dma_segment) ds_link; 104}; 105 106struct ohci_sbus_softc { 107 struct ohci_softc sc; 108 109 LIST_HEAD(, ohci_dma_segment) sc_dmaseg_head; 110}; 111 112CFATTACH_DECL(ohci_sbus, sizeof(struct ohci_sbus_softc), 113 ohci_sbus_match, ohci_sbus_attach, NULL, NULL); 114 115int 116ohci_sbus_match(struct device *parent, struct cfdata *cf, void *aux) 117{ 118 119 return (1); 120} 121 122void 123ohci_sbus_attach(struct device *parent, struct device *self, void *aux) 124{ 125 struct ohci_sbus_softc *sc = (void *)self; 126 usbd_status result; 127 128 printf("\n"); 129 130 sc->sc.iot = bus_space_create(0, "OHCI I/O space", SBUS_OHCI_REGBASE, 131 SBUS_OHCI_REGSIZE); 132 sc->sc.ioh = SBUS_OHCI_REGBASE; 133 134 ohci_bus_dma_tag._dmachip_cookie = sc; 135 sc->sc.sc_bus.dmatag = &ohci_bus_dma_tag; 136 137 /* Disable interrupts, so we don't can any spurious ones. */ 138 bus_space_write_4(sc->sc.iot, sc->sc.ioh, OHCI_INTERRUPT_DISABLE, 139 OHCI_ALL_INTRS); 140 141 sbus_intr_establish(SBUS_IRQ_USB, ohci_intr, sc); 142 143 /* IOP/EE DMA relay segment list */ 144 LIST_INIT(&sc->sc_dmaseg_head); 145 146 result = ohci_init(&sc->sc); 147 148 if (result != USBD_NORMAL_COMPLETION) { 149 printf(": init failed. error=%d\n", result); 150 return; 151 } 152 153 /* Attach usb device. */ 154 sc->sc.sc_child = config_found((void *)sc, &sc->sc.sc_bus, 155 usbctlprint); 156} 157 158void 159_ohci_sbus_map_sync(bus_dma_tag_t t, bus_dmamap_t map, bus_addr_t offset, 160 bus_size_t len, int ops) 161{ 162 163 dmac_sync_buffer(); /* XXX over flush */ 164} 165 166int 167_ohci_sbus_mem_alloc(bus_dma_tag_t t, bus_size_t size, bus_size_t alignment, 168 bus_size_t boundary, bus_dma_segment_t *segs, int nsegs, int *rsegs, 169 int flags) 170{ 171 struct ohci_sbus_softc *sc = t->_dmachip_cookie; 172 struct ohci_dma_segment *ds; 173 struct iopdma_segment *iopdma_seg; 174 int error; 175 176 KDASSERT(sc); 177 ds = malloc(sizeof(struct ohci_dma_segment), M_DEVBUF, M_NOWAIT); 178 if (ds == NULL) 179 return (1); 180 /* 181 * Allocate DMA Area (IOP DMA Area <-> SIF DMA <-> EE DMA Area) 182 */ 183 iopdma_seg = &ds->ds_iopdma_seg; 184 error = iopdma_allocate_buffer(iopdma_seg, size); 185 186 if (error) { 187 free(ds, M_DEVBUF); 188 return (1); 189 } 190 191 segs[0].ds_len = iopdma_seg->size; 192 segs[0].ds_addr = iopdma_seg->iop_paddr; 193 segs[0]._ds_vaddr = iopdma_seg->ee_vaddr; 194 195 LIST_INSERT_HEAD(&sc->sc_dmaseg_head, ds, ds_link); 196 197 *rsegs = 1; 198 199 return (0); 200} 201 202void 203_ohci_sbus_mem_free(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs) 204{ 205 struct ohci_sbus_softc *sc = t->_dmachip_cookie; 206 struct ohci_dma_segment *ds; 207 paddr_t addr = segs[0].ds_addr; 208 209 for (ds = LIST_FIRST(&sc->sc_dmaseg_head); ds != NULL; 210 ds = LIST_NEXT(ds, ds_link)) { 211 if (ds->ds_iopdma_seg.iop_paddr == addr) { 212 iopdma_free_buffer(&ds->ds_iopdma_seg); 213 214 LIST_REMOVE(ds, ds_link); 215 free(ds, M_DEVBUF); 216 return; 217 } 218 } 219 220 panic("_dmamem_free: can't find corresponding handle."); 221 /* NOTREACHED */ 222} 223 224int 225_ohci_sbus_mem_map(bus_dma_tag_t t, bus_dma_segment_t *segs, int nsegs, size_t size, 226 caddr_t *kvap, int flags) 227{ 228 struct ohci_sbus_softc *sc = t->_dmachip_cookie; 229 struct ohci_dma_segment *ds; 230 paddr_t addr = segs[0].ds_addr; 231 232 for (ds = LIST_FIRST(&sc->sc_dmaseg_head); ds != NULL; 233 ds = LIST_NEXT(ds, ds_link)) { 234 if (ds->ds_iopdma_seg.iop_paddr == addr) { 235 236 *kvap = (caddr_t)ds->ds_iopdma_seg.ee_vaddr; 237 238 return (0); 239 } 240 } 241 242 return (1); 243} 244 245void 246_ohci_sbus_mem_unmap(bus_dma_tag_t t, caddr_t kva, size_t size) 247{ 248 /* nothing to do */ 249} 250