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 2006 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 * PC specific DDI implementation 31 */ 32 #include <sys/types.h> 33 #include <sys/autoconf.h> 34 #include <sys/avintr.h> 35 #include <sys/bootconf.h> 36 #include <sys/conf.h> 37 #include <sys/cpuvar.h> 38 #include <sys/ddi_impldefs.h> 39 #include <sys/ddi_subrdefs.h> 40 #include <sys/ethernet.h> 41 #include <sys/fp.h> 42 #include <sys/instance.h> 43 #include <sys/kmem.h> 44 #include <sys/machsystm.h> 45 #include <sys/modctl.h> 46 #include <sys/promif.h> 47 #include <sys/prom_plat.h> 48 #include <sys/sunndi.h> 49 #include <sys/ndi_impldefs.h> 50 #include <sys/ddi_impldefs.h> 51 #include <sys/sysmacros.h> 52 #include <sys/systeminfo.h> 53 #include <sys/utsname.h> 54 #include <sys/atomic.h> 55 #include <sys/spl.h> 56 #include <sys/archsystm.h> 57 #include <vm/seg_kmem.h> 58 #include <sys/ontrap.h> 59 #include <sys/fm/protocol.h> 60 #include <sys/ramdisk.h> 61 #include <sys/sunndi.h> 62 #include <sys/vmem.h> 63 #include <sys/pci_impl.h> 64 #include <sys/mach_intr.h> 65 #include <vm/hat_i86.h> 66 #include <sys/x86_archext.h> 67 68 /* 69 * DDI Boot Configuration 70 */ 71 72 /* 73 * No platform drivers on this platform 74 */ 75 char *platform_module_list[] = { 76 (char *)0 77 }; 78 79 /* pci bus resource maps */ 80 struct pci_bus_resource *pci_bus_res; 81 82 extern int root_is_svm; 83 uint64_t ramdisk_start, ramdisk_end; 84 85 /* 86 * Forward declarations 87 */ 88 static int getlongprop_buf(); 89 static void get_boot_properties(void); 90 static void impl_bus_initialprobe(void); 91 static void impl_bus_reprobe(void); 92 93 static int poke_mem(peekpoke_ctlops_t *in_args); 94 static int peek_mem(peekpoke_ctlops_t *in_args); 95 96 static int kmem_override_cache_attrs(caddr_t, size_t, uint_t); 97 98 #define CTGENTRIES 15 99 100 static struct ctgas { 101 struct ctgas *ctg_next; 102 int ctg_index; 103 void *ctg_addr[CTGENTRIES]; 104 size_t ctg_size[CTGENTRIES]; 105 } ctglist; 106 107 static kmutex_t ctgmutex; 108 #define CTGLOCK() mutex_enter(&ctgmutex) 109 #define CTGUNLOCK() mutex_exit(&ctgmutex) 110 111 /* 112 * Minimum pfn value of page_t's put on the free list. This is to simplify 113 * support of ddi dma memory requests which specify small, non-zero addr_lo 114 * values. 115 * 116 * The default value of 2, which corresponds to the only known non-zero addr_lo 117 * value used, means a single page will be sacrificed (pfn typically starts 118 * at 1). ddiphysmin can be set to 0 to disable. It cannot be set above 0x100 119 * otherwise mp startup panics. 120 */ 121 pfn_t ddiphysmin = 2; 122 123 static void 124 check_driver_disable(void) 125 { 126 int proplen = 128; 127 char *prop_name; 128 char *drv_name, *propval; 129 major_t major; 130 131 prop_name = kmem_alloc(proplen, KM_SLEEP); 132 for (major = 0; major < devcnt; major++) { 133 drv_name = ddi_major_to_name(major); 134 if (drv_name == NULL) 135 continue; 136 (void) snprintf(prop_name, proplen, "disable-%s", drv_name); 137 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 138 DDI_PROP_DONTPASS, prop_name, &propval) == DDI_SUCCESS) { 139 if (strcmp(propval, "true") == 0) { 140 devnamesp[major].dn_flags |= DN_DRIVER_REMOVED; 141 cmn_err(CE_NOTE, "driver %s disabled", 142 drv_name); 143 } 144 ddi_prop_free(propval); 145 } 146 } 147 kmem_free(prop_name, proplen); 148 } 149 150 151 /* 152 * Configure the hardware on the system. 153 * Called before the rootfs is mounted 154 */ 155 void 156 configure(void) 157 { 158 extern void i_ddi_init_root(); 159 160 #if defined(__i386) 161 extern int fpu_pentium_fdivbug; 162 #endif /* __i386 */ 163 extern int fpu_ignored; 164 165 /* 166 * Determine if an FPU is attached 167 */ 168 169 fpu_probe(); 170 171 #if defined(__i386) 172 if (fpu_pentium_fdivbug) { 173 printf("\ 174 FP hardware exhibits Pentium floating point divide problem\n"); 175 } 176 #endif /* __i386 */ 177 178 if (fpu_ignored) { 179 printf("FP hardware will not be used\n"); 180 } else if (!fpu_exists) { 181 printf("No FPU in configuration\n"); 182 } 183 184 /* 185 * Initialize devices on the machine. 186 * Uses configuration tree built by the PROMs to determine what 187 * is present, and builds a tree of prototype dev_info nodes 188 * corresponding to the hardware which identified itself. 189 */ 190 #if !defined(SAS) && !defined(MPSAS) 191 /* 192 * Check for disabled drivers and initialize root node. 193 */ 194 check_driver_disable(); 195 i_ddi_init_root(); 196 197 /* 198 * attach the isa nexus to get ACPI resource usage 199 * isa is "kind of" a pseudo node 200 */ 201 (void) i_ddi_attach_pseudo_node("isa"); 202 203 /* reprogram devices not set up by firmware (BIOS) */ 204 impl_bus_reprobe(); 205 #endif /* !SAS && !MPSAS */ 206 } 207 208 /* 209 * The "status" property indicates the operational status of a device. 210 * If this property is present, the value is a string indicating the 211 * status of the device as follows: 212 * 213 * "okay" operational. 214 * "disabled" not operational, but might become operational. 215 * "fail" not operational because a fault has been detected, 216 * and it is unlikely that the device will become 217 * operational without repair. no additional details 218 * are available. 219 * "fail-xxx" not operational because a fault has been detected, 220 * and it is unlikely that the device will become 221 * operational without repair. "xxx" is additional 222 * human-readable information about the particular 223 * fault condition that was detected. 224 * 225 * The absence of this property means that the operational status is 226 * unknown or okay. 227 * 228 * This routine checks the status property of the specified device node 229 * and returns 0 if the operational status indicates failure, and 1 otherwise. 230 * 231 * The property may exist on plug-in cards the existed before IEEE 1275-1994. 232 * And, in that case, the property may not even be a string. So we carefully 233 * check for the value "fail", in the beginning of the string, noting 234 * the property length. 235 */ 236 int 237 status_okay(int id, char *buf, int buflen) 238 { 239 char status_buf[OBP_MAXPROPNAME]; 240 char *bufp = buf; 241 int len = buflen; 242 int proplen; 243 static const char *status = "status"; 244 static const char *fail = "fail"; 245 int fail_len = (int)strlen(fail); 246 247 /* 248 * Get the proplen ... if it's smaller than "fail", 249 * or doesn't exist ... then we don't care, since 250 * the value can't begin with the char string "fail". 251 * 252 * NB: proplen, if it's a string, includes the NULL in the 253 * the size of the property, and fail_len does not. 254 */ 255 proplen = prom_getproplen((pnode_t)id, (caddr_t)status); 256 if (proplen <= fail_len) /* nonexistant or uninteresting len */ 257 return (1); 258 259 /* 260 * if a buffer was provided, use it 261 */ 262 if ((buf == (char *)NULL) || (buflen <= 0)) { 263 bufp = status_buf; 264 len = sizeof (status_buf); 265 } 266 *bufp = (char)0; 267 268 /* 269 * Get the property into the buffer, to the extent of the buffer, 270 * and in case the buffer is smaller than the property size, 271 * NULL terminate the buffer. (This handles the case where 272 * a buffer was passed in and the caller wants to print the 273 * value, but the buffer was too small). 274 */ 275 (void) prom_bounded_getprop((pnode_t)id, (caddr_t)status, 276 (caddr_t)bufp, len); 277 *(bufp + len - 1) = (char)0; 278 279 /* 280 * If the value begins with the char string "fail", 281 * then it means the node is failed. We don't care 282 * about any other values. We assume the node is ok 283 * although it might be 'disabled'. 284 */ 285 if (strncmp(bufp, fail, fail_len) == 0) 286 return (0); 287 288 return (1); 289 } 290 291 /* 292 * Check the status of the device node passed as an argument. 293 * 294 * if ((status is OKAY) || (status is DISABLED)) 295 * return DDI_SUCCESS 296 * else 297 * print a warning and return DDI_FAILURE 298 */ 299 /*ARGSUSED1*/ 300 int 301 check_status(int id, char *name, dev_info_t *parent) 302 { 303 char status_buf[64]; 304 char devtype_buf[OBP_MAXPROPNAME]; 305 int retval = DDI_FAILURE; 306 307 /* 308 * is the status okay? 309 */ 310 if (status_okay(id, status_buf, sizeof (status_buf))) 311 return (DDI_SUCCESS); 312 313 /* 314 * a status property indicating bad memory will be associated 315 * with a node which has a "device_type" property with a value of 316 * "memory-controller". in this situation, return DDI_SUCCESS 317 */ 318 if (getlongprop_buf(id, OBP_DEVICETYPE, devtype_buf, 319 sizeof (devtype_buf)) > 0) { 320 if (strcmp(devtype_buf, "memory-controller") == 0) 321 retval = DDI_SUCCESS; 322 } 323 324 /* 325 * print the status property information 326 */ 327 cmn_err(CE_WARN, "status '%s' for '%s'", status_buf, name); 328 return (retval); 329 } 330 331 /*ARGSUSED*/ 332 uint_t 333 softlevel1(caddr_t arg1, caddr_t arg2) 334 { 335 softint(); 336 return (1); 337 } 338 339 /* 340 * Allow for implementation specific correction of PROM property values. 341 */ 342 343 /*ARGSUSED*/ 344 void 345 impl_fix_props(dev_info_t *dip, dev_info_t *ch_dip, char *name, int len, 346 caddr_t buffer) 347 { 348 /* 349 * There are no adjustments needed in this implementation. 350 */ 351 } 352 353 static int 354 getlongprop_buf(int id, char *name, char *buf, int maxlen) 355 { 356 int size; 357 358 size = prom_getproplen((pnode_t)id, name); 359 if (size <= 0 || (size > maxlen - 1)) 360 return (-1); 361 362 if (-1 == prom_getprop((pnode_t)id, name, buf)) 363 return (-1); 364 365 if (strcmp("name", name) == 0) { 366 if (buf[size - 1] != '\0') { 367 buf[size] = '\0'; 368 size += 1; 369 } 370 } 371 372 return (size); 373 } 374 375 static int 376 get_prop_int_array(dev_info_t *di, char *pname, int **pval, uint_t *plen) 377 { 378 int ret; 379 380 if ((ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, di, 381 DDI_PROP_DONTPASS, pname, pval, plen)) 382 == DDI_PROP_SUCCESS) { 383 *plen = (*plen) * (sizeof (int)); 384 } 385 return (ret); 386 } 387 388 389 /* 390 * Node Configuration 391 */ 392 393 struct prop_ispec { 394 uint_t pri, vec; 395 }; 396 397 /* 398 * For the x86, we're prepared to claim that the interrupt string 399 * is in the form of a list of <ipl,vec> specifications. 400 */ 401 402 #define VEC_MIN 1 403 #define VEC_MAX 255 404 405 static int 406 impl_xlate_intrs(dev_info_t *child, int *in, 407 struct ddi_parent_private_data *pdptr) 408 { 409 size_t size; 410 int n; 411 struct intrspec *new; 412 caddr_t got_prop; 413 int *inpri; 414 int got_len; 415 extern int ignore_hardware_nodes; /* force flag from ddi_impl.c */ 416 417 static char bad_intr_fmt[] = 418 "bad interrupt spec from %s%d - ipl %d, irq %d\n"; 419 420 /* 421 * determine if the driver is expecting the new style "interrupts" 422 * property which just contains the IRQ, or the old style which 423 * contains pairs of <IPL,IRQ>. if it is the new style, we always 424 * assign IPL 5 unless an "interrupt-priorities" property exists. 425 * in that case, the "interrupt-priorities" property contains the 426 * IPL values that match, one for one, the IRQ values in the 427 * "interrupts" property. 428 */ 429 inpri = NULL; 430 if ((ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 431 "ignore-hardware-nodes", -1) != -1) || ignore_hardware_nodes) { 432 /* the old style "interrupts" property... */ 433 434 /* 435 * The list consists of <ipl,vec> elements 436 */ 437 if ((n = (*in++ >> 1)) < 1) 438 return (DDI_FAILURE); 439 440 pdptr->par_nintr = n; 441 size = n * sizeof (struct intrspec); 442 new = pdptr->par_intr = kmem_zalloc(size, KM_SLEEP); 443 444 while (n--) { 445 int level = *in++; 446 int vec = *in++; 447 448 if (level < 1 || level > MAXIPL || 449 vec < VEC_MIN || vec > VEC_MAX) { 450 cmn_err(CE_CONT, bad_intr_fmt, 451 DEVI(child)->devi_name, 452 DEVI(child)->devi_instance, level, vec); 453 goto broken; 454 } 455 new->intrspec_pri = level; 456 if (vec != 2) 457 new->intrspec_vec = vec; 458 else 459 /* 460 * irq 2 on the PC bus is tied to irq 9 461 * on ISA, EISA and MicroChannel 462 */ 463 new->intrspec_vec = 9; 464 new++; 465 } 466 467 return (DDI_SUCCESS); 468 } else { 469 /* the new style "interrupts" property... */ 470 471 /* 472 * The list consists of <vec> elements 473 */ 474 if ((n = (*in++)) < 1) 475 return (DDI_FAILURE); 476 477 pdptr->par_nintr = n; 478 size = n * sizeof (struct intrspec); 479 new = pdptr->par_intr = kmem_zalloc(size, KM_SLEEP); 480 481 /* XXX check for "interrupt-priorities" property... */ 482 if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 483 "interrupt-priorities", (caddr_t)&got_prop, &got_len) 484 == DDI_PROP_SUCCESS) { 485 if (n != (got_len / sizeof (int))) { 486 cmn_err(CE_CONT, 487 "bad interrupt-priorities length" 488 " from %s%d: expected %d, got %d\n", 489 DEVI(child)->devi_name, 490 DEVI(child)->devi_instance, n, 491 (int)(got_len / sizeof (int))); 492 goto broken; 493 } 494 inpri = (int *)got_prop; 495 } 496 497 while (n--) { 498 int level; 499 int vec = *in++; 500 501 if (inpri == NULL) 502 level = 5; 503 else 504 level = *inpri++; 505 506 if (level < 1 || level > MAXIPL || 507 vec < VEC_MIN || vec > VEC_MAX) { 508 cmn_err(CE_CONT, bad_intr_fmt, 509 DEVI(child)->devi_name, 510 DEVI(child)->devi_instance, level, vec); 511 goto broken; 512 } 513 new->intrspec_pri = level; 514 if (vec != 2) 515 new->intrspec_vec = vec; 516 else 517 /* 518 * irq 2 on the PC bus is tied to irq 9 519 * on ISA, EISA and MicroChannel 520 */ 521 new->intrspec_vec = 9; 522 new++; 523 } 524 525 if (inpri != NULL) 526 kmem_free(got_prop, got_len); 527 return (DDI_SUCCESS); 528 } 529 530 broken: 531 kmem_free(pdptr->par_intr, size); 532 pdptr->par_intr = NULL; 533 pdptr->par_nintr = 0; 534 if (inpri != NULL) 535 kmem_free(got_prop, got_len); 536 537 return (DDI_FAILURE); 538 } 539 540 /* 541 * Create a ddi_parent_private_data structure from the ddi properties of 542 * the dev_info node. 543 * 544 * The "reg" and either an "intr" or "interrupts" properties are required 545 * if the driver wishes to create mappings or field interrupts on behalf 546 * of the device. 547 * 548 * The "reg" property is assumed to be a list of at least one triple 549 * 550 * <bustype, address, size>*1 551 * 552 * The "intr" property is assumed to be a list of at least one duple 553 * 554 * <SPARC ipl, vector#>*1 555 * 556 * The "interrupts" property is assumed to be a list of at least one 557 * n-tuples that describes the interrupt capabilities of the bus the device 558 * is connected to. For SBus, this looks like 559 * 560 * <SBus-level>*1 561 * 562 * (This property obsoletes the 'intr' property). 563 * 564 * The "ranges" property is optional. 565 */ 566 void 567 make_ddi_ppd(dev_info_t *child, struct ddi_parent_private_data **ppd) 568 { 569 struct ddi_parent_private_data *pdptr; 570 int n; 571 int *reg_prop, *rng_prop, *intr_prop, *irupts_prop; 572 uint_t reg_len, rng_len, intr_len, irupts_len; 573 574 *ppd = pdptr = kmem_zalloc(sizeof (*pdptr), KM_SLEEP); 575 576 /* 577 * Handle the 'reg' property. 578 */ 579 if ((get_prop_int_array(child, "reg", ®_prop, ®_len) == 580 DDI_PROP_SUCCESS) && (reg_len != 0)) { 581 pdptr->par_nreg = reg_len / (int)sizeof (struct regspec); 582 pdptr->par_reg = (struct regspec *)reg_prop; 583 } 584 585 /* 586 * See if I have a range (adding one where needed - this 587 * means to add one for sbus node in sun4c, when romvec > 0, 588 * if no range is already defined in the PROM node. 589 * (Currently no sun4c PROMS define range properties, 590 * but they should and may in the future.) For the SBus 591 * node, the range is defined by the SBus reg property. 592 */ 593 if (get_prop_int_array(child, "ranges", &rng_prop, &rng_len) 594 == DDI_PROP_SUCCESS) { 595 pdptr->par_nrng = rng_len / (int)(sizeof (struct rangespec)); 596 pdptr->par_rng = (struct rangespec *)rng_prop; 597 } 598 599 /* 600 * Handle the 'intr' and 'interrupts' properties 601 */ 602 603 /* 604 * For backwards compatibility 605 * we first look for the 'intr' property for the device. 606 */ 607 if (get_prop_int_array(child, "intr", &intr_prop, &intr_len) 608 != DDI_PROP_SUCCESS) { 609 intr_len = 0; 610 } 611 612 /* 613 * If we're to support bus adapters and future platforms cleanly, 614 * we need to support the generalized 'interrupts' property. 615 */ 616 if (get_prop_int_array(child, "interrupts", &irupts_prop, 617 &irupts_len) != DDI_PROP_SUCCESS) { 618 irupts_len = 0; 619 } else if (intr_len != 0) { 620 /* 621 * If both 'intr' and 'interrupts' are defined, 622 * then 'interrupts' wins and we toss the 'intr' away. 623 */ 624 ddi_prop_free((void *)intr_prop); 625 intr_len = 0; 626 } 627 628 if (intr_len != 0) { 629 630 /* 631 * Translate the 'intr' property into an array 632 * an array of struct intrspec's. There's not really 633 * very much to do here except copy what's out there. 634 */ 635 636 struct intrspec *new; 637 struct prop_ispec *l; 638 639 n = pdptr->par_nintr = 640 intr_len / sizeof (struct prop_ispec); 641 l = (struct prop_ispec *)intr_prop; 642 pdptr->par_intr = 643 new = kmem_zalloc(n * sizeof (struct intrspec), KM_SLEEP); 644 while (n--) { 645 new->intrspec_pri = l->pri; 646 new->intrspec_vec = l->vec; 647 new++; 648 l++; 649 } 650 ddi_prop_free((void *)intr_prop); 651 652 } else if ((n = irupts_len) != 0) { 653 size_t size; 654 int *out; 655 656 /* 657 * Translate the 'interrupts' property into an array 658 * of intrspecs for the rest of the DDI framework to 659 * toy with. Only our ancestors really know how to 660 * do this, so ask 'em. We massage the 'interrupts' 661 * property so that it is pre-pended by a count of 662 * the number of integers in the argument. 663 */ 664 size = sizeof (int) + n; 665 out = kmem_alloc(size, KM_SLEEP); 666 *out = n / sizeof (int); 667 bcopy(irupts_prop, out + 1, (size_t)n); 668 ddi_prop_free((void *)irupts_prop); 669 if (impl_xlate_intrs(child, out, pdptr) != DDI_SUCCESS) { 670 cmn_err(CE_CONT, 671 "Unable to translate 'interrupts' for %s%d\n", 672 DEVI(child)->devi_binding_name, 673 DEVI(child)->devi_instance); 674 } 675 kmem_free(out, size); 676 } 677 } 678 679 /* 680 * Name a child 681 */ 682 static int 683 impl_sunbus_name_child(dev_info_t *child, char *name, int namelen) 684 { 685 /* 686 * Fill in parent-private data and this function returns to us 687 * an indication if it used "registers" to fill in the data. 688 */ 689 if (ddi_get_parent_data(child) == NULL) { 690 struct ddi_parent_private_data *pdptr; 691 make_ddi_ppd(child, &pdptr); 692 ddi_set_parent_data(child, pdptr); 693 } 694 695 name[0] = '\0'; 696 if (sparc_pd_getnreg(child) > 0) { 697 (void) snprintf(name, namelen, "%x,%x", 698 (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype, 699 (uint_t)sparc_pd_getreg(child, 0)->regspec_addr); 700 } 701 702 return (DDI_SUCCESS); 703 } 704 705 /* 706 * Called from the bus_ctl op of sunbus (sbus, obio, etc) nexus drivers 707 * to implement the DDI_CTLOPS_INITCHILD operation. That is, it names 708 * the children of sun busses based on the reg spec. 709 * 710 * Handles the following properties (in make_ddi_ppd): 711 * Property value 712 * Name type 713 * reg register spec 714 * intr old-form interrupt spec 715 * interrupts new (bus-oriented) interrupt spec 716 * ranges range spec 717 */ 718 int 719 impl_ddi_sunbus_initchild(dev_info_t *child) 720 { 721 char name[MAXNAMELEN]; 722 void impl_ddi_sunbus_removechild(dev_info_t *); 723 724 /* 725 * Name the child, also makes parent private data 726 */ 727 (void) impl_sunbus_name_child(child, name, MAXNAMELEN); 728 ddi_set_name_addr(child, name); 729 730 /* 731 * Attempt to merge a .conf node; if successful, remove the 732 * .conf node. 733 */ 734 if ((ndi_dev_is_persistent_node(child) == 0) && 735 (ndi_merge_node(child, impl_sunbus_name_child) == DDI_SUCCESS)) { 736 /* 737 * Return failure to remove node 738 */ 739 impl_ddi_sunbus_removechild(child); 740 return (DDI_FAILURE); 741 } 742 return (DDI_SUCCESS); 743 } 744 745 void 746 impl_free_ddi_ppd(dev_info_t *dip) 747 { 748 struct ddi_parent_private_data *pdptr; 749 size_t n; 750 751 if ((pdptr = ddi_get_parent_data(dip)) == NULL) 752 return; 753 754 if ((n = (size_t)pdptr->par_nintr) != 0) 755 /* 756 * Note that kmem_free is used here (instead of 757 * ddi_prop_free) because the contents of the 758 * property were placed into a separate buffer and 759 * mucked with a bit before being stored in par_intr. 760 * The actual return value from the prop lookup 761 * was freed with ddi_prop_free previously. 762 */ 763 kmem_free(pdptr->par_intr, n * sizeof (struct intrspec)); 764 765 if ((n = (size_t)pdptr->par_nrng) != 0) 766 ddi_prop_free((void *)pdptr->par_rng); 767 768 if ((n = pdptr->par_nreg) != 0) 769 ddi_prop_free((void *)pdptr->par_reg); 770 771 kmem_free(pdptr, sizeof (*pdptr)); 772 ddi_set_parent_data(dip, NULL); 773 } 774 775 void 776 impl_ddi_sunbus_removechild(dev_info_t *dip) 777 { 778 impl_free_ddi_ppd(dip); 779 ddi_set_name_addr(dip, NULL); 780 /* 781 * Strip the node to properly convert it back to prototype form 782 */ 783 impl_rem_dev_props(dip); 784 } 785 786 /* 787 * DDI Interrupt 788 */ 789 790 /* 791 * turn this on to force isa, eisa, and mca device to ignore the new 792 * hardware nodes in the device tree (normally turned on only for 793 * drivers that need it by setting the property "ignore-hardware-nodes" 794 * in their driver.conf file). 795 * 796 * 7/31/96 -- Turned off globally. Leaving variable in for the moment 797 * as safety valve. 798 */ 799 int ignore_hardware_nodes = 0; 800 801 /* 802 * Local data 803 */ 804 static struct impl_bus_promops *impl_busp; 805 806 807 /* 808 * New DDI interrupt framework 809 */ 810 811 /* 812 * i_ddi_intr_ops: 813 * 814 * This is the interrupt operator function wrapper for the bus function 815 * bus_intr_op. 816 */ 817 int 818 i_ddi_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op, 819 ddi_intr_handle_impl_t *hdlp, void * result) 820 { 821 dev_info_t *pdip = (dev_info_t *)DEVI(dip)->devi_parent; 822 int ret = DDI_FAILURE; 823 824 /* request parent to process this interrupt op */ 825 if (NEXUS_HAS_INTR_OP(pdip)) 826 ret = (*(DEVI(pdip)->devi_ops->devo_bus_ops->bus_intr_op))( 827 pdip, rdip, op, hdlp, result); 828 else 829 cmn_err(CE_WARN, "Failed to process interrupt " 830 "for %s%d due to down-rev nexus driver %s%d", 831 ddi_get_name(rdip), ddi_get_instance(rdip), 832 ddi_get_name(pdip), ddi_get_instance(pdip)); 833 return (ret); 834 } 835 836 /* 837 * i_ddi_add_softint - allocate and add a soft interrupt to the system 838 */ 839 int 840 i_ddi_add_softint(ddi_softint_hdl_impl_t *hdlp) 841 { 842 int ret; 843 844 /* add soft interrupt handler */ 845 ret = add_avsoftintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func, 846 DEVI(hdlp->ih_dip)->devi_name, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 847 return (ret ? DDI_SUCCESS : DDI_FAILURE); 848 } 849 850 851 void 852 i_ddi_remove_softint(ddi_softint_hdl_impl_t *hdlp) 853 { 854 (void) rem_avsoftintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func); 855 } 856 857 858 extern void (*setsoftint)(int, struct av_softinfo *); 859 extern boolean_t av_check_softint_pending(struct av_softinfo *, boolean_t); 860 861 int 862 i_ddi_trigger_softint(ddi_softint_hdl_impl_t *hdlp, void *arg2) 863 { 864 if (av_check_softint_pending(hdlp->ih_pending, B_FALSE)) 865 return (DDI_EPENDING); 866 867 update_avsoftintr_args((void *)hdlp, hdlp->ih_pri, arg2); 868 869 (*setsoftint)(hdlp->ih_pri, hdlp->ih_pending); 870 return (DDI_SUCCESS); 871 } 872 873 /* 874 * i_ddi_set_softint_pri: 875 * 876 * The way this works is that it first tries to add a softint vector 877 * at the new priority in hdlp. If that succeeds; then it removes the 878 * existing softint vector at the old priority. 879 */ 880 int 881 i_ddi_set_softint_pri(ddi_softint_hdl_impl_t *hdlp, uint_t old_pri) 882 { 883 int ret; 884 885 /* 886 * If a softint is pending at the old priority then fail the request. 887 */ 888 if (av_check_softint_pending(hdlp->ih_pending, B_TRUE)) 889 return (DDI_FAILURE); 890 891 ret = av_softint_movepri((void *)hdlp, old_pri); 892 return (ret ? DDI_SUCCESS : DDI_FAILURE); 893 } 894 895 void 896 i_ddi_alloc_intr_phdl(ddi_intr_handle_impl_t *hdlp) 897 { 898 hdlp->ih_private = (void *)kmem_zalloc(sizeof (ihdl_plat_t), KM_SLEEP); 899 } 900 901 void 902 i_ddi_free_intr_phdl(ddi_intr_handle_impl_t *hdlp) 903 { 904 kmem_free(hdlp->ih_private, sizeof (ihdl_plat_t)); 905 hdlp->ih_private = NULL; 906 } 907 908 /* 909 * DDI Memory/DMA 910 */ 911 912 /* 913 * Support for allocating DMAable memory to implement 914 * ddi_dma_mem_alloc(9F) interface. 915 */ 916 917 #define KA_ALIGN_SHIFT 7 918 #define KA_ALIGN (1 << KA_ALIGN_SHIFT) 919 #define KA_NCACHE (PAGESHIFT + 1 - KA_ALIGN_SHIFT) 920 921 /* 922 * Dummy DMA attribute template for kmem_io[].kmem_io_attr. We only 923 * care about addr_lo, addr_hi, and align. addr_hi will be dynamically set. 924 */ 925 926 static ddi_dma_attr_t kmem_io_attr = { 927 DMA_ATTR_V0, 928 0x0000000000000000ULL, /* dma_attr_addr_lo */ 929 0x0000000000000000ULL, /* dma_attr_addr_hi */ 930 0x00ffffff, 931 0x1000, /* dma_attr_align */ 932 1, 1, 0xffffffffULL, 0xffffffffULL, 0x1, 1, 0 933 }; 934 935 /* kmem io memory ranges and indices */ 936 enum { 937 IO_4P, IO_64G, IO_4G, IO_2G, IO_1G, IO_512M, 938 IO_256M, IO_128M, IO_64M, IO_32M, IO_16M, MAX_MEM_RANGES 939 }; 940 941 static struct { 942 vmem_t *kmem_io_arena; 943 kmem_cache_t *kmem_io_cache[KA_NCACHE]; 944 ddi_dma_attr_t kmem_io_attr; 945 } kmem_io[MAX_MEM_RANGES]; 946 947 static int kmem_io_idx; /* index of first populated kmem_io[] */ 948 949 static page_t * 950 page_create_io_wrapper(void *addr, size_t len, int vmflag, void *arg) 951 { 952 extern page_t *page_create_io(vnode_t *, u_offset_t, uint_t, 953 uint_t, struct as *, caddr_t, ddi_dma_attr_t *); 954 955 return (page_create_io(&kvp, (u_offset_t)(uintptr_t)addr, len, 956 PG_EXCL | ((vmflag & VM_NOSLEEP) ? 0 : PG_WAIT), &kas, addr, arg)); 957 } 958 959 static void * 960 segkmem_alloc_io_4P(vmem_t *vmp, size_t size, int vmflag) 961 { 962 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 963 page_create_io_wrapper, &kmem_io[IO_4P].kmem_io_attr)); 964 } 965 966 static void * 967 segkmem_alloc_io_64G(vmem_t *vmp, size_t size, int vmflag) 968 { 969 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 970 page_create_io_wrapper, &kmem_io[IO_64G].kmem_io_attr)); 971 } 972 973 static void * 974 segkmem_alloc_io_4G(vmem_t *vmp, size_t size, int vmflag) 975 { 976 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 977 page_create_io_wrapper, &kmem_io[IO_4G].kmem_io_attr)); 978 } 979 980 static void * 981 segkmem_alloc_io_2G(vmem_t *vmp, size_t size, int vmflag) 982 { 983 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 984 page_create_io_wrapper, &kmem_io[IO_2G].kmem_io_attr)); 985 } 986 987 static void * 988 segkmem_alloc_io_1G(vmem_t *vmp, size_t size, int vmflag) 989 { 990 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 991 page_create_io_wrapper, &kmem_io[IO_1G].kmem_io_attr)); 992 } 993 994 static void * 995 segkmem_alloc_io_512M(vmem_t *vmp, size_t size, int vmflag) 996 { 997 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 998 page_create_io_wrapper, &kmem_io[IO_512M].kmem_io_attr)); 999 } 1000 1001 static void * 1002 segkmem_alloc_io_256M(vmem_t *vmp, size_t size, int vmflag) 1003 { 1004 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 1005 page_create_io_wrapper, &kmem_io[IO_256M].kmem_io_attr)); 1006 } 1007 1008 static void * 1009 segkmem_alloc_io_128M(vmem_t *vmp, size_t size, int vmflag) 1010 { 1011 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 1012 page_create_io_wrapper, &kmem_io[IO_128M].kmem_io_attr)); 1013 } 1014 1015 static void * 1016 segkmem_alloc_io_64M(vmem_t *vmp, size_t size, int vmflag) 1017 { 1018 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 1019 page_create_io_wrapper, &kmem_io[IO_64M].kmem_io_attr)); 1020 } 1021 1022 static void * 1023 segkmem_alloc_io_32M(vmem_t *vmp, size_t size, int vmflag) 1024 { 1025 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 1026 page_create_io_wrapper, &kmem_io[IO_32M].kmem_io_attr)); 1027 } 1028 1029 static void * 1030 segkmem_alloc_io_16M(vmem_t *vmp, size_t size, int vmflag) 1031 { 1032 return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 1033 page_create_io_wrapper, &kmem_io[IO_16M].kmem_io_attr)); 1034 } 1035 1036 struct { 1037 uint64_t io_limit; 1038 char *io_name; 1039 void *(*io_alloc)(vmem_t *, size_t, int); 1040 int io_initial; /* kmem_io_init during startup */ 1041 } io_arena_params[MAX_MEM_RANGES] = { 1042 {0x000fffffffffffffULL, "kmem_io_4P", segkmem_alloc_io_4P, 1}, 1043 {0x0000000fffffffffULL, "kmem_io_64G", segkmem_alloc_io_64G, 0}, 1044 {0x00000000ffffffffULL, "kmem_io_4G", segkmem_alloc_io_4G, 1}, 1045 {0x000000007fffffffULL, "kmem_io_2G", segkmem_alloc_io_2G, 1}, 1046 {0x000000003fffffffULL, "kmem_io_1G", segkmem_alloc_io_1G, 0}, 1047 {0x000000001fffffffULL, "kmem_io_512M", segkmem_alloc_io_512M, 0}, 1048 {0x000000000fffffffULL, "kmem_io_256M", segkmem_alloc_io_256M, 0}, 1049 {0x0000000007ffffffULL, "kmem_io_128M", segkmem_alloc_io_128M, 0}, 1050 {0x0000000003ffffffULL, "kmem_io_64M", segkmem_alloc_io_64M, 0}, 1051 {0x0000000001ffffffULL, "kmem_io_32M", segkmem_alloc_io_32M, 0}, 1052 {0x0000000000ffffffULL, "kmem_io_16M", segkmem_alloc_io_16M, 1} 1053 }; 1054 1055 void 1056 kmem_io_init(int a) 1057 { 1058 int c; 1059 char name[40]; 1060 1061 kmem_io[a].kmem_io_arena = vmem_create(io_arena_params[a].io_name, 1062 NULL, 0, PAGESIZE, io_arena_params[a].io_alloc, 1063 segkmem_free, heap_arena, 0, VM_SLEEP); 1064 for (c = 0; c < KA_NCACHE; c++) { 1065 size_t size = KA_ALIGN << c; 1066 (void) sprintf(name, "%s_%lu", 1067 io_arena_params[a].io_name, size); 1068 kmem_io[a].kmem_io_cache[c] = kmem_cache_create(name, 1069 size, size, NULL, NULL, NULL, NULL, 1070 kmem_io[a].kmem_io_arena, 0); 1071 } 1072 } 1073 1074 /* 1075 * Return the index of the highest memory range for addr. 1076 */ 1077 static int 1078 kmem_io_index(uint64_t addr) 1079 { 1080 int n; 1081 1082 for (n = kmem_io_idx; n < MAX_MEM_RANGES; n++) { 1083 if (kmem_io[n].kmem_io_attr.dma_attr_addr_hi <= addr) { 1084 if (kmem_io[n].kmem_io_arena == NULL) 1085 kmem_io_init(n); 1086 return (n); 1087 } 1088 } 1089 panic("kmem_io_index: invalid addr - must be at least 16m"); 1090 1091 /*NOTREACHED*/ 1092 } 1093 1094 /* 1095 * Return the index of the next kmem_io populated memory range 1096 * after curindex. 1097 */ 1098 static int 1099 kmem_io_index_next(int curindex) 1100 { 1101 int n; 1102 1103 for (n = curindex + 1; n < MAX_MEM_RANGES; n++) { 1104 if (kmem_io[n].kmem_io_arena) 1105 return (n); 1106 } 1107 return (-1); 1108 } 1109 1110 /* 1111 * allow kmem to be mapped in with different PTE cache attribute settings. 1112 * Used by i_ddi_mem_alloc() 1113 */ 1114 int 1115 kmem_override_cache_attrs(caddr_t kva, size_t size, uint_t order) 1116 { 1117 uint_t hat_flags; 1118 caddr_t kva_end; 1119 uint_t hat_attr; 1120 pfn_t pfn; 1121 1122 if (hat_getattr(kas.a_hat, kva, &hat_attr) == -1) { 1123 return (-1); 1124 } 1125 1126 hat_attr &= ~HAT_ORDER_MASK; 1127 hat_attr |= order | HAT_NOSYNC; 1128 hat_flags = HAT_LOAD_LOCK; 1129 1130 kva_end = (caddr_t)(((uintptr_t)kva + size + PAGEOFFSET) & 1131 (uintptr_t)PAGEMASK); 1132 kva = (caddr_t)((uintptr_t)kva & (uintptr_t)PAGEMASK); 1133 1134 while (kva < kva_end) { 1135 pfn = hat_getpfnum(kas.a_hat, kva); 1136 hat_unload(kas.a_hat, kva, PAGESIZE, HAT_UNLOAD_UNLOCK); 1137 hat_devload(kas.a_hat, kva, PAGESIZE, pfn, hat_attr, hat_flags); 1138 kva += MMU_PAGESIZE; 1139 } 1140 1141 return (0); 1142 } 1143 1144 void 1145 ka_init(void) 1146 { 1147 int a; 1148 extern pfn_t physmax; 1149 uint64_t maxphysaddr = mmu_ptob((uint64_t)physmax + 1) - 1; 1150 1151 ASSERT(maxphysaddr <= io_arena_params[0].io_limit); 1152 1153 for (a = 0; a < MAX_MEM_RANGES; a++) { 1154 if (maxphysaddr >= io_arena_params[a + 1].io_limit) { 1155 if (maxphysaddr > io_arena_params[a + 1].io_limit) 1156 io_arena_params[a].io_limit = maxphysaddr; 1157 else 1158 a++; 1159 break; 1160 } 1161 } 1162 kmem_io_idx = a; 1163 1164 for (; a < MAX_MEM_RANGES; a++) { 1165 kmem_io[a].kmem_io_attr = kmem_io_attr; 1166 kmem_io[a].kmem_io_attr.dma_attr_addr_hi = 1167 io_arena_params[a].io_limit; 1168 /* 1169 * initialize kmem_io[] arena/cache corresponding to 1170 * maxphysaddr and to the "common" io memory ranges that 1171 * have io_initial set to a non-zero value. 1172 */ 1173 if (io_arena_params[a].io_initial || a == kmem_io_idx) 1174 kmem_io_init(a); 1175 } 1176 } 1177 1178 /* 1179 * put contig address/size 1180 */ 1181 static void * 1182 putctgas(void *addr, size_t size) 1183 { 1184 struct ctgas *ctgp = &ctglist; 1185 int i; 1186 1187 CTGLOCK(); 1188 do { 1189 if ((i = ctgp->ctg_index) < CTGENTRIES) { 1190 ctgp->ctg_addr[i] = addr; 1191 ctgp->ctg_size[i] = size; 1192 ctgp->ctg_index++; 1193 break; 1194 } 1195 if (!ctgp->ctg_next) 1196 ctgp->ctg_next = kmem_zalloc(sizeof (struct ctgas), 1197 KM_NOSLEEP); 1198 ctgp = ctgp->ctg_next; 1199 } while (ctgp); 1200 1201 CTGUNLOCK(); 1202 return (ctgp); 1203 } 1204 1205 /* 1206 * get contig size by addr 1207 */ 1208 static size_t 1209 getctgsz(void *addr) 1210 { 1211 struct ctgas *ctgp = &ctglist; 1212 int i, j; 1213 size_t sz; 1214 1215 ASSERT(addr); 1216 CTGLOCK(); 1217 1218 while (ctgp) { 1219 for (i = 0; i < ctgp->ctg_index; i++) { 1220 if (addr != ctgp->ctg_addr[i]) 1221 continue; 1222 1223 sz = ctgp->ctg_size[i]; 1224 j = --ctgp->ctg_index; 1225 if (i != j) { 1226 ctgp->ctg_size[i] = ctgp->ctg_size[j]; 1227 ctgp->ctg_addr[i] = ctgp->ctg_addr[j]; 1228 } 1229 CTGUNLOCK(); 1230 return (sz); 1231 } 1232 ctgp = ctgp->ctg_next; 1233 } 1234 1235 CTGUNLOCK(); 1236 return (0); 1237 } 1238 1239 /* 1240 * contig_alloc: 1241 * 1242 * allocates contiguous memory to satisfy the 'size' and dma attributes 1243 * specified in 'attr'. 1244 * 1245 * Not all of memory need to be physically contiguous if the 1246 * scatter-gather list length is greater than 1. 1247 */ 1248 1249 /*ARGSUSED*/ 1250 void * 1251 contig_alloc(size_t size, ddi_dma_attr_t *attr, uintptr_t align, int cansleep) 1252 { 1253 pgcnt_t pgcnt = btopr(size); 1254 size_t asize = pgcnt * PAGESIZE; 1255 page_t *ppl; 1256 int pflag; 1257 void *addr; 1258 1259 extern page_t *page_create_io(vnode_t *, u_offset_t, uint_t, 1260 uint_t, struct as *, caddr_t, ddi_dma_attr_t *); 1261 1262 /* segkmem_xalloc */ 1263 1264 if (align <= PAGESIZE) 1265 addr = vmem_alloc(heap_arena, asize, 1266 (cansleep) ? VM_SLEEP : VM_NOSLEEP); 1267 else 1268 addr = vmem_xalloc(heap_arena, asize, align, 0, 0, NULL, NULL, 1269 (cansleep) ? VM_SLEEP : VM_NOSLEEP); 1270 if (addr) { 1271 ASSERT(!((uintptr_t)addr & (align - 1))); 1272 1273 if (page_resv(pgcnt, 1274 (cansleep) ? KM_SLEEP : KM_NOSLEEP) == 0) { 1275 1276 vmem_free(heap_arena, addr, asize); 1277 return (NULL); 1278 } 1279 pflag = PG_EXCL; 1280 1281 if (cansleep) 1282 pflag |= PG_WAIT; 1283 1284 /* 4k req gets from freelists rather than pfn search */ 1285 if (pgcnt > 1 || align > PAGESIZE) 1286 pflag |= PG_PHYSCONTIG; 1287 1288 ppl = page_create_io(&kvp, (u_offset_t)(uintptr_t)addr, 1289 asize, pflag, &kas, (caddr_t)addr, attr); 1290 1291 if (!ppl) { 1292 vmem_free(heap_arena, addr, asize); 1293 page_unresv(pgcnt); 1294 return (NULL); 1295 } 1296 1297 while (ppl != NULL) { 1298 page_t *pp = ppl; 1299 page_sub(&ppl, pp); 1300 ASSERT(page_iolock_assert(pp)); 1301 page_io_unlock(pp); 1302 page_downgrade(pp); 1303 hat_memload(kas.a_hat, (caddr_t)(uintptr_t)pp->p_offset, 1304 pp, (PROT_ALL & ~PROT_USER) | 1305 HAT_NOSYNC, HAT_LOAD_LOCK); 1306 } 1307 } 1308 return (addr); 1309 } 1310 1311 static void 1312 contig_free(void *addr, size_t size) 1313 { 1314 pgcnt_t pgcnt = btopr(size); 1315 size_t asize = pgcnt * PAGESIZE; 1316 caddr_t a, ea; 1317 page_t *pp; 1318 1319 hat_unload(kas.a_hat, addr, asize, HAT_UNLOAD_UNLOCK); 1320 1321 for (a = addr, ea = a + asize; a < ea; a += PAGESIZE) { 1322 pp = page_find(&kvp, 1323 (u_offset_t)(uintptr_t)a); 1324 if (!pp) 1325 panic("contig_free: contig pp not found"); 1326 1327 if (!page_tryupgrade(pp)) { 1328 page_unlock(pp); 1329 pp = page_lookup(&kvp, 1330 (u_offset_t)(uintptr_t)a, SE_EXCL); 1331 if (pp == NULL) 1332 panic("contig_free: page freed"); 1333 } 1334 page_destroy(pp, 0); 1335 } 1336 1337 page_unresv(pgcnt); 1338 vmem_free(heap_arena, addr, asize); 1339 } 1340 1341 /* 1342 * Allocate from the system, aligned on a specific boundary. 1343 * The alignment, if non-zero, must be a power of 2. 1344 */ 1345 static void * 1346 kalloca(size_t size, size_t align, int cansleep, int physcontig, 1347 ddi_dma_attr_t *attr) 1348 { 1349 size_t *addr, *raddr, rsize; 1350 size_t hdrsize = 4 * sizeof (size_t); /* must be power of 2 */ 1351 int a, i, c; 1352 vmem_t *vmp; 1353 kmem_cache_t *cp = NULL; 1354 1355 if (attr->dma_attr_addr_lo > mmu_ptob((uint64_t)ddiphysmin)) 1356 return (NULL); 1357 1358 align = MAX(align, hdrsize); 1359 ASSERT((align & (align - 1)) == 0); 1360 1361 /* 1362 * All of our allocators guarantee 16-byte alignment, so we don't 1363 * need to reserve additional space for the header. 1364 * To simplify picking the correct kmem_io_cache, we round up to 1365 * a multiple of KA_ALIGN. 1366 */ 1367 rsize = P2ROUNDUP_TYPED(size + align, KA_ALIGN, size_t); 1368 1369 if (physcontig && rsize > PAGESIZE) { 1370 if (addr = contig_alloc(size, attr, align, cansleep)) { 1371 if (!putctgas(addr, size)) 1372 contig_free(addr, size); 1373 else 1374 return (addr); 1375 } 1376 return (NULL); 1377 } 1378 1379 a = kmem_io_index(attr->dma_attr_addr_hi); 1380 1381 if (rsize > PAGESIZE) { 1382 vmp = kmem_io[a].kmem_io_arena; 1383 raddr = vmem_alloc(vmp, rsize, 1384 (cansleep) ? VM_SLEEP : VM_NOSLEEP); 1385 } else { 1386 c = highbit((rsize >> KA_ALIGN_SHIFT) - 1); 1387 cp = kmem_io[a].kmem_io_cache[c]; 1388 raddr = kmem_cache_alloc(cp, (cansleep) ? KM_SLEEP : 1389 KM_NOSLEEP); 1390 } 1391 1392 if (raddr == NULL) { 1393 int na; 1394 1395 ASSERT(cansleep == 0); 1396 if (rsize > PAGESIZE) 1397 return (NULL); 1398 /* 1399 * System does not have memory in the requested range. 1400 * Try smaller kmem io ranges and larger cache sizes 1401 * to see if there might be memory available in 1402 * these other caches. 1403 */ 1404 1405 for (na = kmem_io_index_next(a); na >= 0; 1406 na = kmem_io_index_next(na)) { 1407 ASSERT(kmem_io[na].kmem_io_arena); 1408 cp = kmem_io[na].kmem_io_cache[c]; 1409 raddr = kmem_cache_alloc(cp, KM_NOSLEEP); 1410 if (raddr) 1411 goto kallocdone; 1412 } 1413 /* now try the larger kmem io cache sizes */ 1414 for (na = a; na >= 0; na = kmem_io_index_next(na)) { 1415 for (i = c + 1; i < KA_NCACHE; i++) { 1416 cp = kmem_io[na].kmem_io_cache[i]; 1417 raddr = kmem_cache_alloc(cp, KM_NOSLEEP); 1418 if (raddr) 1419 goto kallocdone; 1420 } 1421 } 1422 return (NULL); 1423 } 1424 1425 kallocdone: 1426 ASSERT(!P2CROSS((uintptr_t)raddr, (uintptr_t)raddr + rsize - 1, 1427 PAGESIZE) || rsize > PAGESIZE); 1428 1429 addr = (size_t *)P2ROUNDUP((uintptr_t)raddr + hdrsize, align); 1430 ASSERT((uintptr_t)addr + size - (uintptr_t)raddr <= rsize); 1431 1432 addr[-4] = (size_t)cp; 1433 addr[-3] = (size_t)vmp; 1434 addr[-2] = (size_t)raddr; 1435 addr[-1] = rsize; 1436 1437 return (addr); 1438 } 1439 1440 static void 1441 kfreea(void *addr) 1442 { 1443 size_t size; 1444 1445 if (!((uintptr_t)addr & PAGEOFFSET) && (size = getctgsz(addr))) { 1446 contig_free(addr, size); 1447 } else { 1448 size_t *saddr = addr; 1449 if (saddr[-4] == 0) 1450 vmem_free((vmem_t *)saddr[-3], (void *)saddr[-2], 1451 saddr[-1]); 1452 else 1453 kmem_cache_free((kmem_cache_t *)saddr[-4], 1454 (void *)saddr[-2]); 1455 } 1456 } 1457 1458 /* 1459 * Check if the endianess attribute is supported on the platform. 1460 * This function must be called before i_ddi_devacc_to_hatacc(). 1461 */ 1462 boolean_t 1463 i_ddi_check_endian_attr(ddi_device_acc_attr_t *devaccp) 1464 { 1465 /* 1466 * Big endianess is not supported on X86. 1467 */ 1468 if (devaccp != NULL && 1469 devaccp->devacc_attr_endian_flags == DDI_STRUCTURE_BE_ACC) 1470 return (B_FALSE); 1471 1472 return (B_TRUE); 1473 } 1474 1475 /* set HAT endianess attributes from ddi_device_acc_attr */ 1476 void 1477 i_ddi_devacc_to_hatacc(ddi_device_acc_attr_t *devaccp, uint_t *hataccp) 1478 { 1479 static char *fname = "i_ddi_devacc_to_hatacc"; 1480 #if defined(lint) 1481 *hataccp = *hataccp; 1482 #endif 1483 /* 1484 * This case must not occur because the endianess is examined 1485 * before this function is called. 1486 */ 1487 if (devaccp != NULL && 1488 devaccp->devacc_attr_endian_flags == DDI_STRUCTURE_BE_ACC) { 1489 cmn_err(CE_WARN, 1490 "%s: devacc_attr_endian_flags=0x%x is ignored.", 1491 fname, devaccp->devacc_attr_endian_flags); 1492 } 1493 } 1494 1495 /* 1496 * Check if the specified cache attribute is supported on the platform. 1497 * This function must be called before i_ddi_cacheattr_to_hatacc(). 1498 */ 1499 boolean_t 1500 i_ddi_check_cache_attr(uint_t flags) 1501 { 1502 /* 1503 * The cache attributes are mutually exclusive. Any combination of 1504 * the attributes leads to a failure. 1505 */ 1506 uint_t cache_attr = IOMEM_CACHE_ATTR(flags); 1507 if ((cache_attr != 0) && ((cache_attr & (cache_attr - 1)) != 0)) 1508 return (B_FALSE); 1509 1510 /* All cache attributes are supported on X86/X64 */ 1511 if (cache_attr & (IOMEM_DATA_UNCACHED | IOMEM_DATA_CACHED | 1512 IOMEM_DATA_UC_WR_COMBINE)) 1513 return (B_TRUE); 1514 1515 /* undefined attributes */ 1516 return (B_FALSE); 1517 } 1518 1519 /* set HAT cache attributes from the cache attributes */ 1520 void 1521 i_ddi_cacheattr_to_hatacc(uint_t flags, uint_t *hataccp) 1522 { 1523 uint_t cache_attr = IOMEM_CACHE_ATTR(flags); 1524 static char *fname = "i_ddi_cacheattr_to_hatacc"; 1525 1526 /* 1527 * If write-combining is not supported, then it falls back 1528 * to uncacheable. 1529 */ 1530 if (cache_attr == IOMEM_DATA_UC_WR_COMBINE && !(x86_feature & X86_PAT)) 1531 cache_attr = IOMEM_DATA_UNCACHED; 1532 1533 /* 1534 * set HAT attrs according to the cache attrs. 1535 */ 1536 switch (cache_attr) { 1537 case IOMEM_DATA_UNCACHED: 1538 *hataccp &= ~HAT_ORDER_MASK; 1539 *hataccp |= (HAT_STRICTORDER | HAT_PLAT_NOCACHE); 1540 break; 1541 case IOMEM_DATA_UC_WR_COMBINE: 1542 *hataccp &= ~HAT_ORDER_MASK; 1543 *hataccp |= (HAT_MERGING_OK | HAT_PLAT_NOCACHE); 1544 break; 1545 case IOMEM_DATA_CACHED: 1546 *hataccp &= ~HAT_ORDER_MASK; 1547 *hataccp |= HAT_UNORDERED_OK; 1548 break; 1549 /* 1550 * This case must not occur because the cache attribute is scrutinized 1551 * before this function is called. 1552 */ 1553 default: 1554 /* 1555 * set cacheable to hat attrs. 1556 */ 1557 *hataccp &= ~HAT_ORDER_MASK; 1558 *hataccp |= HAT_UNORDERED_OK; 1559 cmn_err(CE_WARN, "%s: cache_attr=0x%x is ignored.", 1560 fname, cache_attr); 1561 } 1562 } 1563 1564 /* 1565 * This should actually be called i_ddi_dma_mem_alloc. There should 1566 * also be an i_ddi_pio_mem_alloc. i_ddi_dma_mem_alloc should call 1567 * through the device tree with the DDI_CTLOPS_DMA_ALIGN ctl ops to 1568 * get alignment requirements for DMA memory. i_ddi_pio_mem_alloc 1569 * should use DDI_CTLOPS_PIO_ALIGN. Since we only have i_ddi_mem_alloc 1570 * so far which is used for both, DMA and PIO, we have to use the DMA 1571 * ctl ops to make everybody happy. 1572 */ 1573 /*ARGSUSED*/ 1574 int 1575 i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attr, 1576 size_t length, int cansleep, int flags, 1577 ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, 1578 size_t *real_length, ddi_acc_hdl_t *ap) 1579 { 1580 caddr_t a; 1581 int iomin; 1582 ddi_acc_impl_t *iap; 1583 int physcontig = 0; 1584 pgcnt_t npages; 1585 pgcnt_t minctg; 1586 uint_t order; 1587 int e; 1588 1589 /* 1590 * Check legality of arguments 1591 */ 1592 if (length == 0 || kaddrp == NULL || attr == NULL) { 1593 return (DDI_FAILURE); 1594 } 1595 1596 if (attr->dma_attr_minxfer == 0 || attr->dma_attr_align == 0 || 1597 (attr->dma_attr_align & (attr->dma_attr_align - 1)) || 1598 (attr->dma_attr_minxfer & (attr->dma_attr_minxfer - 1))) { 1599 return (DDI_FAILURE); 1600 } 1601 1602 /* 1603 * figure out most restrictive alignment requirement 1604 */ 1605 iomin = attr->dma_attr_minxfer; 1606 iomin = maxbit(iomin, attr->dma_attr_align); 1607 if (iomin == 0) 1608 return (DDI_FAILURE); 1609 1610 ASSERT((iomin & (iomin - 1)) == 0); 1611 1612 /* 1613 * if we allocate memory with IOMEM_DATA_UNCACHED or 1614 * IOMEM_DATA_UC_WR_COMBINE, make sure we allocate a page aligned 1615 * memory that ends on a page boundry. 1616 * Don't want to have to different cache mappings to the same 1617 * physical page. 1618 */ 1619 if (OVERRIDE_CACHE_ATTR(flags)) { 1620 iomin = (iomin + MMU_PAGEOFFSET) & MMU_PAGEMASK; 1621 length = (length + MMU_PAGEOFFSET) & (size_t)MMU_PAGEMASK; 1622 } 1623 1624 /* 1625 * Determine if we need to satisfy the request for physically 1626 * contiguous memory or alignments larger than pagesize. 1627 */ 1628 npages = btopr(length + attr->dma_attr_align); 1629 minctg = howmany(npages, attr->dma_attr_sgllen); 1630 1631 if (minctg > 1) { 1632 uint64_t pfnseg = attr->dma_attr_seg >> PAGESHIFT; 1633 /* 1634 * verify that the minimum contig requirement for the 1635 * actual length does not cross segment boundary. 1636 */ 1637 length = P2ROUNDUP_TYPED(length, attr->dma_attr_minxfer, 1638 size_t); 1639 npages = btopr(length); 1640 minctg = howmany(npages, attr->dma_attr_sgllen); 1641 if (minctg > pfnseg + 1) 1642 return (DDI_FAILURE); 1643 physcontig = 1; 1644 } else { 1645 length = P2ROUNDUP_TYPED(length, iomin, size_t); 1646 } 1647 1648 /* 1649 * Allocate the requested amount from the system. 1650 */ 1651 a = kalloca(length, iomin, cansleep, physcontig, attr); 1652 1653 if ((*kaddrp = a) == NULL) 1654 return (DDI_FAILURE); 1655 1656 /* 1657 * if we to modify the cache attributes, go back and muck with the 1658 * mappings. 1659 */ 1660 if (OVERRIDE_CACHE_ATTR(flags)) { 1661 order = 0; 1662 i_ddi_cacheattr_to_hatacc(flags, &order); 1663 e = kmem_override_cache_attrs(a, length, order); 1664 if (e != 0) { 1665 kfreea(a); 1666 return (DDI_FAILURE); 1667 } 1668 } 1669 1670 if (real_length) { 1671 *real_length = length; 1672 } 1673 if (ap) { 1674 /* 1675 * initialize access handle 1676 */ 1677 iap = (ddi_acc_impl_t *)ap->ah_platform_private; 1678 iap->ahi_acc_attr |= DDI_ACCATTR_CPU_VADDR; 1679 impl_acc_hdl_init(ap); 1680 } 1681 1682 return (DDI_SUCCESS); 1683 } 1684 1685 /* 1686 * covert old DMA limits structure to DMA attribute structure 1687 * and continue 1688 */ 1689 int 1690 i_ddi_mem_alloc_lim(dev_info_t *dip, ddi_dma_lim_t *limits, 1691 size_t length, int cansleep, int streaming, 1692 ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, 1693 uint_t *real_length, ddi_acc_hdl_t *ap) 1694 { 1695 ddi_dma_attr_t dma_attr, *attrp; 1696 size_t rlen; 1697 int ret; 1698 1699 if (limits == NULL) { 1700 return (DDI_FAILURE); 1701 } 1702 1703 /* 1704 * set up DMA attribute structure to pass to i_ddi_mem_alloc() 1705 */ 1706 attrp = &dma_attr; 1707 attrp->dma_attr_version = DMA_ATTR_V0; 1708 attrp->dma_attr_addr_lo = (uint64_t)limits->dlim_addr_lo; 1709 attrp->dma_attr_addr_hi = (uint64_t)limits->dlim_addr_hi; 1710 attrp->dma_attr_count_max = (uint64_t)limits->dlim_ctreg_max; 1711 attrp->dma_attr_align = 1; 1712 attrp->dma_attr_burstsizes = (uint_t)limits->dlim_burstsizes; 1713 attrp->dma_attr_minxfer = (uint32_t)limits->dlim_minxfer; 1714 attrp->dma_attr_maxxfer = (uint64_t)limits->dlim_reqsize; 1715 attrp->dma_attr_seg = (uint64_t)limits->dlim_adreg_max; 1716 attrp->dma_attr_sgllen = limits->dlim_sgllen; 1717 attrp->dma_attr_granular = (uint32_t)limits->dlim_granular; 1718 attrp->dma_attr_flags = 0; 1719 1720 ret = i_ddi_mem_alloc(dip, attrp, length, cansleep, streaming, 1721 accattrp, kaddrp, &rlen, ap); 1722 if (ret == DDI_SUCCESS) { 1723 if (real_length) 1724 *real_length = (uint_t)rlen; 1725 } 1726 return (ret); 1727 } 1728 1729 /* ARGSUSED */ 1730 void 1731 i_ddi_mem_free(caddr_t kaddr, ddi_acc_hdl_t *ap) 1732 { 1733 if (ap != NULL) { 1734 /* 1735 * if we modified the cache attributes on alloc, go back and 1736 * fix them since this memory could be returned to the 1737 * general pool. 1738 */ 1739 if (OVERRIDE_CACHE_ATTR(ap->ah_xfermodes)) { 1740 uint_t order = 0; 1741 int e; 1742 i_ddi_cacheattr_to_hatacc(IOMEM_DATA_CACHED, &order); 1743 e = kmem_override_cache_attrs(kaddr, ap->ah_len, order); 1744 if (e != 0) { 1745 cmn_err(CE_WARN, "i_ddi_mem_free() failed to " 1746 "override cache attrs, memory leaked\n"); 1747 return; 1748 } 1749 } 1750 } 1751 kfreea(kaddr); 1752 } 1753 1754 /* 1755 * Access Barriers 1756 * 1757 */ 1758 /*ARGSUSED*/ 1759 int 1760 i_ddi_ontrap(ddi_acc_handle_t hp) 1761 { 1762 return (DDI_FAILURE); 1763 } 1764 1765 /*ARGSUSED*/ 1766 void 1767 i_ddi_notrap(ddi_acc_handle_t hp) 1768 { 1769 } 1770 1771 1772 /* 1773 * Misc Functions 1774 */ 1775 1776 /* 1777 * Implementation instance override functions 1778 * 1779 * No override on i86pc 1780 */ 1781 /*ARGSUSED*/ 1782 uint_t 1783 impl_assign_instance(dev_info_t *dip) 1784 { 1785 return ((uint_t)-1); 1786 } 1787 1788 /*ARGSUSED*/ 1789 int 1790 impl_keep_instance(dev_info_t *dip) 1791 { 1792 return (DDI_FAILURE); 1793 } 1794 1795 /*ARGSUSED*/ 1796 int 1797 impl_free_instance(dev_info_t *dip) 1798 { 1799 return (DDI_FAILURE); 1800 } 1801 1802 /*ARGSUSED*/ 1803 int 1804 impl_check_cpu(dev_info_t *devi) 1805 { 1806 return (DDI_SUCCESS); 1807 } 1808 1809 /* 1810 * Referenced in common/cpr_driver.c: Power off machine. 1811 * Don't know how to power off i86pc. 1812 */ 1813 void 1814 arch_power_down() 1815 {} 1816 1817 /* 1818 * Copy name to property_name, since name 1819 * is in the low address range below kernelbase. 1820 */ 1821 static void 1822 copy_boot_str(const char *boot_str, char *kern_str, int len) 1823 { 1824 int i = 0; 1825 1826 while (i < len - 1 && boot_str[i] != '\0') { 1827 kern_str[i] = boot_str[i]; 1828 i++; 1829 } 1830 1831 kern_str[i] = 0; /* null terminate */ 1832 if (boot_str[i] != '\0') 1833 cmn_err(CE_WARN, 1834 "boot property string is truncated to %s", kern_str); 1835 } 1836 1837 static void 1838 get_boot_properties(void) 1839 { 1840 extern char hw_provider[]; 1841 dev_info_t *devi; 1842 char *name; 1843 int length; 1844 char property_name[50], property_val[50]; 1845 void *bop_staging_area; 1846 1847 bop_staging_area = kmem_zalloc(MMU_PAGESIZE, KM_NOSLEEP); 1848 1849 /* 1850 * Import "root" properties from the boot. 1851 * 1852 * We do this by invoking BOP_NEXTPROP until the list 1853 * is completely copied in. 1854 */ 1855 1856 devi = ddi_root_node(); 1857 for (name = BOP_NEXTPROP(bootops, ""); /* get first */ 1858 name; /* NULL => DONE */ 1859 name = BOP_NEXTPROP(bootops, name)) { /* get next */ 1860 1861 /* copy string to memory above kernelbase */ 1862 copy_boot_str(name, property_name, 50); 1863 1864 /* 1865 * Skip vga properties. They will be picked up later 1866 * by get_vga_properties. 1867 */ 1868 if (strcmp(property_name, "display-edif-block") == 0 || 1869 strcmp(property_name, "display-edif-id") == 0) { 1870 continue; 1871 } 1872 1873 length = BOP_GETPROPLEN(bootops, property_name); 1874 if (length == 0) 1875 continue; 1876 if (length > MMU_PAGESIZE) { 1877 cmn_err(CE_NOTE, 1878 "boot property %s longer than 0x%x, ignored\n", 1879 property_name, MMU_PAGESIZE); 1880 continue; 1881 } 1882 BOP_GETPROP(bootops, property_name, bop_staging_area); 1883 1884 /* 1885 * special properties: 1886 * si-machine, si-hw-provider 1887 * goes to kernel data structures. 1888 * bios-boot-device and stdout 1889 * goes to hardware property list so it may show up 1890 * in the prtconf -vp output. This is needed by 1891 * Install/Upgrade. Once we fix install upgrade, 1892 * this can be taken out. 1893 */ 1894 if (strcmp(name, "si-machine") == 0) { 1895 (void) strncpy(utsname.machine, bop_staging_area, 1896 SYS_NMLN); 1897 utsname.machine[SYS_NMLN - 1] = (char)NULL; 1898 } else if (strcmp(name, "si-hw-provider") == 0) { 1899 (void) strncpy(hw_provider, bop_staging_area, SYS_NMLN); 1900 hw_provider[SYS_NMLN - 1] = (char)NULL; 1901 } else if (strcmp(name, "bios-boot-device") == 0) { 1902 copy_boot_str(bop_staging_area, property_val, 50); 1903 (void) ndi_prop_update_string(DDI_DEV_T_NONE, devi, 1904 property_name, property_val); 1905 } else if (strcmp(name, "stdout") == 0) { 1906 (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, 1907 property_name, *((int *)bop_staging_area)); 1908 } else { 1909 /* Property type unknown, use old prop interface */ 1910 (void) e_ddi_prop_create(DDI_DEV_T_NONE, devi, 1911 DDI_PROP_CANSLEEP, property_name, bop_staging_area, 1912 length); 1913 } 1914 } 1915 1916 kmem_free(bop_staging_area, MMU_PAGESIZE); 1917 } 1918 1919 static void 1920 get_vga_properties(void) 1921 { 1922 dev_info_t *devi; 1923 major_t major; 1924 char *name; 1925 int length; 1926 char property_val[50]; 1927 void *bop_staging_area; 1928 1929 major = ddi_name_to_major("vgatext"); 1930 if (major == (major_t)-1) 1931 return; 1932 devi = devnamesp[major].dn_head; 1933 if (devi == NULL) 1934 return; 1935 1936 bop_staging_area = kmem_zalloc(MMU_PAGESIZE, KM_SLEEP); 1937 1938 /* 1939 * Import "vga" properties from the boot. 1940 */ 1941 name = "display-edif-block"; 1942 length = BOP_GETPROPLEN(bootops, name); 1943 if (length > 0 && length < MMU_PAGESIZE) { 1944 BOP_GETPROP(bootops, name, bop_staging_area); 1945 (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE, 1946 devi, name, bop_staging_area, length); 1947 } 1948 1949 /* 1950 * kdmconfig is also looking for display-type and 1951 * video-adapter-type. We default to color and svga. 1952 * 1953 * Could it be "monochrome", "vga"? 1954 * Nah, you've got to come to the 21st century... 1955 * And you can set monitor type manually in kdmconfig 1956 * if you are really an old junky. 1957 */ 1958 (void) ndi_prop_update_string(DDI_DEV_T_NONE, 1959 devi, "display-type", "color"); 1960 (void) ndi_prop_update_string(DDI_DEV_T_NONE, 1961 devi, "video-adapter-type", "svga"); 1962 1963 name = "display-edif-id"; 1964 length = BOP_GETPROPLEN(bootops, name); 1965 if (length > 0 && length < MMU_PAGESIZE) { 1966 BOP_GETPROP(bootops, name, bop_staging_area); 1967 copy_boot_str(bop_staging_area, property_val, length); 1968 (void) ndi_prop_update_string(DDI_DEV_T_NONE, 1969 devi, name, property_val); 1970 } 1971 1972 kmem_free(bop_staging_area, MMU_PAGESIZE); 1973 } 1974 1975 1976 /* 1977 * This is temporary, but absolutely necessary. If we are being 1978 * booted with a device tree created by the DevConf project's bootconf 1979 * program, then we have device information nodes that reflect 1980 * reality. At this point in time in the Solaris release schedule, the 1981 * kernel drivers aren't prepared for reality. They still depend on their 1982 * own ad-hoc interpretations of the properties created when their .conf 1983 * files were interpreted. These drivers use an "ignore-hardware-nodes" 1984 * property to prevent them from using the nodes passed up from the bootconf 1985 * device tree. 1986 * 1987 * Trying to assemble root file system drivers as we are booting from 1988 * devconf will fail if the kernel driver is basing its name_addr's on the 1989 * psuedo-node device info while the bootpath passed up from bootconf is using 1990 * reality-based name_addrs. We help the boot along in this case by 1991 * looking at the pre-bootconf bootpath and determining if we would have 1992 * successfully matched if that had been the bootpath we had chosen. 1993 * 1994 * Note that we only even perform this extra check if we've booted 1995 * using bootconf's 1275 compliant bootpath, this is the boot device, and 1996 * we're trying to match the name_addr specified in the 1275 bootpath. 1997 */ 1998 1999 #define MAXCOMPONENTLEN 32 2000 2001 int 2002 x86_old_bootpath_name_addr_match(dev_info_t *cdip, char *caddr, char *naddr) 2003 { 2004 /* 2005 * There are multiple criteria to be met before we can even 2006 * consider allowing a name_addr match here. 2007 * 2008 * 1) We must have been booted such that the bootconf program 2009 * created device tree nodes and properties. This can be 2010 * determined by examining the 'bootpath' property. This 2011 * property will be a non-null string iff bootconf was 2012 * involved in the boot. 2013 * 2014 * 2) The module that we want to match must be the boot device. 2015 * 2016 * 3) The instance of the module we are thinking of letting be 2017 * our match must be ignoring hardware nodes. 2018 * 2019 * 4) The name_addr we want to match must be the name_addr 2020 * specified in the 1275 bootpath. 2021 */ 2022 static char bootdev_module[MAXCOMPONENTLEN]; 2023 static char bootdev_oldmod[MAXCOMPONENTLEN]; 2024 static char bootdev_newaddr[MAXCOMPONENTLEN]; 2025 static char bootdev_oldaddr[MAXCOMPONENTLEN]; 2026 static int quickexit; 2027 2028 char *daddr; 2029 int dlen; 2030 2031 char *lkupname; 2032 int rv = DDI_FAILURE; 2033 2034 if ((ddi_getlongprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 2035 "devconf-addr", (caddr_t)&daddr, &dlen) == DDI_PROP_SUCCESS) && 2036 (ddi_getprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 2037 "ignore-hardware-nodes", -1) != -1)) { 2038 if (strcmp(daddr, caddr) == 0) { 2039 return (DDI_SUCCESS); 2040 } 2041 } 2042 2043 if (quickexit) 2044 return (rv); 2045 2046 if (bootdev_module[0] == '\0') { 2047 char *addrp, *eoaddrp; 2048 char *busp, *modp, *atp; 2049 char *bp1275, *bp; 2050 int bp1275len, bplen; 2051 2052 bp1275 = bp = addrp = eoaddrp = busp = modp = atp = NULL; 2053 2054 if (ddi_getlongprop(DDI_DEV_T_ANY, 2055 ddi_root_node(), 0, "bootpath", 2056 (caddr_t)&bp1275, &bp1275len) != DDI_PROP_SUCCESS || 2057 bp1275len <= 1) { 2058 /* 2059 * We didn't boot from bootconf so we never need to 2060 * do any special matches. 2061 */ 2062 quickexit = 1; 2063 if (bp1275) 2064 kmem_free(bp1275, bp1275len); 2065 return (rv); 2066 } 2067 2068 if (ddi_getlongprop(DDI_DEV_T_ANY, 2069 ddi_root_node(), 0, "boot-path", 2070 (caddr_t)&bp, &bplen) != DDI_PROP_SUCCESS || bplen <= 1) { 2071 /* 2072 * No fallback position for matching. This is 2073 * certainly unexpected, but we'll handle it 2074 * just in case. 2075 */ 2076 quickexit = 1; 2077 kmem_free(bp1275, bp1275len); 2078 if (bp) 2079 kmem_free(bp, bplen); 2080 return (rv); 2081 } 2082 2083 /* 2084 * Determine boot device module and 1275 name_addr 2085 * 2086 * bootpath assumed to be of the form /bus/module@name_addr 2087 */ 2088 if (busp = strchr(bp1275, '/')) { 2089 if (modp = strchr(busp + 1, '/')) { 2090 if (atp = strchr(modp + 1, '@')) { 2091 *atp = '\0'; 2092 addrp = atp + 1; 2093 if (eoaddrp = strchr(addrp, '/')) 2094 *eoaddrp = '\0'; 2095 } 2096 } 2097 } 2098 2099 if (modp && addrp) { 2100 (void) strncpy(bootdev_module, modp + 1, 2101 MAXCOMPONENTLEN); 2102 bootdev_module[MAXCOMPONENTLEN - 1] = '\0'; 2103 2104 (void) strncpy(bootdev_newaddr, addrp, MAXCOMPONENTLEN); 2105 bootdev_newaddr[MAXCOMPONENTLEN - 1] = '\0'; 2106 } else { 2107 quickexit = 1; 2108 kmem_free(bp1275, bp1275len); 2109 kmem_free(bp, bplen); 2110 return (rv); 2111 } 2112 2113 /* 2114 * Determine fallback name_addr 2115 * 2116 * 10/3/96 - Also save fallback module name because it 2117 * might actually be different than the current module 2118 * name. E.G., ISA pnp drivers have new names. 2119 * 2120 * bootpath assumed to be of the form /bus/module@name_addr 2121 */ 2122 addrp = NULL; 2123 if (busp = strchr(bp, '/')) { 2124 if (modp = strchr(busp + 1, '/')) { 2125 if (atp = strchr(modp + 1, '@')) { 2126 *atp = '\0'; 2127 addrp = atp + 1; 2128 if (eoaddrp = strchr(addrp, '/')) 2129 *eoaddrp = '\0'; 2130 } 2131 } 2132 } 2133 2134 if (modp && addrp) { 2135 (void) strncpy(bootdev_oldmod, modp + 1, 2136 MAXCOMPONENTLEN); 2137 bootdev_module[MAXCOMPONENTLEN - 1] = '\0'; 2138 2139 (void) strncpy(bootdev_oldaddr, addrp, MAXCOMPONENTLEN); 2140 bootdev_oldaddr[MAXCOMPONENTLEN - 1] = '\0'; 2141 } 2142 2143 /* Free up the bootpath storage now that we're done with it. */ 2144 kmem_free(bp1275, bp1275len); 2145 kmem_free(bp, bplen); 2146 2147 if (bootdev_oldaddr[0] == '\0') { 2148 quickexit = 1; 2149 return (rv); 2150 } 2151 } 2152 2153 if (((lkupname = ddi_get_name(cdip)) != NULL) && 2154 (strcmp(bootdev_module, lkupname) == 0 || 2155 strcmp(bootdev_oldmod, lkupname) == 0) && 2156 ((ddi_getprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 2157 "ignore-hardware-nodes", -1) != -1) || 2158 ignore_hardware_nodes) && 2159 strcmp(bootdev_newaddr, caddr) == 0 && 2160 strcmp(bootdev_oldaddr, naddr) == 0) { 2161 rv = DDI_SUCCESS; 2162 } 2163 2164 return (rv); 2165 } 2166 2167 /* 2168 * Perform a copy from a memory mapped device (whose devinfo pointer is devi) 2169 * separately mapped at devaddr in the kernel to a kernel buffer at kaddr. 2170 */ 2171 /*ARGSUSED*/ 2172 int 2173 e_ddi_copyfromdev(dev_info_t *devi, 2174 off_t off, const void *devaddr, void *kaddr, size_t len) 2175 { 2176 bcopy(devaddr, kaddr, len); 2177 return (0); 2178 } 2179 2180 /* 2181 * Perform a copy to a memory mapped device (whose devinfo pointer is devi) 2182 * separately mapped at devaddr in the kernel from a kernel buffer at kaddr. 2183 */ 2184 /*ARGSUSED*/ 2185 int 2186 e_ddi_copytodev(dev_info_t *devi, 2187 off_t off, const void *kaddr, void *devaddr, size_t len) 2188 { 2189 bcopy(kaddr, devaddr, len); 2190 return (0); 2191 } 2192 2193 2194 static int 2195 poke_mem(peekpoke_ctlops_t *in_args) 2196 { 2197 int err = DDI_SUCCESS; 2198 on_trap_data_t otd; 2199 2200 /* Set up protected environment. */ 2201 if (!on_trap(&otd, OT_DATA_ACCESS)) { 2202 switch (in_args->size) { 2203 case sizeof (uint8_t): 2204 *(uint8_t *)(in_args->dev_addr) = 2205 *(uint8_t *)in_args->host_addr; 2206 break; 2207 2208 case sizeof (uint16_t): 2209 *(uint16_t *)(in_args->dev_addr) = 2210 *(uint16_t *)in_args->host_addr; 2211 break; 2212 2213 case sizeof (uint32_t): 2214 *(uint32_t *)(in_args->dev_addr) = 2215 *(uint32_t *)in_args->host_addr; 2216 break; 2217 2218 case sizeof (uint64_t): 2219 *(uint64_t *)(in_args->dev_addr) = 2220 *(uint64_t *)in_args->host_addr; 2221 break; 2222 2223 default: 2224 err = DDI_FAILURE; 2225 break; 2226 } 2227 } else 2228 err = DDI_FAILURE; 2229 2230 /* Take down protected environment. */ 2231 no_trap(); 2232 2233 return (err); 2234 } 2235 2236 2237 static int 2238 peek_mem(peekpoke_ctlops_t *in_args) 2239 { 2240 int err = DDI_SUCCESS; 2241 on_trap_data_t otd; 2242 2243 if (!on_trap(&otd, OT_DATA_ACCESS)) { 2244 switch (in_args->size) { 2245 case sizeof (uint8_t): 2246 *(uint8_t *)in_args->host_addr = 2247 *(uint8_t *)in_args->dev_addr; 2248 break; 2249 2250 case sizeof (uint16_t): 2251 *(uint16_t *)in_args->host_addr = 2252 *(uint16_t *)in_args->dev_addr; 2253 break; 2254 2255 case sizeof (uint32_t): 2256 *(uint32_t *)in_args->host_addr = 2257 *(uint32_t *)in_args->dev_addr; 2258 break; 2259 2260 case sizeof (uint64_t): 2261 *(uint64_t *)in_args->host_addr = 2262 *(uint64_t *)in_args->dev_addr; 2263 break; 2264 2265 default: 2266 err = DDI_FAILURE; 2267 break; 2268 } 2269 } else 2270 err = DDI_FAILURE; 2271 2272 no_trap(); 2273 return (err); 2274 } 2275 2276 2277 /* 2278 * This is called only to process peek/poke when the DIP is NULL. 2279 * Assume that this is for memory, as nexi take care of device safe accesses. 2280 */ 2281 int 2282 peekpoke_mem(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args) 2283 { 2284 return (cmd == DDI_CTLOPS_PEEK ? peek_mem(in_args) : poke_mem(in_args)); 2285 } 2286 2287 /* 2288 * we've just done a cautious put/get. Check if it was successful by 2289 * calling pci_ereport_post() on all puts and for any gets that return -1 2290 */ 2291 static int 2292 pci_peekpoke_check_fma(dev_info_t *dip, void *arg, ddi_ctl_enum_t ctlop) 2293 { 2294 int rval = DDI_SUCCESS; 2295 peekpoke_ctlops_t *in_args = (peekpoke_ctlops_t *)arg; 2296 ddi_fm_error_t de; 2297 ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 2298 ddi_acc_hdl_t *hdlp = (ddi_acc_hdl_t *)in_args->handle; 2299 int check_err = 0; 2300 int repcount = in_args->repcount; 2301 2302 if (ctlop == DDI_CTLOPS_POKE && 2303 hdlp->ah_acc.devacc_attr_access != DDI_CAUTIOUS_ACC) 2304 return (DDI_SUCCESS); 2305 2306 if (ctlop == DDI_CTLOPS_PEEK && 2307 hdlp->ah_acc.devacc_attr_access != DDI_CAUTIOUS_ACC) { 2308 for (; repcount; repcount--) { 2309 switch (in_args->size) { 2310 case sizeof (uint8_t): 2311 if (*(uint8_t *)in_args->host_addr == 0xff) 2312 check_err = 1; 2313 break; 2314 case sizeof (uint16_t): 2315 if (*(uint16_t *)in_args->host_addr == 0xffff) 2316 check_err = 1; 2317 break; 2318 case sizeof (uint32_t): 2319 if (*(uint32_t *)in_args->host_addr == 2320 0xffffffff) 2321 check_err = 1; 2322 break; 2323 case sizeof (uint64_t): 2324 if (*(uint64_t *)in_args->host_addr == 2325 0xffffffffffffffff) 2326 check_err = 1; 2327 break; 2328 } 2329 } 2330 if (check_err == 0) 2331 return (DDI_SUCCESS); 2332 } 2333 /* 2334 * for a cautious put or get or a non-cautious get that returned -1 call 2335 * io framework to see if there really was an error 2336 */ 2337 bzero(&de, sizeof (ddi_fm_error_t)); 2338 de.fme_ena = fm_ena_generate(0, FM_ENA_FMT1); 2339 if (hdlp->ah_acc.devacc_attr_access == DDI_CAUTIOUS_ACC) { 2340 de.fme_flag = DDI_FM_ERR_EXPECTED; 2341 de.fme_acc_handle = in_args->handle; 2342 } else if (hdlp->ah_acc.devacc_attr_access == DDI_DEFAULT_ACC) { 2343 /* 2344 * We only get here with DDI_DEFAULT_ACC for config space gets. 2345 * Non-hardened drivers may be probing the hardware and 2346 * expecting -1 returned. So need to treat errors on 2347 * DDI_DEFAULT_ACC as DDI_FM_ERR_EXPECTED. 2348 */ 2349 de.fme_flag = DDI_FM_ERR_EXPECTED; 2350 de.fme_acc_handle = in_args->handle; 2351 } else { 2352 /* 2353 * Hardened driver doing protected accesses shouldn't 2354 * get errors unless there's a hardware problem. Treat 2355 * as nonfatal if there's an error, but set UNEXPECTED 2356 * so we raise ereports on any errors and potentially 2357 * fault the device 2358 */ 2359 de.fme_flag = DDI_FM_ERR_UNEXPECTED; 2360 } 2361 pci_ereport_post(dip, &de, NULL); 2362 if (hdlp->ah_acc.devacc_attr_access != DDI_DEFAULT_ACC && 2363 de.fme_status != DDI_FM_OK) { 2364 ndi_err_t *errp = (ndi_err_t *)hp->ahi_err; 2365 rval = DDI_FAILURE; 2366 errp->err_ena = de.fme_ena; 2367 errp->err_expected = de.fme_flag; 2368 errp->err_status = DDI_FM_NONFATAL; 2369 } 2370 return (rval); 2371 } 2372 2373 /* 2374 * pci_peekpoke_check_nofma() is for when an error occurs on a register access 2375 * during pci_ereport_post(). We can't call pci_ereport_post() again or we'd 2376 * recurse, so assume all puts are OK and gets have failed if they return -1 2377 */ 2378 static int 2379 pci_peekpoke_check_nofma(void *arg, ddi_ctl_enum_t ctlop) 2380 { 2381 int rval = DDI_SUCCESS; 2382 peekpoke_ctlops_t *in_args = (peekpoke_ctlops_t *)arg; 2383 ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 2384 ddi_acc_hdl_t *hdlp = (ddi_acc_hdl_t *)in_args->handle; 2385 int repcount = in_args->repcount; 2386 2387 if (ctlop == DDI_CTLOPS_POKE) 2388 return (rval); 2389 2390 for (; repcount; repcount--) { 2391 switch (in_args->size) { 2392 case sizeof (uint8_t): 2393 if (*(uint8_t *)in_args->host_addr == 0xff) 2394 rval = DDI_FAILURE; 2395 break; 2396 case sizeof (uint16_t): 2397 if (*(uint16_t *)in_args->host_addr == 0xffff) 2398 rval = DDI_FAILURE; 2399 break; 2400 case sizeof (uint32_t): 2401 if (*(uint32_t *)in_args->host_addr == 0xffffffff) 2402 rval = DDI_FAILURE; 2403 break; 2404 case sizeof (uint64_t): 2405 if (*(uint64_t *)in_args->host_addr == 2406 0xffffffffffffffff) 2407 rval = DDI_FAILURE; 2408 break; 2409 } 2410 } 2411 if (hdlp->ah_acc.devacc_attr_access != DDI_DEFAULT_ACC && 2412 rval == DDI_FAILURE) { 2413 ndi_err_t *errp = (ndi_err_t *)hp->ahi_err; 2414 errp->err_ena = fm_ena_generate(0, FM_ENA_FMT1); 2415 errp->err_expected = DDI_FM_ERR_UNEXPECTED; 2416 errp->err_status = DDI_FM_NONFATAL; 2417 } 2418 return (rval); 2419 } 2420 2421 int 2422 pci_peekpoke_check(dev_info_t *dip, dev_info_t *rdip, 2423 ddi_ctl_enum_t ctlop, void *arg, void *result, 2424 int (*handler)(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, 2425 void *), kmutex_t *err_mutexp, kmutex_t *peek_poke_mutexp) 2426 { 2427 int rval; 2428 peekpoke_ctlops_t *in_args = (peekpoke_ctlops_t *)arg; 2429 ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 2430 2431 if (hp->ahi_acc_attr & DDI_ACCATTR_CONFIG_SPACE) { 2432 if (!mutex_tryenter(err_mutexp)) { 2433 /* 2434 * As this may be a recursive call from within 2435 * pci_ereport_post() we can't wait for the mutexes. 2436 * Fortunately we know someone is already calling 2437 * pci_ereport_post() which will handle the error bits 2438 * for us, and as this is a config space access we can 2439 * just do the access and check return value for -1 2440 * using pci_peekpoke_check_nofma(). 2441 */ 2442 rval = handler(dip, rdip, ctlop, arg, result); 2443 if (rval == DDI_SUCCESS) 2444 rval = pci_peekpoke_check_nofma(arg, ctlop); 2445 return (rval); 2446 } 2447 /* 2448 * This can't be a recursive call. Drop the err_mutex and get 2449 * both mutexes in the right order. If an error hasn't already 2450 * been detected by the ontrap code, use pci_peekpoke_check_fma 2451 * which will call pci_ereport_post() to check error status. 2452 */ 2453 mutex_exit(err_mutexp); 2454 } 2455 mutex_enter(peek_poke_mutexp); 2456 rval = handler(dip, rdip, ctlop, arg, result); 2457 if (rval == DDI_SUCCESS) { 2458 mutex_enter(err_mutexp); 2459 rval = pci_peekpoke_check_fma(dip, arg, ctlop); 2460 mutex_exit(err_mutexp); 2461 } 2462 mutex_exit(peek_poke_mutexp); 2463 return (rval); 2464 } 2465 2466 void 2467 impl_setup_ddi(void) 2468 { 2469 dev_info_t *xdip, *isa_dip; 2470 rd_existing_t rd_mem_prop; 2471 int err; 2472 2473 ndi_devi_alloc_sleep(ddi_root_node(), "ramdisk", 2474 (pnode_t)DEVI_SID_NODEID, &xdip); 2475 2476 (void) BOP_GETPROP(bootops, 2477 "ramdisk_start", (void *)&ramdisk_start); 2478 (void) BOP_GETPROP(bootops, 2479 "ramdisk_end", (void *)&ramdisk_end); 2480 2481 rd_mem_prop.phys = ramdisk_start; 2482 rd_mem_prop.size = ramdisk_end - ramdisk_start + 1; 2483 2484 (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE, xdip, 2485 RD_EXISTING_PROP_NAME, (uchar_t *)&rd_mem_prop, 2486 sizeof (rd_mem_prop)); 2487 err = ndi_devi_bind_driver(xdip, 0); 2488 ASSERT(err == 0); 2489 2490 /* isa node */ 2491 ndi_devi_alloc_sleep(ddi_root_node(), "isa", 2492 (pnode_t)DEVI_SID_NODEID, &isa_dip); 2493 (void) ndi_prop_update_string(DDI_DEV_T_NONE, isa_dip, 2494 "device_type", "isa"); 2495 (void) ndi_prop_update_string(DDI_DEV_T_NONE, isa_dip, 2496 "bus-type", "isa"); 2497 (void) ndi_devi_bind_driver(isa_dip, 0); 2498 2499 /* 2500 * Read in the properties from the boot. 2501 */ 2502 get_boot_properties(); 2503 2504 /* do bus dependent probes. */ 2505 impl_bus_initialprobe(); 2506 2507 /* not framebuffer should be enumerated, if present */ 2508 get_vga_properties(); 2509 } 2510 2511 dev_t 2512 getrootdev(void) 2513 { 2514 /* 2515 * Precedence given to rootdev if set in /etc/system 2516 */ 2517 if (root_is_svm) { 2518 return (ddi_pathname_to_dev_t(svm_bootpath)); 2519 } 2520 2521 /* 2522 * Usually rootfs.bo_name is initialized by the 2523 * the bootpath property from bootenv.rc, but 2524 * defaults to "/ramdisk:a" otherwise. 2525 */ 2526 return (ddi_pathname_to_dev_t(rootfs.bo_name)); 2527 } 2528 2529 static struct bus_probe { 2530 struct bus_probe *next; 2531 void (*probe)(int); 2532 } *bus_probes; 2533 2534 void 2535 impl_bus_add_probe(void (*func)(int)) 2536 { 2537 struct bus_probe *probe; 2538 2539 probe = kmem_alloc(sizeof (*probe), KM_SLEEP); 2540 probe->next = bus_probes; 2541 probe->probe = func; 2542 bus_probes = probe; 2543 } 2544 2545 /*ARGSUSED*/ 2546 void 2547 impl_bus_delete_probe(void (*func)(int)) 2548 { 2549 struct bus_probe *prev = NULL; 2550 struct bus_probe *probe = bus_probes; 2551 2552 while (probe) { 2553 if (probe->probe == func) 2554 break; 2555 prev = probe; 2556 probe = probe->next; 2557 } 2558 2559 if (probe == NULL) 2560 return; 2561 2562 if (prev) 2563 prev->next = probe->next; 2564 else 2565 bus_probes = probe->next; 2566 2567 kmem_free(probe, sizeof (struct bus_probe)); 2568 } 2569 2570 /* 2571 * impl_bus_initialprobe 2572 * Modload the prom simulator, then let it probe to verify existence 2573 * and type of PCI support. 2574 */ 2575 static void 2576 impl_bus_initialprobe(void) 2577 { 2578 struct bus_probe *probe; 2579 2580 /* load modules to install bus probes */ 2581 if (modload("misc", "pci_autoconfig") < 0) { 2582 cmn_err(CE_PANIC, "failed to load misc/pci_autoconfig"); 2583 } 2584 2585 probe = bus_probes; 2586 while (probe) { 2587 /* run the probe function */ 2588 (*probe->probe)(0); 2589 probe = probe->next; 2590 } 2591 } 2592 2593 /* 2594 * impl_bus_reprobe 2595 * Reprogram devices not set up by firmware. 2596 */ 2597 static void 2598 impl_bus_reprobe(void) 2599 { 2600 struct bus_probe *probe; 2601 2602 probe = bus_probes; 2603 while (probe) { 2604 /* run the probe function */ 2605 (*probe->probe)(1); 2606 probe = probe->next; 2607 } 2608 } 2609 2610 2611 /* 2612 * The following functions ready a cautious request to go up to the nexus 2613 * driver. It is up to the nexus driver to decide how to process the request. 2614 * It may choose to call i_ddi_do_caut_get/put in this file, or do it 2615 * differently. 2616 */ 2617 2618 static void 2619 i_ddi_caut_getput_ctlops(ddi_acc_impl_t *hp, uint64_t host_addr, 2620 uint64_t dev_addr, size_t size, size_t repcount, uint_t flags, 2621 ddi_ctl_enum_t cmd) 2622 { 2623 peekpoke_ctlops_t cautacc_ctlops_arg; 2624 2625 cautacc_ctlops_arg.size = size; 2626 cautacc_ctlops_arg.dev_addr = dev_addr; 2627 cautacc_ctlops_arg.host_addr = host_addr; 2628 cautacc_ctlops_arg.handle = (ddi_acc_handle_t)hp; 2629 cautacc_ctlops_arg.repcount = repcount; 2630 cautacc_ctlops_arg.flags = flags; 2631 2632 (void) ddi_ctlops(hp->ahi_common.ah_dip, hp->ahi_common.ah_dip, cmd, 2633 &cautacc_ctlops_arg, NULL); 2634 } 2635 2636 uint8_t 2637 i_ddi_caut_get8(ddi_acc_impl_t *hp, uint8_t *addr) 2638 { 2639 uint8_t value; 2640 i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 2641 sizeof (uint8_t), 1, 0, DDI_CTLOPS_PEEK); 2642 2643 return (value); 2644 } 2645 2646 uint16_t 2647 i_ddi_caut_get16(ddi_acc_impl_t *hp, uint16_t *addr) 2648 { 2649 uint16_t value; 2650 i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 2651 sizeof (uint16_t), 1, 0, DDI_CTLOPS_PEEK); 2652 2653 return (value); 2654 } 2655 2656 uint32_t 2657 i_ddi_caut_get32(ddi_acc_impl_t *hp, uint32_t *addr) 2658 { 2659 uint32_t value; 2660 i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 2661 sizeof (uint32_t), 1, 0, DDI_CTLOPS_PEEK); 2662 2663 return (value); 2664 } 2665 2666 uint64_t 2667 i_ddi_caut_get64(ddi_acc_impl_t *hp, uint64_t *addr) 2668 { 2669 uint64_t value; 2670 i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 2671 sizeof (uint64_t), 1, 0, DDI_CTLOPS_PEEK); 2672 2673 return (value); 2674 } 2675 2676 void 2677 i_ddi_caut_put8(ddi_acc_impl_t *hp, uint8_t *addr, uint8_t value) 2678 { 2679 i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 2680 sizeof (uint8_t), 1, 0, DDI_CTLOPS_POKE); 2681 } 2682 2683 void 2684 i_ddi_caut_put16(ddi_acc_impl_t *hp, uint16_t *addr, uint16_t value) 2685 { 2686 i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 2687 sizeof (uint16_t), 1, 0, DDI_CTLOPS_POKE); 2688 } 2689 2690 void 2691 i_ddi_caut_put32(ddi_acc_impl_t *hp, uint32_t *addr, uint32_t value) 2692 { 2693 i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 2694 sizeof (uint32_t), 1, 0, DDI_CTLOPS_POKE); 2695 } 2696 2697 void 2698 i_ddi_caut_put64(ddi_acc_impl_t *hp, uint64_t *addr, uint64_t value) 2699 { 2700 i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 2701 sizeof (uint64_t), 1, 0, DDI_CTLOPS_POKE); 2702 } 2703 2704 void 2705 i_ddi_caut_rep_get8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr, 2706 size_t repcount, uint_t flags) 2707 { 2708 i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 2709 sizeof (uint8_t), repcount, flags, DDI_CTLOPS_PEEK); 2710 } 2711 2712 void 2713 i_ddi_caut_rep_get16(ddi_acc_impl_t *hp, uint16_t *host_addr, 2714 uint16_t *dev_addr, size_t repcount, uint_t flags) 2715 { 2716 i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 2717 sizeof (uint16_t), repcount, flags, DDI_CTLOPS_PEEK); 2718 } 2719 2720 void 2721 i_ddi_caut_rep_get32(ddi_acc_impl_t *hp, uint32_t *host_addr, 2722 uint32_t *dev_addr, size_t repcount, uint_t flags) 2723 { 2724 i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 2725 sizeof (uint32_t), repcount, flags, DDI_CTLOPS_PEEK); 2726 } 2727 2728 void 2729 i_ddi_caut_rep_get64(ddi_acc_impl_t *hp, uint64_t *host_addr, 2730 uint64_t *dev_addr, size_t repcount, uint_t flags) 2731 { 2732 i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 2733 sizeof (uint64_t), repcount, flags, DDI_CTLOPS_PEEK); 2734 } 2735 2736 void 2737 i_ddi_caut_rep_put8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr, 2738 size_t repcount, uint_t flags) 2739 { 2740 i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 2741 sizeof (uint8_t), repcount, flags, DDI_CTLOPS_POKE); 2742 } 2743 2744 void 2745 i_ddi_caut_rep_put16(ddi_acc_impl_t *hp, uint16_t *host_addr, 2746 uint16_t *dev_addr, size_t repcount, uint_t flags) 2747 { 2748 i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 2749 sizeof (uint16_t), repcount, flags, DDI_CTLOPS_POKE); 2750 } 2751 2752 void 2753 i_ddi_caut_rep_put32(ddi_acc_impl_t *hp, uint32_t *host_addr, 2754 uint32_t *dev_addr, size_t repcount, uint_t flags) 2755 { 2756 i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 2757 sizeof (uint32_t), repcount, flags, DDI_CTLOPS_POKE); 2758 } 2759 2760 void 2761 i_ddi_caut_rep_put64(ddi_acc_impl_t *hp, uint64_t *host_addr, 2762 uint64_t *dev_addr, size_t repcount, uint_t flags) 2763 { 2764 i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 2765 sizeof (uint64_t), repcount, flags, DDI_CTLOPS_POKE); 2766 } 2767