rootnex.c revision 580:70dfd36fd02c
1/* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22/* 23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27#pragma ident "%Z%%M% %I% %E% SMI" 28 29/* 30 * sun4 root nexus driver 31 */ 32 33#include <sys/conf.h> 34#include <sys/modctl.h> 35#include <sys/ddi_subrdefs.h> 36#include <sys/sunndi.h> 37#include <sys/vmsystm.h> 38#include <sys/async.h> 39#include <sys/intr.h> 40#include <sys/ndifm.h> 41#include <vm/seg_dev.h> 42#include <vm/seg_kmem.h> 43#include <sys/ontrap.h> 44 45/* Useful debugging Stuff */ 46#include <sys/nexusdebug.h> 47#define ROOTNEX_MAP_DEBUG 0x1 48#define ROOTNEX_INTR_DEBUG 0x2 49 50/* 51 * config information 52 */ 53 54static int 55rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 56 off_t offset, off_t len, caddr_t *vaddrp); 57 58static int 59rootnex_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t, 60 ddi_intr_handle_impl_t *, void *); 61 62static int 63rootnex_map_fault(dev_info_t *dip, dev_info_t *rdip, 64 struct hat *hat, struct seg *seg, caddr_t addr, 65 struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock); 66 67static int 68rootnex_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); 69 70static int 71rootnex_busop_fminit(dev_info_t *dip, dev_info_t *tdip, int tcap, 72 ddi_iblock_cookie_t *ibc); 73 74static void 75rootnex_fm_init(dev_info_t *); 76 77static int 78rootnex_ctlops_peekpoke(ddi_ctl_enum_t, peekpoke_ctlops_t *, void *result); 79 80/* 81 * Defined in $KARCH/io/mach_rootnex.c 82 */ 83int rootnex_add_intr_impl(dev_info_t *dip, dev_info_t *rdip, 84 ddi_intr_handle_impl_t *hdlp); 85#pragma weak rootnex_add_intr_impl 86 87int rootnex_remove_intr_impl(dev_info_t *dip, dev_info_t *rdip, 88 ddi_intr_handle_impl_t *hdlp); 89#pragma weak rootnex_remove_intr_impl 90 91void rootnex_get_intr_pri(dev_info_t *dip, dev_info_t *rdip, 92 ddi_intr_handle_impl_t *hdlp); 93#pragma weak rootnex_get_intr_pri 94 95int rootnex_name_child_impl(dev_info_t *child, char *name, int namelen); 96#pragma weak rootnex_name_child_impl 97 98int rootnex_ctl_initchild_impl(dev_info_t *dip); 99#pragma weak rootnex_initchild_impl 100 101void rootnex_ctl_uninitchild_impl(dev_info_t *dip); 102#pragma weak rootnex_uninitchild_impl 103 104int rootnex_ctl_reportdev_impl(dev_info_t *dev); 105#pragma weak rootnex_reportdev_impl 106 107static struct cb_ops rootnex_cb_ops = { 108 nodev, /* open */ 109 nodev, /* close */ 110 nodev, /* strategy */ 111 nodev, /* print */ 112 nodev, /* dump */ 113 nodev, /* read */ 114 nodev, /* write */ 115 nodev, /* ioctl */ 116 nodev, /* devmap */ 117 nodev, /* mmap */ 118 nodev, /* segmap */ 119 nochpoll, /* chpoll */ 120 ddi_prop_op, /* cb_prop_op */ 121 NULL, /* struct streamtab */ 122 D_NEW | D_MP | D_HOTPLUG, /* compatibility flags */ 123 CB_REV, /* Rev */ 124 nodev, /* cb_aread */ 125 nodev /* cb_awrite */ 126}; 127 128static struct bus_ops rootnex_bus_ops = { 129 BUSO_REV, 130 rootnex_map, 131 NULL, 132 NULL, 133 NULL, 134 rootnex_map_fault, 135 ddi_no_dma_map, /* no rootnex_dma_map- now in sysio nexus */ 136 ddi_no_dma_allochdl, 137 ddi_no_dma_freehdl, 138 ddi_no_dma_bindhdl, 139 ddi_no_dma_unbindhdl, 140 ddi_no_dma_flush, 141 ddi_no_dma_win, 142 ddi_no_dma_mctl, /* no rootnex_dma_mctl- now in sysio nexus */ 143 rootnex_ctlops, 144 ddi_bus_prop_op, 145 i_ddi_rootnex_get_eventcookie, 146 i_ddi_rootnex_add_eventcall, 147 i_ddi_rootnex_remove_eventcall, 148 i_ddi_rootnex_post_event, 149 NULL, /* bus_intr_ctl */ 150 NULL, /* bus_config */ 151 NULL, /* bus_unconfig */ 152 rootnex_busop_fminit, /* bus_fm_init */ 153 NULL, /* bus_fm_fini */ 154 NULL, /* bus_fm_access_enter */ 155 NULL, /* bus_fm_access_fini */ 156 NULL, /* bus_power */ 157 rootnex_intr_ops /* bus_intr_op */ 158}; 159 160static int rootnex_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 161static int rootnex_detach(dev_info_t *devi, ddi_detach_cmd_t cmd); 162 163static struct dev_ops rootnex_ops = { 164 DEVO_REV, 165 0, /* refcnt */ 166 ddi_no_info, /* info */ 167 nulldev, 168 nulldev, /* probe */ 169 rootnex_attach, 170 rootnex_detach, 171 nodev, /* reset */ 172 &rootnex_cb_ops, 173 &rootnex_bus_ops 174}; 175 176 177extern uint_t root_phys_addr_lo_mask; 178extern uint_t root_phys_addr_hi_mask; 179extern struct mod_ops mod_driverops; 180extern struct dev_ops rootnex_ops; 181extern struct cpu cpu0; 182extern ddi_iblock_cookie_t rootnex_err_ibc; 183 184 185/* 186 * Add statically defined root properties to this list... 187 */ 188static const int pagesize = PAGESIZE; 189static const int mmu_pagesize = MMU_PAGESIZE; 190static const int mmu_pageoffset = MMU_PAGEOFFSET; 191 192struct prop_def { 193 char *prop_name; 194 caddr_t prop_value; 195}; 196 197static struct prop_def root_props[] = { 198 { "PAGESIZE", (caddr_t)&pagesize }, 199 { "MMU_PAGESIZE", (caddr_t)&mmu_pagesize}, 200 { "MMU_PAGEOFFSET", (caddr_t)&mmu_pageoffset}, 201}; 202 203static vmem_t *rootnex_regspec_arena; 204 205#define NROOT_PROPS (sizeof (root_props) / sizeof (struct prop_def)) 206 207 208 209/* 210 * Module linkage information for the kernel. 211 */ 212 213static struct modldrv modldrv = { 214 &mod_driverops, /* Type of module. This one is a nexus driver */ 215 "sun4 root nexus %I%", 216 &rootnex_ops, /* Driver ops */ 217}; 218 219static struct modlinkage modlinkage = { 220 MODREV_1, (void *)&modldrv, NULL 221}; 222 223int 224_init(void) 225{ 226 return (mod_install(&modlinkage)); 227} 228 229int 230_fini(void) 231{ 232 return (EBUSY); 233} 234 235int 236_info(struct modinfo *modinfop) 237{ 238 return (mod_info(&modlinkage, modinfop)); 239} 240 241/* 242 * rootnex_attach: 243 * 244 * attach the root nexus. 245 */ 246static void add_root_props(dev_info_t *); 247 248/*ARGSUSED*/ 249static int 250rootnex_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 251{ 252 int length; 253 char *valuep = NULL; 254 255 /* 256 * Only do these functions when the driver is acting as the 257 * root nexus, not when it is driving a memory controller. 258 */ 259 if (ddi_root_node() == devi) { 260 rootnex_fm_init(devi); 261 add_root_props(devi); 262 i_ddi_rootnex_init_events(devi); 263 rootnex_regspec_arena = vmem_create("regspec", 264 (void *)PIOMAPBASE, PIOMAPSIZE, MMU_PAGESIZE, NULL, NULL, 265 NULL, 0, VM_SLEEP); 266 } 267 268 if (ddi_prop_op(DDI_DEV_T_ANY, devi, PROP_LEN_AND_VAL_ALLOC, 269 DDI_PROP_DONTPASS, "banner-name", (caddr_t)&valuep, 270 &length) == DDI_PROP_SUCCESS) { 271 cmn_err(CE_CONT, "?root nexus = %s\n", valuep); 272 kmem_free(valuep, length); 273 } 274 /* 275 * Add a no-suspend-resume property so that NDI 276 * does not attempt to suspend/resume the rootnex 277 * (or any of its aliases) node. 278 */ 279 (void) ddi_prop_update_string(DDI_DEV_T_NONE, devi, 280 "pm-hardware-state", "no-suspend-resume"); 281 282 return (DDI_SUCCESS); 283} 284 285/*ARGSUSED*/ 286static int 287rootnex_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 288{ 289 return (DDI_SUCCESS); 290} 291 292static void 293add_root_props(dev_info_t *devi) 294{ 295 int i; 296 struct prop_def *rpp; 297 298 /* 299 * Note that this for loop works because all of the 300 * properties in root_prop are integers 301 */ 302 for (i = 0, rpp = root_props; i < NROOT_PROPS; ++i, ++rpp) { 303 (void) e_ddi_prop_update_int(DDI_DEV_T_NONE, devi, 304 rpp->prop_name, *((int *)rpp->prop_value)); 305 } 306 307 /* 308 * Create the root node "boolean" property 309 * corresponding to addressing type supported in the root node: 310 * 311 * Choices are: 312 * "relative-addressing" (OBP PROMS) 313 * "generic-addressing" (SunMon -- pseudo OBP/DDI) 314 */ 315 316 (void) e_ddi_prop_update_int(DDI_DEV_T_NONE, devi, 317 DDI_RELATIVE_ADDRESSING, 1); 318 319 /* 320 * Create fault management capability property 321 */ 322 (void) e_ddi_prop_update_int(DDI_DEV_T_NONE, devi, "fm-capable", 323 ddi_fm_capable(devi)); 324} 325 326static int 327rootnex_map_regspec(ddi_map_req_t *mp, caddr_t *vaddrp, uint_t mapping_attr) 328{ 329 ulong_t base; 330 caddr_t kaddr; 331 pgcnt_t npages; 332 pfn_t pfn; 333 uint_t pgoffset; 334 struct regspec *rp = mp->map_obj.rp; 335 ddi_acc_hdl_t *hp; 336 337 base = (ulong_t)rp->regspec_addr & (~MMU_PAGEOFFSET); /* base addr */ 338 339 /* 340 * Take the bustype and the physical page base within the 341 * bus space and turn it into a 28 bit page frame number. 342 */ 343 344 pfn = BUSTYPE_TO_PFN(((rp->regspec_bustype) & root_phys_addr_hi_mask), 345 mmu_btop(base)); 346 347 348 /* 349 * Do a quick sanity check to make sure we are in I/O space. 350 */ 351 if (pf_is_memory(pfn)) 352 return (DDI_ME_INVAL); 353 354 if (rp->regspec_size == 0) { 355 DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_regspec: zero " 356 "regspec_size\n")); 357 return (DDI_ME_INVAL); 358 } 359 360 if (mp->map_flags & DDI_MF_DEVICE_MAPPING) 361 *vaddrp = (caddr_t)pfn; 362 else { 363 pgoffset = (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET; 364 npages = mmu_btopr(rp->regspec_size + pgoffset); 365 366 DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_regspec: Mapping " 367 "%lu pages physical %x.%lx ", npages, rp->regspec_bustype, 368 base)); 369 370 if ((kaddr = vmem_alloc(rootnex_regspec_arena, 371 ptob(npages), VM_NOSLEEP)) == NULL) 372 return (DDI_ME_NORESOURCES); 373 374 /* 375 * Now map in the pages we've allocated... 376 */ 377 hat_devload(kas.a_hat, kaddr, ptob(npages), pfn, 378 mp->map_prot | mapping_attr, HAT_LOAD_LOCK); 379 380 *vaddrp = kaddr + pgoffset; 381 382 hp = mp->map_handlep; 383 if (hp) { 384 hp->ah_pfn = pfn; 385 hp->ah_pnum = npages; 386 } 387 } 388 389 DPRINTF(ROOTNEX_MAP_DEBUG, ("at virtual 0x%p\n", *vaddrp)); 390 return (0); 391} 392 393static int 394rootnex_unmap_regspec(ddi_map_req_t *mp, caddr_t *vaddrp) 395{ 396 caddr_t addr = *vaddrp; 397 pgcnt_t npages; 398 uint_t pgoffset; 399 caddr_t base; 400 struct regspec *rp; 401 402 if (mp->map_flags & DDI_MF_DEVICE_MAPPING) 403 return (0); 404 405 rp = mp->map_obj.rp; 406 pgoffset = (uintptr_t)addr & MMU_PAGEOFFSET; 407 408 if (rp->regspec_size == 0) { 409 DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_unmap_regspec: " 410 "zero regspec_size\n")); 411 return (DDI_ME_INVAL); 412 } 413 414 base = addr - pgoffset; 415 npages = mmu_btopr(rp->regspec_size + pgoffset); 416 hat_unload(kas.a_hat, base, ptob(npages), HAT_UNLOAD_UNLOCK); 417 vmem_free(rootnex_regspec_arena, base, ptob(npages)); 418 419 /* 420 * Destroy the pointer - the mapping has logically gone 421 */ 422 *vaddrp = (caddr_t)0; 423 424 return (0); 425} 426 427static int 428rootnex_map_handle(ddi_map_req_t *mp) 429{ 430 ddi_acc_hdl_t *hp; 431 uint_t hat_flags; 432 register struct regspec *rp; 433 434 /* 435 * Set up the hat_flags for the mapping. 436 */ 437 hp = mp->map_handlep; 438 439 switch (hp->ah_acc.devacc_attr_endian_flags) { 440 case DDI_NEVERSWAP_ACC: 441 hat_flags = HAT_NEVERSWAP | HAT_STRICTORDER; 442 break; 443 case DDI_STRUCTURE_BE_ACC: 444 hat_flags = HAT_STRUCTURE_BE; 445 break; 446 case DDI_STRUCTURE_LE_ACC: 447 hat_flags = HAT_STRUCTURE_LE; 448 break; 449 default: 450 return (DDI_REGS_ACC_CONFLICT); 451 } 452 453 switch (hp->ah_acc.devacc_attr_dataorder) { 454 case DDI_STRICTORDER_ACC: 455 break; 456 case DDI_UNORDERED_OK_ACC: 457 hat_flags |= HAT_UNORDERED_OK; 458 break; 459 case DDI_MERGING_OK_ACC: 460 hat_flags |= HAT_MERGING_OK; 461 break; 462 case DDI_LOADCACHING_OK_ACC: 463 hat_flags |= HAT_LOADCACHING_OK; 464 break; 465 case DDI_STORECACHING_OK_ACC: 466 hat_flags |= HAT_STORECACHING_OK; 467 break; 468 default: 469 return (DDI_FAILURE); 470 } 471 472 rp = mp->map_obj.rp; 473 if (rp->regspec_size == 0) 474 return (DDI_ME_INVAL); 475 476 hp->ah_hat_flags = hat_flags; 477 hp->ah_pfn = mmu_btop((ulong_t)rp->regspec_addr & (~MMU_PAGEOFFSET)); 478 hp->ah_pnum = mmu_btopr(rp->regspec_size + 479 (ulong_t)rp->regspec_addr & MMU_PAGEOFFSET); 480 return (DDI_SUCCESS); 481} 482 483static int 484rootnex_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 485 off_t offset, off_t len, caddr_t *vaddrp) 486{ 487 struct regspec *rp, tmp_reg; 488 ddi_map_req_t mr = *mp; /* Get private copy of request */ 489 int error; 490 uint_t mapping_attr; 491 ddi_acc_hdl_t *hp = NULL; 492 493 mp = &mr; 494 495 switch (mp->map_op) { 496 case DDI_MO_MAP_LOCKED: 497 case DDI_MO_UNMAP: 498 case DDI_MO_MAP_HANDLE: 499 break; 500 default: 501 DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: unimplemented map " 502 "op %d.", mp->map_op)); 503 return (DDI_ME_UNIMPLEMENTED); 504 } 505 506 if (mp->map_flags & DDI_MF_USER_MAPPING) { 507 DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: unimplemented map " 508 "type: user.")); 509 return (DDI_ME_UNIMPLEMENTED); 510 } 511 512 /* 513 * First, if given an rnumber, convert it to a regspec... 514 * (Presumably, this is on behalf of a child of the root node?) 515 */ 516 517 if (mp->map_type == DDI_MT_RNUMBER) { 518 519 int rnumber = mp->map_obj.rnumber; 520 521 rp = i_ddi_rnumber_to_regspec(rdip, rnumber); 522 if (rp == (struct regspec *)0) { 523 DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: Out of " 524 "range rnumber <%d>, device <%s>", rnumber, 525 ddi_get_name(rdip))); 526 return (DDI_ME_RNUMBER_RANGE); 527 } 528 529 /* 530 * Convert the given ddi_map_req_t from rnumber to regspec... 531 */ 532 533 mp->map_type = DDI_MT_REGSPEC; 534 mp->map_obj.rp = rp; 535 } 536 537 /* 538 * Adjust offset and length corresponding to called values... 539 * XXX: A non-zero length means override the one in the regspec 540 * XXX: regardless of what's in the parent's range?. 541 */ 542 543 tmp_reg = *(mp->map_obj.rp); /* Preserve underlying data */ 544 rp = mp->map_obj.rp = &tmp_reg; /* Use tmp_reg in request */ 545 546 rp->regspec_addr += (uint_t)offset; 547 if (len != 0) 548 rp->regspec_size = (uint_t)len; 549 550 /* 551 * Apply any parent ranges at this level, if applicable. 552 * (This is where nexus specific regspec translation takes place. 553 * Use of this function is implicit agreement that translation is 554 * provided via ddi_apply_range.) 555 */ 556 557 DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map: applying range of parent " 558 "<%s> to child <%s>...\n", ddi_get_name(dip), ddi_get_name(rdip))); 559 560 if ((error = i_ddi_apply_range(dip, rdip, mp->map_obj.rp)) != 0) 561 return (error); 562 563 switch (mp->map_op) { 564 case DDI_MO_MAP_LOCKED: 565 566 /* 567 * Set up the locked down kernel mapping to the regspec... 568 */ 569 570 /* 571 * If we were passed an access handle we need to determine 572 * the "endian-ness" of the mapping and fill in the handle. 573 */ 574 if (mp->map_handlep) { 575 hp = mp->map_handlep; 576 switch (hp->ah_acc.devacc_attr_endian_flags) { 577 case DDI_NEVERSWAP_ACC: 578 mapping_attr = HAT_NEVERSWAP | HAT_STRICTORDER; 579 break; 580 case DDI_STRUCTURE_BE_ACC: 581 mapping_attr = HAT_STRUCTURE_BE; 582 break; 583 case DDI_STRUCTURE_LE_ACC: 584 mapping_attr = HAT_STRUCTURE_LE; 585 break; 586 default: 587 return (DDI_REGS_ACC_CONFLICT); 588 } 589 590 switch (hp->ah_acc.devacc_attr_dataorder) { 591 case DDI_STRICTORDER_ACC: 592 break; 593 case DDI_UNORDERED_OK_ACC: 594 mapping_attr |= HAT_UNORDERED_OK; 595 break; 596 case DDI_MERGING_OK_ACC: 597 mapping_attr |= HAT_MERGING_OK; 598 break; 599 case DDI_LOADCACHING_OK_ACC: 600 mapping_attr |= HAT_LOADCACHING_OK; 601 break; 602 case DDI_STORECACHING_OK_ACC: 603 mapping_attr |= HAT_STORECACHING_OK; 604 break; 605 default: 606 return (DDI_REGS_ACC_CONFLICT); 607 } 608 } else { 609 mapping_attr = HAT_NEVERSWAP | HAT_STRICTORDER; 610 } 611 612 /* 613 * Set up the mapping. 614 */ 615 error = rootnex_map_regspec(mp, vaddrp, mapping_attr); 616 617 /* 618 * Fill in the access handle if needed. 619 */ 620 if (hp) { 621 hp->ah_addr = *vaddrp; 622 hp->ah_hat_flags = mapping_attr; 623 if (error == 0) 624 impl_acc_hdl_init(hp); 625 } 626 return (error); 627 628 case DDI_MO_UNMAP: 629 630 /* 631 * Release mapping... 632 */ 633 634 return (rootnex_unmap_regspec(mp, vaddrp)); 635 636 case DDI_MO_MAP_HANDLE: 637 return (rootnex_map_handle(mp)); 638 639 } 640 641 return (DDI_ME_UNIMPLEMENTED); 642} 643 644static int 645rootnex_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 646 ddi_intr_handle_impl_t *hdlp, void *result) 647{ 648 ddi_ispec_t *ip = (ddi_ispec_t *)hdlp->ih_private; 649 int ret = DDI_SUCCESS; 650 651 DPRINTF(ROOTNEX_INTR_DEBUG, ("rootnex_intr_ops: rdip=%s%d " 652 "intr_op 0x%x hdlp 0x%p\n", ddi_driver_name(rdip), 653 ddi_get_instance(rdip), intr_op, hdlp)); 654 655 switch (intr_op) { 656 case DDI_INTROP_GETCAP: 657 *(int *)result = 0; 658 break; 659 case DDI_INTROP_SETCAP: 660 ret = DDI_ENOTSUP; 661 break; 662 case DDI_INTROP_ALLOC: 663 *(int *)result = hdlp->ih_scratch1; 664 break; 665 case DDI_INTROP_FREE: 666 break; 667 case DDI_INTROP_GETPRI: 668 rootnex_get_intr_pri(dip, rdip, hdlp); 669 *(int *)result = ip->is_pil; 670 break; 671 case DDI_INTROP_SETPRI: 672 ip->is_pil = (*(int *)result); 673 break; 674 case DDI_INTROP_ADDISR: 675 ret = rootnex_add_intr_impl(dip, rdip, hdlp); 676 break; 677 case DDI_INTROP_REMISR: 678 ret = rootnex_remove_intr_impl(dip, rdip, hdlp); 679 break; 680 case DDI_INTROP_ENABLE: 681 case DDI_INTROP_DISABLE: 682 break; 683 case DDI_INTROP_NINTRS: 684 case DDI_INTROP_NAVAIL: 685 *(int *)result = i_ddi_get_nintrs(rdip); 686 break; 687 case DDI_INTROP_SUPPORTED_TYPES: 688 /* Root nexus driver supports only fixed interrupts */ 689 *(int *)result = i_ddi_get_nintrs(rdip) ? 690 DDI_INTR_TYPE_FIXED : 0; 691 break; 692 default: 693 ret = DDI_ENOTSUP; 694 break; 695 } 696 697 return (ret); 698} 699 700 701/* 702 * Shorthand defines 703 */ 704 705#define DMAOBJ_PP_PP dmao_obj.pp_obj.pp_pp 706#define DMAOBJ_PP_OFF dmao_ogj.pp_obj.pp_offset 707#define ALO dma_lim->dlim_addr_lo 708#define AHI dma_lim->dlim_addr_hi 709#define OBJSIZE dmareq->dmar_object.dmao_size 710#define ORIGVADDR dmareq->dmar_object.dmao_obj.virt_obj.v_addr 711#define RED ((mp->dmai_rflags & DDI_DMA_REDZONE)? 1 : 0) 712#define DIRECTION (mp->dmai_rflags & DDI_DMA_RDWR) 713 714/* 715 * rootnex_map_fault: 716 * 717 * fault in mappings for requestors 718 */ 719 720/*ARGSUSED*/ 721static int 722rootnex_map_fault(dev_info_t *dip, dev_info_t *rdip, 723 struct hat *hat, struct seg *seg, caddr_t addr, 724 struct devpage *dp, pfn_t pfn, uint_t prot, uint_t lock) 725{ 726 extern struct seg_ops segdev_ops; 727 728 DPRINTF(ROOTNEX_MAP_DEBUG, ("rootnex_map_fault: address <%p> " 729 "pfn <%lx>", addr, pfn)); 730 DPRINTF(ROOTNEX_MAP_DEBUG, (" Seg <%s>\n", 731 seg->s_ops == &segdev_ops ? "segdev" : 732 seg == &kvseg ? "segkmem" : "NONE!")); 733 734 /* 735 * This is all terribly broken, but it is a start 736 * 737 * XXX Note that this test means that segdev_ops 738 * must be exported from seg_dev.c. 739 * XXX What about devices with their own segment drivers? 740 */ 741 if (seg->s_ops == &segdev_ops) { 742 register struct segdev_data *sdp = 743 (struct segdev_data *)seg->s_data; 744 745 if (hat == NULL) { 746 /* 747 * This is one plausible interpretation of 748 * a null hat i.e. use the first hat on the 749 * address space hat list which by convention is 750 * the hat of the system MMU. At alternative 751 * would be to panic .. this might well be better .. 752 */ 753 ASSERT(AS_READ_HELD(seg->s_as, &seg->s_as->a_lock)); 754 hat = seg->s_as->a_hat; 755 cmn_err(CE_NOTE, "rootnex_map_fault: nil hat"); 756 } 757 hat_devload(hat, addr, MMU_PAGESIZE, pfn, prot | sdp->hat_attr, 758 (lock ? HAT_LOAD_LOCK : HAT_LOAD)); 759 } else if (seg == &kvseg && dp == (struct devpage *)0) { 760 hat_devload(kas.a_hat, addr, MMU_PAGESIZE, pfn, prot, 761 HAT_LOAD_LOCK); 762 } else 763 return (DDI_FAILURE); 764 return (DDI_SUCCESS); 765} 766 767/* 768 * Name a child of rootnex 769 * 770 * This may be called multiple times, independent of initchild calls. 771 */ 772int 773rootnex_name_child(dev_info_t *child, char *name, int namelen) 774{ 775 return (rootnex_name_child_impl(child, name, namelen)); 776} 777 778 779static int 780rootnex_ctl_initchild(dev_info_t *dip) 781{ 782 return (rootnex_ctl_initchild_impl(dip)); 783} 784 785 786int 787rootnex_ctl_uninitchild(dev_info_t *dip) 788{ 789 extern void impl_free_ddi_ppd(dev_info_t *); 790 791 rootnex_ctl_uninitchild_impl(dip); 792 793 /* 794 * strip properties and convert node to prototype form 795 */ 796 impl_free_ddi_ppd(dip); 797 ddi_set_name_addr(dip, NULL); 798 impl_rem_dev_props(dip); 799 return (DDI_SUCCESS); 800} 801 802 803static int 804rootnex_ctl_reportdev(dev_info_t *dev) 805{ 806 return (rootnex_ctl_reportdev_impl(dev)); 807} 808 809 810static int 811rootnex_ctlops_peekpoke(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args, 812 void *result) 813{ 814 int err = DDI_SUCCESS; 815 on_trap_data_t otd; 816 817 /* No safe access except for peek/poke is supported. */ 818 if (in_args->handle != NULL) 819 return (DDI_FAILURE); 820 821 /* Set up protected environment. */ 822 if (!on_trap(&otd, OT_DATA_ACCESS)) { 823 uintptr_t tramp = otd.ot_trampoline; 824 825 if (cmd == DDI_CTLOPS_POKE) { 826 otd.ot_trampoline = (uintptr_t)&poke_fault; 827 err = do_poke(in_args->size, (void *)in_args->dev_addr, 828 (void *)in_args->host_addr); 829 } else { 830 otd.ot_trampoline = (uintptr_t)&peek_fault; 831 err = do_peek(in_args->size, (void *)in_args->dev_addr, 832 (void *)in_args->host_addr); 833 result = (void *)in_args->host_addr; 834 } 835 otd.ot_trampoline = tramp; 836 } else 837 err = DDI_FAILURE; 838 839 /* Take down protected environment. */ 840 no_trap(); 841 842 return (err); 843} 844 845/*ARGSUSED*/ 846static int 847rootnex_ctlops(dev_info_t *dip, dev_info_t *rdip, 848 ddi_ctl_enum_t ctlop, void *arg, void *result) 849{ 850 register int n, *ptr; 851 register struct ddi_parent_private_data *pdp; 852 853 static boolean_t reserved_msg_printed = B_FALSE; 854 855 switch (ctlop) { 856 case DDI_CTLOPS_DMAPMAPC: 857 return (DDI_FAILURE); 858 859 case DDI_CTLOPS_BTOP: 860 /* 861 * Convert byte count input to physical page units. 862 * (byte counts that are not a page-size multiple 863 * are rounded down) 864 */ 865 *(ulong_t *)result = btop(*(ulong_t *)arg); 866 return (DDI_SUCCESS); 867 868 case DDI_CTLOPS_PTOB: 869 /* 870 * Convert size in physical pages to bytes 871 */ 872 *(ulong_t *)result = ptob(*(ulong_t *)arg); 873 return (DDI_SUCCESS); 874 875 case DDI_CTLOPS_BTOPR: 876 /* 877 * Convert byte count input to physical page units 878 * (byte counts that are not a page-size multiple 879 * are rounded up) 880 */ 881 *(ulong_t *)result = btopr(*(ulong_t *)arg); 882 return (DDI_SUCCESS); 883 884 case DDI_CTLOPS_INITCHILD: 885 return (rootnex_ctl_initchild((dev_info_t *)arg)); 886 887 case DDI_CTLOPS_UNINITCHILD: 888 return (rootnex_ctl_uninitchild((dev_info_t *)arg)); 889 890 case DDI_CTLOPS_REPORTDEV: 891 return (rootnex_ctl_reportdev(rdip)); 892 893 case DDI_CTLOPS_IOMIN: 894 /* 895 * Nothing to do here but reflect back.. 896 */ 897 return (DDI_SUCCESS); 898 899 case DDI_CTLOPS_REGSIZE: 900 case DDI_CTLOPS_NREGS: 901 break; 902 903 case DDI_CTLOPS_SIDDEV: 904 if (ndi_dev_is_prom_node(rdip)) 905 return (DDI_SUCCESS); 906 if (ndi_dev_is_persistent_node(rdip)) 907 return (DDI_SUCCESS); 908 return (DDI_FAILURE); 909 910 case DDI_CTLOPS_POWER: { 911 return ((*pm_platform_power)((power_req_t *)arg)); 912 } 913 914 case DDI_CTLOPS_RESERVED1: /* Was DDI_CTLOPS_POKE_INIT, obsolete */ 915 case DDI_CTLOPS_RESERVED2: /* Was DDI_CTLOPS_POKE_FLUSH, obsolete */ 916 case DDI_CTLOPS_RESERVED3: /* Was DDI_CTLOPS_POKE_FINI, obsolete */ 917 if (!reserved_msg_printed) { 918 reserved_msg_printed = B_TRUE; 919 cmn_err(CE_WARN, "Failing ddi_ctlops call(s) for " 920 "1 or more reserved/obsolete operations."); 921 } 922 return (DDI_FAILURE); 923 924 case DDI_CTLOPS_POKE: 925 case DDI_CTLOPS_PEEK: 926 return (rootnex_ctlops_peekpoke(ctlop, (peekpoke_ctlops_t *)arg, 927 result)); 928 929 default: 930 return (DDI_FAILURE); 931 } 932 933 /* 934 * The rest are for "hardware" properties 935 */ 936 if ((pdp = ddi_get_parent_data(rdip)) == NULL) 937 return (DDI_FAILURE); 938 939 if (ctlop == DDI_CTLOPS_NREGS) { 940 ptr = (int *)result; 941 *ptr = pdp->par_nreg; 942 } else if (ctlop == DDI_CTLOPS_NINTRS) { 943 return (DDI_FAILURE); 944 } else { /* ctlop == DDI_CTLOPS_REGSIZE */ 945 off_t *size = (off_t *)result; 946 947 ptr = (int *)arg; 948 n = *ptr; 949 if (n >= pdp->par_nreg) { 950 return (DDI_FAILURE); 951 } 952 *size = (off_t)pdp->par_reg[n].regspec_size; 953 } 954 return (DDI_SUCCESS); 955} 956 957/* ARGSUSED */ 958int 959rootnex_busop_fminit(dev_info_t *dip, dev_info_t *tdip, int cap, 960 ddi_iblock_cookie_t *ibc) 961{ 962 *ibc = rootnex_err_ibc; 963 return (ddi_system_fmcap | DDI_FM_ACCCHK_CAPABLE | 964 DDI_FM_DMACHK_CAPABLE); 965} 966 967static void 968rootnex_fm_init(dev_info_t *dip) 969{ 970 int fmcap; 971 972 /* Minimum fm capability level for sun4u platforms */ 973 ddi_system_fmcap = DDI_FM_EREPORT_CAPABLE | DDI_FM_ERRCB_CAPABLE; 974 975 fmcap = ddi_system_fmcap; 976 977 /* 978 * Initialize ECC error handling 979 */ 980 rootnex_err_ibc = (ddi_iblock_cookie_t)PIL_15; 981 ddi_fm_init(dip, &fmcap, &rootnex_err_ibc); 982} 983