1 /* $NetBSD: sbus.c,v 1.83 2008/10/18 03:31:10 nakayama Exp $ */ 2 3 /* 4 * Copyright (c) 1999-2002 Eduardo Horvath 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of the author may not be used to endorse or promote products 16 * derived from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 */ 30 31 32 /* 33 * Sbus stuff. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: sbus.c,v 1.83 2008/10/18 03:31:10 nakayama Exp $"); 38 39 #include "opt_ddb.h" 40 41 #include <sys/param.h> 42 #include <sys/extent.h> 43 #include <sys/malloc.h> 44 #include <sys/systm.h> 45 #include <sys/device.h> 46 #include <sys/reboot.h> 47 48 #include <machine/bus.h> 49 #include <machine/openfirm.h> 50 51 #include <sparc64/dev/iommureg.h> 52 #include <sparc64/dev/iommuvar.h> 53 #include <sparc64/dev/sbusreg.h> 54 #include <dev/sbus/sbusvar.h> 55 56 #include <uvm/uvm_extern.h> 57 58 #include <machine/autoconf.h> 59 #include <machine/cpu.h> 60 #include <machine/sparc64.h> 61 62 #ifdef DEBUG 63 #define SDB_DVMA 0x1 64 #define SDB_INTR 0x2 65 int sbus_debug = 0; 66 #define DPRINTF(l, s) do { if (sbus_debug & l) printf s; } while (0) 67 #else 68 #define DPRINTF(l, s) 69 #endif 70 71 void sbusreset(int); 72 73 static bus_dma_tag_t sbus_alloc_dmatag(struct sbus_softc *); 74 static int sbus_get_intr(struct sbus_softc *, int, struct openprom_intr **, 75 int *, int); 76 static int sbus_overtemp(void *); 77 static int _sbus_bus_map( 78 bus_space_tag_t, 79 bus_addr_t, /*offset*/ 80 bus_size_t, /*size*/ 81 int, /*flags*/ 82 vaddr_t, /* XXX unused -- compat w/sparc */ 83 bus_space_handle_t *); 84 static void *sbus_intr_establish( 85 bus_space_tag_t, 86 int, /*`device class' priority*/ 87 int, /*Sbus interrupt level*/ 88 int (*)(void *), /*handler*/ 89 void *, /*handler arg*/ 90 void (*)(void)); /*optional fast trap*/ 91 92 93 /* autoconfiguration driver */ 94 int sbus_match(struct device *, struct cfdata *, void *); 95 void sbus_attach(struct device *, struct device *, void *); 96 97 98 CFATTACH_DECL(sbus, sizeof(struct sbus_softc), 99 sbus_match, sbus_attach, NULL, NULL); 100 101 extern struct cfdriver sbus_cd; 102 103 /* 104 * DVMA routines 105 */ 106 static int sbus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, 107 bus_size_t, int, bus_dmamap_t *); 108 109 /* 110 * Child devices receive the Sbus interrupt level in their attach 111 * arguments. We translate these to CPU IPLs using the following 112 * tables. Note: obio bus interrupt levels are identical to the 113 * processor IPL. 114 * 115 * The second set of tables is used when the Sbus interrupt level 116 * cannot be had from the PROM as an `interrupt' property. We then 117 * fall back on the `intr' property which contains the CPU IPL. 118 */ 119 120 /* 121 * This value is or'ed into the attach args' interrupt level cookie 122 * if the interrupt level comes from an `intr' property, i.e. it is 123 * not an Sbus interrupt level. 124 */ 125 #define SBUS_INTR_COMPAT 0x80000000 126 127 128 /* 129 * Print the location of some sbus-attached device (called just 130 * before attaching that device). If `sbus' is not NULL, the 131 * device was found but not configured; print the sbus as well. 132 * Return UNCONF (config_find ignores this if the device was configured). 133 */ 134 int 135 sbus_print(void *args, const char *busname) 136 { 137 struct sbus_attach_args *sa = args; 138 int i; 139 140 if (busname) 141 aprint_normal("%s at %s", sa->sa_name, busname); 142 aprint_normal(" slot %ld offset 0x%lx", (long)sa->sa_slot, 143 (u_long)sa->sa_offset); 144 for (i = 0; i < sa->sa_nintr; i++) { 145 struct openprom_intr *sbi = &sa->sa_intr[i]; 146 147 aprint_normal(" vector %lx ipl %ld", 148 (u_long)sbi->oi_vec, 149 (long)INTLEV(sbi->oi_pri)); 150 } 151 return (UNCONF); 152 } 153 154 int 155 sbus_match(struct device *parent, struct cfdata *cf, void *aux) 156 { 157 struct mainbus_attach_args *ma = aux; 158 159 return (strcmp(cf->cf_name, ma->ma_name) == 0); 160 } 161 162 /* 163 * Attach an Sbus. 164 */ 165 void 166 sbus_attach(struct device *parent, struct device *self, void *aux) 167 { 168 struct sbus_softc *sc = device_private(self); 169 struct mainbus_attach_args *ma = aux; 170 struct intrhand *ih; 171 int ipl; 172 char *name; 173 int node = ma->ma_node; 174 int node0, error; 175 bus_space_tag_t sbt; 176 struct sbus_attach_args sa; 177 178 sc->sc_bustag = ma->ma_bustag; 179 sc->sc_dmatag = ma->ma_dmatag; 180 sc->sc_ign = ma->ma_interrupts[0] & INTMAP_IGN; 181 182 /* XXXX Use sysio PROM mappings for interrupt vector regs. */ 183 sparc_promaddr_to_handle(sc->sc_bustag, ma->ma_address[0], &sc->sc_bh); 184 sc->sc_sysio = (struct sysioreg *)bus_space_vaddr(sc->sc_bustag, 185 sc->sc_bh); 186 187 #ifdef _LP64 188 /* 189 * 32-bit kernels use virtual addresses for bus space operations 190 * so we may as well use the prom VA. 191 * 192 * 64-bit kernels use physical addresses for bus space operations 193 * so mapping this in again will reduce TLB thrashing. 194 */ 195 if (bus_space_map(sc->sc_bustag, ma->ma_reg[0].ur_paddr, 196 ma->ma_reg[0].ur_len, 0, &sc->sc_bh) != 0) { 197 aprint_error_dev(self, "cannot map registers\n"); 198 return; 199 } 200 #endif 201 202 /* 203 * Record clock frequency for synchronous SCSI. 204 * IS THIS THE CORRECT DEFAULT?? 205 */ 206 sc->sc_clockfreq = prom_getpropint(node, "clock-frequency", 207 25*1000*1000); 208 printf(": clock = %s MHz\n", clockfreq(sc->sc_clockfreq)); 209 210 sbt = bus_space_tag_alloc(sc->sc_bustag, sc); 211 sbt->type = SBUS_BUS_SPACE; 212 sbt->sparc_bus_map = _sbus_bus_map; 213 sbt->sparc_intr_establish = sbus_intr_establish; 214 215 sc->sc_dmatag = sbus_alloc_dmatag(sc); 216 217 /* 218 * Get the SBus burst transfer size if burst transfers are supported 219 */ 220 sc->sc_burst = prom_getpropint(node, "burst-sizes", 0); 221 222 /* 223 * Collect address translations from the OBP. 224 */ 225 error = prom_getprop(node, "ranges", sizeof(struct openprom_range), 226 &sbt->nranges, &sbt->ranges); 227 if (error) 228 panic("%s: error getting ranges property", device_xname(&sc->sc_dev)); 229 230 /* initialize the IOMMU */ 231 232 /* punch in our copies */ 233 sc->sc_is.is_bustag = sc->sc_bustag; 234 bus_space_subregion(sc->sc_bustag, sc->sc_bh, 235 (vaddr_t)&((struct sysioreg *)NULL)->sys_iommu, 236 sizeof (struct iommureg), &sc->sc_is.is_iommu); 237 238 /* initialize our strbuf_ctl */ 239 sc->sc_is.is_sb[0] = &sc->sc_sb; 240 sc->sc_sb.sb_is = &sc->sc_is; 241 bus_space_subregion(sc->sc_bustag, sc->sc_bh, 242 (vaddr_t)&((struct sysioreg *)NULL)->sys_strbuf, 243 sizeof (struct iommu_strbuf), &sc->sc_sb.sb_sb); 244 /* Point sb_flush to our flush buffer. */ 245 sc->sc_sb.sb_flush = &sc->sc_flush; 246 247 /* give us a nice name.. */ 248 name = (char *)malloc(32, M_DEVBUF, M_NOWAIT); 249 if (name == 0) 250 panic("couldn't malloc iommu name"); 251 snprintf(name, 32, "%s dvma", device_xname(&sc->sc_dev)); 252 253 iommu_init(name, &sc->sc_is, 0, -1); 254 255 /* Enable the over temp intr */ 256 ih = (struct intrhand *) 257 malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT); 258 ih->ih_map = &sc->sc_sysio->therm_int_map; 259 ih->ih_clr = NULL; /* &sc->sc_sysio->therm_clr_int; */ 260 ih->ih_fun = sbus_overtemp; 261 ipl = 1; 262 ih->ih_pil = (1<<ipl); 263 ih->ih_number = INTVEC(*(ih->ih_map)); 264 intr_establish(ipl, true, ih); 265 *(ih->ih_map) |= INTMAP_V|(CPU_UPAID << INTMAP_TID_SHIFT); 266 267 /* 268 * Note: the stupid SBUS IOMMU ignores the high bits of an address, so a 269 * NULL DMA pointer will be translated by the first page of the IOTSB. 270 * To avoid bugs we'll alloc and ignore the first entry in the IOTSB. 271 */ 272 { 273 u_long dummy; 274 275 if (extent_alloc_subregion(sc->sc_is.is_dvmamap, 276 sc->sc_is.is_dvmabase, sc->sc_is.is_dvmabase + PAGE_SIZE, 277 PAGE_SIZE, PAGE_SIZE, 0, EX_NOWAIT|EX_BOUNDZERO, 278 (u_long *)&dummy) != 0) 279 panic("sbus iommu: can't toss first dvma page"); 280 } 281 282 /* 283 * Loop through ROM children, fixing any relative addresses 284 * and then configuring each device. 285 * `specials' is an array of device names that are treated 286 * specially: 287 */ 288 node0 = OF_child(node); 289 for (node = node0; node; node = OF_peer(node)) { 290 char *name1 = prom_getpropstring(node, "name"); 291 292 if (sbus_setup_attach_args(sc, sbt, sc->sc_dmatag, 293 node, &sa) != 0) { 294 printf("sbus_attach: %s: incomplete\n", name1); 295 continue; 296 } 297 (void) config_found(&sc->sc_dev, (void *)&sa, sbus_print); 298 sbus_destroy_attach_args(&sa); 299 } 300 } 301 302 int 303 sbus_setup_attach_args(struct sbus_softc *sc, bus_space_tag_t bustag, 304 bus_dma_tag_t dmatag, int node, struct sbus_attach_args *sa) 305 { 306 /*struct openprom_addr sbusreg;*/ 307 /*int base;*/ 308 int error; 309 int n; 310 311 memset(sa, 0, sizeof(struct sbus_attach_args)); 312 n = 0; 313 error = prom_getprop(node, "name", 1, &n, &sa->sa_name); 314 if (error != 0) 315 return (error); 316 sa->sa_name[n] = '\0'; 317 318 sa->sa_bustag = bustag; 319 sa->sa_dmatag = dmatag; 320 sa->sa_node = node; 321 sa->sa_frequency = sc->sc_clockfreq; 322 323 error = prom_getprop(node, "reg", sizeof(struct openprom_addr), 324 &sa->sa_nreg, &sa->sa_reg); 325 if (error != 0) { 326 char buf[32]; 327 if (error != ENOENT || 328 !node_has_property(node, "device_type") || 329 strcmp(prom_getpropstringA(node, "device_type", buf, sizeof buf), 330 "hierarchical") != 0) 331 return (error); 332 } 333 for (n = 0; n < sa->sa_nreg; n++) { 334 /* Convert to relative addressing, if necessary */ 335 uint32_t base = sa->sa_reg[n].oa_base; 336 if (SBUS_ABS(base)) { 337 sa->sa_reg[n].oa_space = SBUS_ABS_TO_SLOT(base); 338 sa->sa_reg[n].oa_base = SBUS_ABS_TO_OFFSET(base); 339 } 340 } 341 342 if ((error = sbus_get_intr(sc, node, &sa->sa_intr, &sa->sa_nintr, 343 sa->sa_slot)) != 0) 344 return (error); 345 346 error = prom_getprop(node, "address", sizeof(uint32_t), 347 &sa->sa_npromvaddrs, &sa->sa_promvaddrs); 348 if (error != 0 && error != ENOENT) 349 return (error); 350 351 return (0); 352 } 353 354 void 355 sbus_destroy_attach_args(struct sbus_attach_args *sa) 356 { 357 if (sa->sa_name != NULL) 358 free(sa->sa_name, M_DEVBUF); 359 360 if (sa->sa_nreg != 0) 361 free(sa->sa_reg, M_DEVBUF); 362 363 if (sa->sa_intr) 364 free(sa->sa_intr, M_DEVBUF); 365 366 if (sa->sa_promvaddrs) 367 free((void *)sa->sa_promvaddrs, M_DEVBUF); 368 369 memset(sa, 0, sizeof(struct sbus_attach_args)); /*DEBUG*/ 370 } 371 372 373 int 374 _sbus_bus_map(bus_space_tag_t t, bus_addr_t addr, bus_size_t size, int flags, 375 vaddr_t v, bus_space_handle_t *hp) 376 { 377 int error; 378 379 if (t->ranges != NULL) { 380 if ((error = bus_space_translate_address_generic( 381 t->ranges, t->nranges, &addr)) != 0) 382 return (error); 383 } 384 385 return (bus_space_map(t->parent, addr, size, flags, hp)); 386 } 387 388 389 bus_addr_t 390 sbus_bus_addr(bus_space_tag_t t, u_int btype, u_int offset) 391 { 392 int slot = btype; 393 struct openprom_range *rp; 394 int i; 395 396 for (i = 0; i < t->nranges; i++) { 397 rp = &t->ranges[i]; 398 if (rp->or_child_space != slot) 399 continue; 400 401 return BUS_ADDR(rp->or_parent_space, 402 rp->or_parent_base + offset); 403 } 404 405 return (0); 406 } 407 408 409 /* 410 * Each attached device calls sbus_establish after it initializes 411 * its sbusdev portion. 412 */ 413 void 414 sbus_establish(register struct sbusdev *sd, register struct device *dev) 415 { 416 register struct sbus_softc *sc; 417 register struct device *curdev; 418 419 /* 420 * We have to look for the sbus by name, since it is not necessarily 421 * our immediate parent (i.e. sun4m /iommu/sbus/espdma/esp) 422 * We don't just use the device structure of the above-attached 423 * sbus, since we might (in the future) support multiple sbus's. 424 */ 425 for (curdev = device_parent(dev); ; curdev = device_parent(curdev)) { 426 if (!curdev || !device_xname(curdev)) 427 panic("sbus_establish: can't find sbus parent for %s", 428 device_xname(sd->sd_dev) 429 ? device_xname(sd->sd_dev) 430 : "<unknown>" ); 431 432 if (strncmp(device_xname(curdev), "sbus", 4) == 0) 433 break; 434 } 435 sc = (struct sbus_softc *) curdev; 436 437 sd->sd_dev = dev; 438 sd->sd_bchain = sc->sc_sbdev; 439 sc->sc_sbdev = sd; 440 } 441 442 /* 443 * Reset the given sbus. 444 */ 445 void 446 sbusreset(int sbus) 447 { 448 register struct sbusdev *sd; 449 struct sbus_softc *sc = device_lookup_private(&sbus_cd, sbus); 450 struct device *dev; 451 452 printf("reset %s:", device_xname(&sc->sc_dev)); 453 for (sd = sc->sc_sbdev; sd != NULL; sd = sd->sd_bchain) { 454 if (sd->sd_reset) { 455 dev = sd->sd_dev; 456 (*sd->sd_reset)(dev); 457 printf(" %s", device_xname(dev)); 458 } 459 } 460 /* Reload iommu regs */ 461 iommu_reset(&sc->sc_is); 462 } 463 464 /* 465 * Handle an overtemp situation. 466 * 467 * SPARCs have temperature sensors which generate interrupts 468 * if the machine's temperature exceeds a certain threshold. 469 * This handles the interrupt and powers off the machine. 470 * The same needs to be done to PCI controller drivers. 471 */ 472 int 473 sbus_overtemp(void *arg) 474 { 475 /* Should try a clean shutdown first */ 476 printf("DANGER: OVER TEMPERATURE detected\nShutting down...\n"); 477 delay(20); 478 cpu_reboot(RB_POWERDOWN|RB_HALT, NULL); 479 } 480 481 /* 482 * Get interrupt attributes for an Sbus device. 483 */ 484 int 485 sbus_get_intr(struct sbus_softc *sc, int node, struct openprom_intr **ipp, 486 int *np, int slot) 487 { 488 int *ipl; 489 int n, i; 490 char buf[32]; 491 492 /* 493 * The `interrupts' property contains the Sbus interrupt level. 494 */ 495 ipl = NULL; 496 if (prom_getprop(node, "interrupts", sizeof(int), np, &ipl) == 0) { 497 struct openprom_intr *ip; 498 int pri; 499 500 /* Default to interrupt level 2 -- otherwise unused */ 501 pri = INTLEVENCODE(2); 502 503 /* Change format to an `struct sbus_intr' array */ 504 ip = malloc(*np * sizeof(struct openprom_intr), M_DEVBUF, 505 M_NOWAIT); 506 if (ip == NULL) 507 return (ENOMEM); 508 509 /* 510 * Now things get ugly. We need to take this value which is 511 * the interrupt vector number and encode the IPL into it 512 * somehow. Luckily, the interrupt vector has lots of free 513 * space and we can easily stuff the IPL in there for a while. 514 */ 515 prom_getpropstringA(node, "device_type", buf, sizeof buf); 516 if (buf[0] == '\0') 517 prom_getpropstringA(node, "name", buf, sizeof buf); 518 519 for (i = 0; intrmap[i].in_class; i++) 520 if (strcmp(intrmap[i].in_class, buf) == 0) { 521 pri = INTLEVENCODE(intrmap[i].in_lev); 522 break; 523 } 524 525 /* 526 * Sbus card devices need the slot number encoded into 527 * the vector as this is generally not done. 528 */ 529 if ((ipl[0] & INTMAP_OBIO) == 0) 530 pri |= slot << 3; 531 532 for (n = 0; n < *np; n++) { 533 /* 534 * We encode vector and priority into sbi_pri so we 535 * can pass them as a unit. This will go away if 536 * sbus_establish ever takes an sbus_intr instead 537 * of an integer level. 538 * Stuff the real vector in sbi_vec. 539 */ 540 541 ip[n].oi_pri = pri|ipl[n]; 542 ip[n].oi_vec = ipl[n]; 543 } 544 free(ipl, M_DEVBUF); 545 *ipp = ip; 546 } 547 548 return (0); 549 } 550 551 552 /* 553 * Install an interrupt handler for an Sbus device. 554 */ 555 void * 556 sbus_intr_establish(bus_space_tag_t t, int pri, int level, 557 int (*handler)(void *), void *arg, void (*fastvec)(void)) 558 { 559 struct sbus_softc *sc = t->cookie; 560 struct intrhand *ih; 561 int ipl; 562 long vec = pri; 563 564 ih = (struct intrhand *) 565 malloc(sizeof(struct intrhand), M_DEVBUF, M_NOWAIT); 566 if (ih == NULL) 567 return (NULL); 568 569 if ((vec & SBUS_INTR_COMPAT) != 0) 570 ipl = vec & ~SBUS_INTR_COMPAT; 571 else { 572 /* Decode and remove IPL */ 573 ipl = INTLEV(vec); 574 vec = INTVEC(vec); 575 DPRINTF(SDB_INTR, 576 ("\nsbus: intr[%ld]%lx: %lx\nHunting for IRQ...\n", 577 (long)ipl, (long)vec, (u_long)intrlev[vec])); 578 if ((vec & INTMAP_OBIO) == 0) { 579 /* We're in an SBUS slot */ 580 /* Register the map and clear intr registers */ 581 582 int slot = INTSLOT(pri); 583 584 ih->ih_map = &(&sc->sc_sysio->sbus_slot0_int)[slot]; 585 ih->ih_clr = &sc->sc_sysio->sbus0_clr_int[vec]; 586 #ifdef DEBUG 587 if (sbus_debug & SDB_INTR) { 588 int64_t imap = *ih->ih_map; 589 590 printf("SBUS %lx IRQ as %llx in slot %d\n", 591 (long)vec, (long long)imap, slot); 592 printf("\tmap addr %p clr addr %p\n", 593 ih->ih_map, ih->ih_clr); 594 } 595 #endif 596 /* Enable the interrupt */ 597 vec |= INTMAP_V | sc->sc_ign | 598 (CPU_UPAID << INTMAP_TID_SHIFT); 599 *(ih->ih_map) = vec; 600 } else { 601 int64_t *intrptr = &sc->sc_sysio->scsi_int_map; 602 int64_t imap = 0; 603 int i; 604 605 /* Insert IGN */ 606 vec |= sc->sc_ign; 607 for (i = 0; &intrptr[i] <= 608 (int64_t *)&sc->sc_sysio->reserved_int_map && 609 INTVEC(imap = intrptr[i]) != INTVEC(vec); i++) 610 ; 611 if (INTVEC(imap) == INTVEC(vec)) { 612 DPRINTF(SDB_INTR, 613 ("OBIO %lx IRQ as %lx in slot %d\n", 614 vec, (long)imap, i)); 615 /* Register the map and clear intr registers */ 616 ih->ih_map = &intrptr[i]; 617 intrptr = (int64_t *)&sc->sc_sysio->scsi_clr_int; 618 ih->ih_clr = &intrptr[i]; 619 /* Enable the interrupt */ 620 imap |= INTMAP_V 621 |(CPU_UPAID << INTMAP_TID_SHIFT); 622 /* XXXX */ 623 *(ih->ih_map) = imap; 624 } else 625 panic("IRQ not found!"); 626 } 627 } 628 #ifdef DEBUG 629 if (sbus_debug & SDB_INTR) { long i; for (i = 0; i < 400000000; i++); } 630 #endif 631 632 ih->ih_fun = handler; 633 ih->ih_arg = arg; 634 ih->ih_number = vec; 635 ih->ih_pil = (1<<ipl); 636 intr_establish(ipl, level != IPL_VM, ih); 637 return (ih); 638 } 639 640 static bus_dma_tag_t 641 sbus_alloc_dmatag(struct sbus_softc *sc) 642 { 643 bus_dma_tag_t sdt, psdt = sc->sc_dmatag; 644 645 sdt = (bus_dma_tag_t) 646 malloc(sizeof(struct sparc_bus_dma_tag), M_DEVBUF, M_NOWAIT); 647 if (sdt == NULL) 648 /* Panic? */ 649 return (psdt); 650 651 sdt->_cookie = sc; 652 sdt->_parent = psdt; 653 #define PCOPY(x) sdt->x = psdt->x 654 sdt->_dmamap_create = sbus_dmamap_create; 655 PCOPY(_dmamap_destroy); 656 sdt->_dmamap_load = iommu_dvmamap_load; 657 PCOPY(_dmamap_load_mbuf); 658 PCOPY(_dmamap_load_uio); 659 sdt->_dmamap_load_raw = iommu_dvmamap_load_raw; 660 sdt->_dmamap_unload = iommu_dvmamap_unload; 661 sdt->_dmamap_sync = iommu_dvmamap_sync; 662 sdt->_dmamem_alloc = iommu_dvmamem_alloc; 663 sdt->_dmamem_free = iommu_dvmamem_free; 664 sdt->_dmamem_map = iommu_dvmamem_map; 665 sdt->_dmamem_unmap = iommu_dvmamem_unmap; 666 PCOPY(_dmamem_mmap); 667 #undef PCOPY 668 sc->sc_dmatag = sdt; 669 return (sdt); 670 } 671 672 static int 673 sbus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments, 674 bus_size_t maxsegsz, bus_size_t boundary, int flags, 675 bus_dmamap_t *dmamp) 676 { 677 struct sbus_softc *sc = (struct sbus_softc *)t->_cookie; 678 int error; 679 680 error = bus_dmamap_create(t->_parent, size, nsegments, maxsegsz, 681 boundary, flags, dmamp); 682 if (error == 0) 683 (*dmamp)->_dm_cookie = &sc->sc_sb; 684 return error; 685 } 686