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 * Copyright 2014 Garrett D'Amore <garrett@damore.org> 23 * Copyright (c) 2012 Gary Mills 24 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 25 */ 26 27 /* 28 * ISA bus nexus driver 29 */ 30 31 #include <sys/types.h> 32 #include <sys/cmn_err.h> 33 #include <sys/conf.h> 34 #include <sys/modctl.h> 35 #include <sys/autoconf.h> 36 #include <sys/errno.h> 37 #include <sys/debug.h> 38 #include <sys/kmem.h> 39 #include <sys/psm.h> 40 #include <sys/ddidmareq.h> 41 #include <sys/ddi_impldefs.h> 42 #include <sys/ddi_subrdefs.h> 43 #include <sys/dma_engine.h> 44 #include <sys/ddi.h> 45 #include <sys/sunddi.h> 46 #include <sys/sunndi.h> 47 #include <sys/acpi/acpi_enum.h> 48 #include <sys/mach_intr.h> 49 #include <sys/pci.h> 50 #include <sys/note.h> 51 #include <sys/boot_console.h> 52 #include <sys/apic.h> 53 #if defined(__xpv) 54 #include <sys/hypervisor.h> 55 #include <sys/evtchn_impl.h> 56 57 extern int console_hypervisor_dev_type(int *); 58 #endif 59 60 61 extern int pseudo_isa; 62 extern int isa_resource_setup(void); 63 extern int (*psm_intr_ops)(dev_info_t *, ddi_intr_handle_impl_t *, 64 psm_intr_op_t, int *); 65 extern void pci_register_isa_resources(int, uint32_t, uint32_t); 66 static void isa_enumerate(int); 67 static void enumerate_BIOS_serial(dev_info_t *); 68 static void adjust_prtsz(dev_info_t *isa_dip); 69 static void isa_create_ranges_prop(dev_info_t *); 70 71 #define USED_RESOURCES "used-resources" 72 73 /* 74 * The following typedef is used to represent an entry in the "ranges" 75 * property of a pci-isa bridge device node. 76 */ 77 typedef struct { 78 uint32_t child_high; 79 uint32_t child_low; 80 uint32_t parent_high; 81 uint32_t parent_mid; 82 uint32_t parent_low; 83 uint32_t size; 84 } pib_ranges_t; 85 86 typedef struct { 87 uint32_t base; 88 uint32_t len; 89 } used_ranges_t; 90 91 #define USED_CELL_SIZE 2 /* 1 byte addr, 1 byte size */ 92 #define ISA_ADDR_IO 1 /* IO address space */ 93 #define ISA_ADDR_MEM 0 /* memory adress space */ 94 95 /* 96 * #define ISA_DEBUG 1 97 */ 98 99 #define num_BIOS_serial 4 /* number of BIOS serial ports to look at */ 100 #define min_BIOS_serial 2 /* minimum number of BIOS serial ports */ 101 #define COM_ISR 2 /* 16550 intr status register */ 102 #define COM_SCR 7 /* 16550 scratch register */ 103 104 /* 105 * For serial ports not enumerated by ACPI, and parallel ports with 106 * illegal size. Typically, a system can have as many as 4 serial 107 * ports and 3 parallel ports. 108 */ 109 #define MAX_EXTRA_RESOURCE 7 110 static struct regspec isa_extra_resource[MAX_EXTRA_RESOURCE]; 111 static int isa_extra_count = 0; 112 113 /* Register definitions for COM1 to COM4. */ 114 static struct regspec asy_regs[] = { 115 {1, 0x3f8, 0x8}, 116 {1, 0x2f8, 0x8}, 117 {1, 0x3e8, 0x8}, 118 {1, 0x2e8, 0x8} 119 }; 120 121 /* Serial port interrupt vectors for COM1 to COM4. */ 122 static int asy_intrs[] = {0x4, 0x3, 0x4, 0x3}; 123 /* Bitfield indicating which interrupts are overridden by eeprom config */ 124 static uchar_t asy_intr_override = 0; 125 126 /* 127 * Local data 128 */ 129 130 static ddi_dma_attr_t ISA_dma_attr = { 131 DMA_ATTR_V0, 132 (unsigned long long)0, 133 (unsigned long long)0x00ffffff, 134 0x0000ffff, 135 1, 136 1, 137 1, 138 (unsigned long long)0xffffffff, 139 (unsigned long long)0x0000ffff, 140 1, 141 1, 142 0 143 }; 144 145 146 /* 147 * Config information 148 */ 149 150 static int 151 isa_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 152 off_t offset, off_t len, caddr_t *vaddrp); 153 154 static int 155 isa_dma_allochdl(dev_info_t *, dev_info_t *, ddi_dma_attr_t *, 156 int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *); 157 158 static int 159 isa_dma_mctl(dev_info_t *, dev_info_t *, ddi_dma_handle_t, enum ddi_dma_ctlops, 160 off_t *, size_t *, caddr_t *, uint_t); 161 162 static int 163 isa_ctlops(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); 164 165 static int 166 isa_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op, 167 ddi_intr_handle_impl_t *hdlp, void *result); 168 static int isa_alloc_intr_fixed(dev_info_t *, ddi_intr_handle_impl_t *, void *); 169 static int isa_free_intr_fixed(dev_info_t *, ddi_intr_handle_impl_t *); 170 171 struct bus_ops isa_bus_ops = { 172 BUSO_REV, 173 isa_bus_map, 174 NULL, 175 NULL, 176 NULL, 177 i_ddi_map_fault, 178 NULL, 179 isa_dma_allochdl, 180 ddi_dma_freehdl, 181 ddi_dma_bindhdl, 182 ddi_dma_unbindhdl, 183 ddi_dma_flush, 184 ddi_dma_win, 185 isa_dma_mctl, 186 isa_ctlops, 187 ddi_bus_prop_op, 188 NULL, /* (*bus_get_eventcookie)(); */ 189 NULL, /* (*bus_add_eventcall)(); */ 190 NULL, /* (*bus_remove_eventcall)(); */ 191 NULL, /* (*bus_post_event)(); */ 192 NULL, /* (*bus_intr_ctl)(); */ 193 NULL, /* (*bus_config)(); */ 194 NULL, /* (*bus_unconfig)(); */ 195 NULL, /* (*bus_fm_init)(); */ 196 NULL, /* (*bus_fm_fini)(); */ 197 NULL, /* (*bus_fm_access_enter)(); */ 198 NULL, /* (*bus_fm_access_exit)(); */ 199 NULL, /* (*bus_power)(); */ 200 isa_intr_ops /* (*bus_intr_op)(); */ 201 }; 202 203 204 static int isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd); 205 206 /* 207 * Internal isa ctlops support routines 208 */ 209 static int isa_initchild(dev_info_t *child); 210 211 struct dev_ops isa_ops = { 212 DEVO_REV, /* devo_rev, */ 213 0, /* refcnt */ 214 ddi_no_info, /* info */ 215 nulldev, /* identify */ 216 nulldev, /* probe */ 217 isa_attach, /* attach */ 218 nulldev, /* detach */ 219 nodev, /* reset */ 220 (struct cb_ops *)0, /* driver operations */ 221 &isa_bus_ops, /* bus operations */ 222 NULL, /* power */ 223 ddi_quiesce_not_needed, /* quiesce */ 224 }; 225 226 /* 227 * Module linkage information for the kernel. 228 */ 229 230 static struct modldrv modldrv = { 231 &mod_driverops, /* Type of module. This is ISA bus driver */ 232 "isa nexus driver for 'ISA'", 233 &isa_ops, /* driver ops */ 234 }; 235 236 static struct modlinkage modlinkage = { 237 MODREV_1, 238 &modldrv, 239 NULL 240 }; 241 242 int 243 _init(void) 244 { 245 int err; 246 char tty_irq_param[9] = "ttyX-irq"; 247 char *tty_irq; 248 int i; 249 250 if ((err = mod_install(&modlinkage)) != 0) 251 return (err); 252 253 /* Check if any tty irqs are overridden by eeprom config */ 254 for (i = 0; i < num_BIOS_serial; i++) { 255 tty_irq_param[3] = 'a' + i; 256 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 257 DDI_PROP_DONTPASS, tty_irq_param, &tty_irq) 258 == DDI_PROP_SUCCESS) { 259 long data; 260 261 if (ddi_strtol(tty_irq, NULL, 0, &data) == 0) { 262 asy_intrs[i] = (int)data; 263 asy_intr_override |= 1<<i; 264 } 265 266 ddi_prop_free(tty_irq); 267 } 268 } 269 270 impl_bus_add_probe(isa_enumerate); 271 return (0); 272 } 273 274 int 275 _fini(void) 276 { 277 int err; 278 279 impl_bus_delete_probe(isa_enumerate); 280 281 if ((err = mod_remove(&modlinkage)) != 0) 282 return (err); 283 284 return (0); 285 } 286 287 int 288 _info(struct modinfo *modinfop) 289 { 290 return (mod_info(&modlinkage, modinfop)); 291 } 292 293 static int 294 isa_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 295 { 296 int rval; 297 298 #if defined(__xpv) 299 /* 300 * don't allow isa to attach in domU. this can happen if someone sets 301 * the console wrong, etc. ISA devices assume the H/W is there and 302 * will cause the domU to panic. 303 */ 304 if (!DOMAIN_IS_INITDOMAIN(xen_info)) { 305 return (DDI_FAILURE); 306 } 307 #endif 308 309 switch (cmd) { 310 case DDI_ATTACH: 311 break; 312 case DDI_RESUME: 313 return (DDI_SUCCESS); 314 default: 315 return (DDI_FAILURE); 316 } 317 318 if ((rval = i_dmae_init(devi)) == DDI_SUCCESS) 319 ddi_report_dev(devi); 320 321 return (rval); 322 } 323 324 #define SET_RNGS(rng_p, used_p, ctyp, ptyp) do { \ 325 (rng_p)->child_high = (ctyp); \ 326 (rng_p)->child_low = (rng_p)->parent_low = (used_p)->base; \ 327 (rng_p)->parent_high = (ptyp); \ 328 (rng_p)->parent_mid = 0; \ 329 (rng_p)->size = (used_p)->len; \ 330 _NOTE(CONSTCOND) } while (0) 331 static uint_t 332 isa_used_to_ranges(int ctype, int *array, uint_t size, pib_ranges_t *ranges) 333 { 334 used_ranges_t *used_p; 335 pib_ranges_t *rng_p = ranges; 336 uint_t i, ptype; 337 338 ptype = (ctype == ISA_ADDR_IO) ? PCI_ADDR_IO : PCI_ADDR_MEM32; 339 ptype |= PCI_REG_REL_M; 340 size /= USED_CELL_SIZE; 341 used_p = (used_ranges_t *)array; 342 SET_RNGS(rng_p, used_p, ctype, ptype); 343 for (i = 1, used_p++; i < size; i++, used_p++) { 344 /* merge ranges record if applicable */ 345 if (rng_p->child_low + rng_p->size == used_p->base) 346 rng_p->size += used_p->len; 347 else { 348 rng_p++; 349 SET_RNGS(rng_p, used_p, ctype, ptype); 350 } 351 } 352 return (rng_p - ranges + 1); 353 } 354 355 void 356 isa_remove_res_from_pci(int type, int *array, uint_t size) 357 { 358 int i; 359 used_ranges_t *used_p; 360 361 size /= USED_CELL_SIZE; 362 used_p = (used_ranges_t *)array; 363 for (i = 0; i < size; i++, used_p++) 364 pci_register_isa_resources(type, used_p->base, used_p->len); 365 } 366 367 static void 368 isa_create_ranges_prop(dev_info_t *dip) 369 { 370 dev_info_t *used; 371 int *ioarray, *memarray, status; 372 uint_t nio = 0, nmem = 0, nrng = 0, n; 373 pib_ranges_t *ranges; 374 375 used = ddi_find_devinfo(USED_RESOURCES, -1, 0); 376 if (used == NULL) { 377 cmn_err(CE_WARN, "Failed to find used-resources <%s>\n", 378 ddi_get_name(dip)); 379 return; 380 } 381 status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, used, 382 DDI_PROP_DONTPASS, "io-space", &ioarray, &nio); 383 if (status != DDI_PROP_SUCCESS && status != DDI_PROP_NOT_FOUND) { 384 cmn_err(CE_WARN, "io-space property failure for %s (%x)\n", 385 ddi_get_name(used), status); 386 return; 387 } 388 status = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, used, 389 DDI_PROP_DONTPASS, "device-memory", &memarray, &nmem); 390 if (status != DDI_PROP_SUCCESS && status != DDI_PROP_NOT_FOUND) { 391 cmn_err(CE_WARN, "device-memory property failure for %s (%x)\n", 392 ddi_get_name(used), status); 393 return; 394 } 395 n = (nio + nmem) / USED_CELL_SIZE; 396 ranges = (pib_ranges_t *)kmem_zalloc(sizeof (pib_ranges_t) * n, 397 KM_SLEEP); 398 399 if (nio != 0) { 400 nrng = isa_used_to_ranges(ISA_ADDR_IO, ioarray, nio, ranges); 401 isa_remove_res_from_pci(ISA_ADDR_IO, ioarray, nio); 402 ddi_prop_free(ioarray); 403 } 404 if (nmem != 0) { 405 nrng += isa_used_to_ranges(ISA_ADDR_MEM, memarray, nmem, 406 ranges + nrng); 407 isa_remove_res_from_pci(ISA_ADDR_MEM, memarray, nmem); 408 ddi_prop_free(memarray); 409 } 410 411 if (!pseudo_isa) 412 (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, dip, "ranges", 413 (int *)ranges, nrng * sizeof (pib_ranges_t) / sizeof (int)); 414 kmem_free(ranges, sizeof (pib_ranges_t) * n); 415 } 416 417 /*ARGSUSED*/ 418 static int 419 isa_apply_range(dev_info_t *dip, struct regspec *isa_reg_p, 420 pci_regspec_t *pci_reg_p) 421 { 422 pib_ranges_t *ranges, *rng_p; 423 int len, i, offset, nrange; 424 425 if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 426 "ranges", (caddr_t)&ranges, &len) != DDI_SUCCESS) { 427 cmn_err(CE_WARN, "Can't get %s ranges property", 428 ddi_get_name(dip)); 429 return (DDI_ME_REGSPEC_RANGE); 430 } 431 nrange = len / sizeof (pib_ranges_t); 432 rng_p = ranges; 433 for (i = 0; i < nrange; i++, rng_p++) { 434 /* Check for correct space */ 435 if (isa_reg_p->regspec_bustype != rng_p->child_high) 436 continue; 437 438 /* Detect whether request entirely fits within a range */ 439 if (isa_reg_p->regspec_addr < rng_p->child_low) 440 continue; 441 if ((isa_reg_p->regspec_addr + isa_reg_p->regspec_size - 1) > 442 (rng_p->child_low + rng_p->size - 1)) 443 continue; 444 445 offset = isa_reg_p->regspec_addr - rng_p->child_low; 446 447 pci_reg_p->pci_phys_hi = rng_p->parent_high; 448 pci_reg_p->pci_phys_mid = 0; 449 pci_reg_p->pci_phys_low = rng_p->parent_low + offset; 450 pci_reg_p->pci_size_hi = 0; 451 pci_reg_p->pci_size_low = isa_reg_p->regspec_size; 452 453 break; 454 } 455 kmem_free(ranges, len); 456 457 if (i < nrange) 458 return (DDI_SUCCESS); 459 460 /* 461 * Check extra resource range specially for serial and parallel 462 * devices, which are treated differently from all other ISA 463 * devices. On some machines, serial ports are not enumerated 464 * by ACPI but by BIOS, with io base addresses noted in legacy 465 * BIOS data area. Parallel port on some machines comes with 466 * illegal size. 467 */ 468 if (isa_reg_p->regspec_bustype != ISA_ADDR_IO) { 469 cmn_err(CE_WARN, "Bus type not ISA I/O\n"); 470 return (DDI_ME_REGSPEC_RANGE); 471 } 472 473 for (i = 0; i < isa_extra_count; i++) { 474 struct regspec *reg_p = &isa_extra_resource[i]; 475 476 if (isa_reg_p->regspec_addr < reg_p->regspec_addr) 477 continue; 478 if ((isa_reg_p->regspec_addr + isa_reg_p->regspec_size) > 479 (reg_p->regspec_addr + reg_p->regspec_size)) 480 continue; 481 482 pci_reg_p->pci_phys_hi = PCI_ADDR_IO | PCI_REG_REL_M; 483 pci_reg_p->pci_phys_mid = 0; 484 pci_reg_p->pci_phys_low = isa_reg_p->regspec_addr; 485 pci_reg_p->pci_size_hi = 0; 486 pci_reg_p->pci_size_low = isa_reg_p->regspec_size; 487 break; 488 } 489 if (i < isa_extra_count) 490 return (DDI_SUCCESS); 491 492 cmn_err(CE_WARN, "isa_apply_range: Out of range base <0x%x>, size <%d>", 493 isa_reg_p->regspec_addr, isa_reg_p->regspec_size); 494 return (DDI_ME_REGSPEC_RANGE); 495 } 496 497 static int 498 isa_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 499 off_t offset, off_t len, caddr_t *vaddrp) 500 { 501 struct regspec tmp_reg, *rp; 502 pci_regspec_t vreg; 503 ddi_map_req_t mr = *mp; /* Get private copy of request */ 504 int error; 505 506 if (pseudo_isa) 507 return (i_ddi_bus_map(dip, rdip, mp, offset, len, vaddrp)); 508 509 mp = &mr; 510 511 /* 512 * First, if given an rnumber, convert it to a regspec... 513 */ 514 if (mp->map_type == DDI_MT_RNUMBER) { 515 516 int rnumber = mp->map_obj.rnumber; 517 518 rp = i_ddi_rnumber_to_regspec(rdip, rnumber); 519 if (rp == (struct regspec *)0) 520 return (DDI_ME_RNUMBER_RANGE); 521 522 /* 523 * Convert the given ddi_map_req_t from rnumber to regspec... 524 */ 525 mp->map_type = DDI_MT_REGSPEC; 526 mp->map_obj.rp = rp; 527 } 528 529 /* 530 * Adjust offset and length correspnding to called values... 531 * XXX: A non-zero length means override the one in the regspec. 532 * XXX: (Regardless of what's in the parent's range) 533 */ 534 535 tmp_reg = *(mp->map_obj.rp); /* Preserve underlying data */ 536 rp = mp->map_obj.rp = &tmp_reg; /* Use tmp_reg in request */ 537 538 rp->regspec_addr += (uint_t)offset; 539 if (len != 0) 540 rp->regspec_size = (uint_t)len; 541 542 if ((error = isa_apply_range(dip, rp, &vreg)) != 0) 543 return (error); 544 mp->map_obj.rp = (struct regspec *)&vreg; 545 546 /* 547 * Call my parents bus_map function with modified values... 548 */ 549 550 return (ddi_map(dip, mp, (off_t)0, (off_t)0, vaddrp)); 551 } 552 553 static int 554 isa_dma_allochdl(dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *dma_attr, 555 int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep) 556 { 557 ddi_dma_attr_merge(dma_attr, &ISA_dma_attr); 558 return (ddi_dma_allochdl(dip, rdip, dma_attr, waitfp, arg, handlep)); 559 } 560 561 static int 562 isa_dma_mctl(dev_info_t *dip, dev_info_t *rdip, 563 ddi_dma_handle_t handle, enum ddi_dma_ctlops request, 564 off_t *offp, size_t *lenp, caddr_t *objp, uint_t flags) 565 { 566 int rval; 567 int arg = (int)(uintptr_t)objp; 568 569 switch (request) { 570 571 case DDI_DMA_E_PROG: 572 return (i_dmae_prog(rdip, (struct ddi_dmae_req *)offp, 573 (ddi_dma_cookie_t *)lenp, arg)); 574 575 case DDI_DMA_E_ACQUIRE: 576 return (i_dmae_acquire(rdip, arg, (int(*)(caddr_t))offp, 577 (caddr_t)lenp)); 578 579 case DDI_DMA_E_FREE: 580 return (i_dmae_free(rdip, arg)); 581 582 case DDI_DMA_E_STOP: 583 i_dmae_stop(rdip, arg); 584 return (DDI_SUCCESS); 585 586 case DDI_DMA_E_ENABLE: 587 i_dmae_enable(rdip, arg); 588 return (DDI_SUCCESS); 589 590 case DDI_DMA_E_DISABLE: 591 i_dmae_disable(rdip, arg); 592 return (DDI_SUCCESS); 593 594 case DDI_DMA_E_GETCNT: 595 i_dmae_get_chan_stat(rdip, arg, NULL, (int *)lenp); 596 return (DDI_SUCCESS); 597 598 case DDI_DMA_E_SWSETUP: 599 return (i_dmae_swsetup(rdip, (struct ddi_dmae_req *)offp, 600 (ddi_dma_cookie_t *)lenp, arg)); 601 602 case DDI_DMA_E_SWSTART: 603 i_dmae_swstart(rdip, arg); 604 return (DDI_SUCCESS); 605 606 case DDI_DMA_E_GETATTR: 607 bcopy(&ISA_dma_attr, objp, sizeof (ddi_dma_attr_t)); 608 return (DDI_SUCCESS); 609 610 case DDI_DMA_E_1STPTY: 611 { 612 struct ddi_dmae_req req1stpty = 613 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; 614 if (arg == 0) { 615 req1stpty.der_command = DMAE_CMD_TRAN; 616 req1stpty.der_trans = DMAE_TRANS_DMND; 617 } else { 618 req1stpty.der_trans = DMAE_TRANS_CSCD; 619 } 620 return (i_dmae_prog(rdip, &req1stpty, NULL, arg)); 621 } 622 623 default: 624 /* 625 * We pass to rootnex, but it turns out that rootnex will just 626 * return failure, as we don't use ddi_dma_mctl() except 627 * for DMA engine (ISA) and DVMA (SPARC). Arguably we could 628 * just return an error direclty here, instead. 629 */ 630 rval = ddi_dma_mctl(dip, rdip, handle, request, offp, 631 lenp, objp, flags); 632 } 633 return (rval); 634 } 635 636 /* 637 * Check if driver should be treated as an old pre 2.6 driver 638 */ 639 static int 640 old_driver(dev_info_t *dip) 641 { 642 extern int ignore_hardware_nodes; /* force flag from ddi_impl.c */ 643 644 if (ndi_dev_is_persistent_node(dip)) { 645 if (ignore_hardware_nodes) 646 return (1); 647 if (ddi_getprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 648 "ignore-hardware-nodes", -1) != -1) 649 return (1); 650 } 651 return (0); 652 } 653 654 typedef struct { 655 uint32_t phys_hi; 656 uint32_t phys_lo; 657 uint32_t size; 658 } isa_regs_t; 659 660 /* 661 * Return non-zero if device in tree is a PnP isa device 662 */ 663 static int 664 is_pnpisa(dev_info_t *dip) 665 { 666 isa_regs_t *isa_regs; 667 int proplen, pnpisa; 668 669 if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "reg", 670 (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) { 671 return (0); 672 } 673 pnpisa = isa_regs[0].phys_hi & 0x80000000; 674 /* 675 * free the memory allocated by ddi_getlongprop(). 676 */ 677 kmem_free(isa_regs, proplen); 678 if (pnpisa) 679 return (1); 680 else 681 return (0); 682 } 683 684 /*ARGSUSED*/ 685 static int 686 isa_ctlops(dev_info_t *dip, dev_info_t *rdip, 687 ddi_ctl_enum_t ctlop, void *arg, void *result) 688 { 689 int rn; 690 struct ddi_parent_private_data *pdp; 691 692 switch (ctlop) { 693 case DDI_CTLOPS_REPORTDEV: 694 if (rdip == (dev_info_t *)0) 695 return (DDI_FAILURE); 696 cmn_err(CE_CONT, "?ISA-device: %s%d\n", 697 ddi_driver_name(rdip), ddi_get_instance(rdip)); 698 return (DDI_SUCCESS); 699 700 case DDI_CTLOPS_INITCHILD: 701 /* 702 * older drivers aren't expecting the "standard" device 703 * node format used by the hardware nodes. these drivers 704 * only expect their own properties set in their driver.conf 705 * files. so they tell us not to call them with hardware 706 * nodes by setting the property "ignore-hardware-nodes". 707 */ 708 if (old_driver((dev_info_t *)arg)) { 709 return (DDI_NOT_WELL_FORMED); 710 } 711 712 return (isa_initchild((dev_info_t *)arg)); 713 714 case DDI_CTLOPS_UNINITCHILD: 715 impl_ddi_sunbus_removechild((dev_info_t *)arg); 716 return (DDI_SUCCESS); 717 718 case DDI_CTLOPS_SIDDEV: 719 if (ndi_dev_is_persistent_node(rdip)) 720 return (DDI_SUCCESS); 721 /* 722 * All ISA devices need to do confirming probes 723 * unless they are PnP ISA. 724 */ 725 if (is_pnpisa(rdip)) 726 return (DDI_SUCCESS); 727 else 728 return (DDI_FAILURE); 729 730 case DDI_CTLOPS_REGSIZE: 731 case DDI_CTLOPS_NREGS: 732 if (rdip == (dev_info_t *)0) 733 return (DDI_FAILURE); 734 735 if ((pdp = ddi_get_parent_data(rdip)) == NULL) 736 return (DDI_FAILURE); 737 738 if (ctlop == DDI_CTLOPS_NREGS) { 739 *(int *)result = pdp->par_nreg; 740 } else { 741 rn = *(int *)arg; 742 if (rn >= pdp->par_nreg) 743 return (DDI_FAILURE); 744 *(off_t *)result = (off_t)pdp->par_reg[rn].regspec_size; 745 } 746 return (DDI_SUCCESS); 747 748 case DDI_CTLOPS_ATTACH: 749 case DDI_CTLOPS_DETACH: 750 case DDI_CTLOPS_PEEK: 751 case DDI_CTLOPS_POKE: 752 return (DDI_FAILURE); 753 754 default: 755 return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 756 } 757 } 758 759 static struct intrspec * 760 isa_get_ispec(dev_info_t *rdip, int inum) 761 { 762 struct ddi_parent_private_data *pdp = ddi_get_parent_data(rdip); 763 764 /* Validate the interrupt number */ 765 if (inum >= pdp->par_nintr) 766 return (NULL); 767 768 /* Get the interrupt structure pointer and return that */ 769 return ((struct intrspec *)&pdp->par_intr[inum]); 770 } 771 772 static int 773 isa_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t intr_op, 774 ddi_intr_handle_impl_t *hdlp, void *result) 775 { 776 struct intrspec *ispec; 777 #if defined(__xpv) 778 int cons, ttyn; 779 780 cons = console_hypervisor_dev_type(&ttyn); 781 #endif 782 if (pseudo_isa) 783 return (i_ddi_intr_ops(pdip, rdip, intr_op, hdlp, result)); 784 785 786 /* Process the interrupt operation */ 787 switch (intr_op) { 788 case DDI_INTROP_GETCAP: 789 /* First check with pcplusmp */ 790 if (psm_intr_ops == NULL) 791 return (DDI_FAILURE); 792 793 if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_GET_CAP, result)) { 794 *(int *)result = 0; 795 return (DDI_FAILURE); 796 } 797 break; 798 case DDI_INTROP_SETCAP: 799 if (psm_intr_ops == NULL) 800 return (DDI_FAILURE); 801 802 if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_CAP, result)) 803 return (DDI_FAILURE); 804 break; 805 case DDI_INTROP_ALLOC: 806 ASSERT(hdlp->ih_type == DDI_INTR_TYPE_FIXED); 807 return (isa_alloc_intr_fixed(rdip, hdlp, result)); 808 case DDI_INTROP_FREE: 809 ASSERT(hdlp->ih_type == DDI_INTR_TYPE_FIXED); 810 return (isa_free_intr_fixed(rdip, hdlp)); 811 case DDI_INTROP_GETPRI: 812 if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL) 813 return (DDI_FAILURE); 814 *(int *)result = ispec->intrspec_pri; 815 break; 816 case DDI_INTROP_SETPRI: 817 /* Validate the interrupt priority passed to us */ 818 if (*(int *)result > LOCK_LEVEL) 819 return (DDI_FAILURE); 820 821 /* Ensure that PSM is all initialized and ispec is ok */ 822 if ((psm_intr_ops == NULL) || 823 ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL)) 824 return (DDI_FAILURE); 825 826 /* update the ispec with the new priority */ 827 ispec->intrspec_pri = *(int *)result; 828 break; 829 case DDI_INTROP_ADDISR: 830 if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL) 831 return (DDI_FAILURE); 832 ispec->intrspec_func = hdlp->ih_cb_func; 833 break; 834 case DDI_INTROP_REMISR: 835 if (hdlp->ih_type != DDI_INTR_TYPE_FIXED) 836 return (DDI_FAILURE); 837 if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL) 838 return (DDI_FAILURE); 839 ispec->intrspec_func = (uint_t (*)()) 0; 840 break; 841 case DDI_INTROP_ENABLE: 842 if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL) 843 return (DDI_FAILURE); 844 845 /* Call psmi to translate irq with the dip */ 846 if (psm_intr_ops == NULL) 847 return (DDI_FAILURE); 848 849 #if defined(__xpv) 850 /* 851 * if the hypervisor is using an isa serial port for the 852 * console, make sure we don't try to use that interrupt as 853 * it will cause us to panic when xen_bind_pirq() fails. 854 */ 855 if (cons == CONS_TTY && ispec->intrspec_vec == asy_intrs[ttyn]) 856 return (DDI_FAILURE); 857 #endif 858 ((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec; 859 if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_XLATE_VECTOR, 860 (int *)&hdlp->ih_vector) == PSM_FAILURE) 861 return (DDI_FAILURE); 862 863 /* Add the interrupt handler */ 864 if (!add_avintr((void *)hdlp, ispec->intrspec_pri, 865 hdlp->ih_cb_func, DEVI(rdip)->devi_name, hdlp->ih_vector, 866 hdlp->ih_cb_arg1, hdlp->ih_cb_arg2, NULL, rdip)) 867 return (DDI_FAILURE); 868 break; 869 case DDI_INTROP_DISABLE: 870 if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL) 871 return (DDI_FAILURE); 872 873 /* Call psm_ops() to translate irq with the dip */ 874 if (psm_intr_ops == NULL) 875 return (DDI_FAILURE); 876 877 ((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec; 878 (void) (*psm_intr_ops)(rdip, hdlp, 879 PSM_INTR_OP_XLATE_VECTOR, (int *)&hdlp->ih_vector); 880 881 /* Remove the interrupt handler */ 882 rem_avintr((void *)hdlp, ispec->intrspec_pri, 883 hdlp->ih_cb_func, hdlp->ih_vector); 884 break; 885 case DDI_INTROP_SETMASK: 886 if (psm_intr_ops == NULL) 887 return (DDI_FAILURE); 888 889 if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_SET_MASK, NULL)) 890 return (DDI_FAILURE); 891 break; 892 case DDI_INTROP_CLRMASK: 893 if (psm_intr_ops == NULL) 894 return (DDI_FAILURE); 895 896 if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_CLEAR_MASK, NULL)) 897 return (DDI_FAILURE); 898 break; 899 case DDI_INTROP_GETPENDING: 900 if (psm_intr_ops == NULL) 901 return (DDI_FAILURE); 902 903 if ((*psm_intr_ops)(rdip, hdlp, PSM_INTR_OP_GET_PENDING, 904 result)) { 905 *(int *)result = 0; 906 return (DDI_FAILURE); 907 } 908 break; 909 case DDI_INTROP_NAVAIL: 910 case DDI_INTROP_NINTRS: 911 *(int *)result = i_ddi_get_intx_nintrs(rdip); 912 if (*(int *)result == 0) { 913 return (DDI_FAILURE); 914 } 915 break; 916 case DDI_INTROP_SUPPORTED_TYPES: 917 *(int *)result = DDI_INTR_TYPE_FIXED; /* Always ... */ 918 break; 919 default: 920 return (DDI_FAILURE); 921 } 922 923 return (DDI_SUCCESS); 924 } 925 926 /* 927 * Allocate interrupt vector for FIXED (legacy) type. 928 */ 929 static int 930 isa_alloc_intr_fixed(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp, 931 void *result) 932 { 933 struct intrspec *ispec; 934 ddi_intr_handle_impl_t info_hdl; 935 int ret; 936 int free_phdl = 0; 937 apic_get_type_t type_info; 938 939 if (psm_intr_ops == NULL) 940 return (DDI_FAILURE); 941 942 if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL) 943 return (DDI_FAILURE); 944 945 /* 946 * If the PSM module is "APIX" then pass the request for it 947 * to allocate the vector now. 948 */ 949 bzero(&info_hdl, sizeof (ddi_intr_handle_impl_t)); 950 info_hdl.ih_private = &type_info; 951 if ((*psm_intr_ops)(NULL, &info_hdl, PSM_INTR_OP_APIC_TYPE, NULL) == 952 PSM_SUCCESS && strcmp(type_info.avgi_type, APIC_APIX_NAME) == 0) { 953 if (hdlp->ih_private == NULL) { /* allocate phdl structure */ 954 free_phdl = 1; 955 i_ddi_alloc_intr_phdl(hdlp); 956 } 957 ((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec; 958 ret = (*psm_intr_ops)(rdip, hdlp, 959 PSM_INTR_OP_ALLOC_VECTORS, result); 960 if (free_phdl) { /* free up the phdl structure */ 961 free_phdl = 0; 962 i_ddi_free_intr_phdl(hdlp); 963 hdlp->ih_private = NULL; 964 } 965 } else { 966 /* 967 * No APIX module; fall back to the old scheme where the 968 * interrupt vector is allocated during ddi_enable_intr() call. 969 */ 970 hdlp->ih_pri = ispec->intrspec_pri; 971 *(int *)result = hdlp->ih_scratch1; 972 ret = DDI_SUCCESS; 973 } 974 975 return (ret); 976 } 977 978 /* 979 * Free up interrupt vector for FIXED (legacy) type. 980 */ 981 static int 982 isa_free_intr_fixed(dev_info_t *rdip, ddi_intr_handle_impl_t *hdlp) 983 { 984 struct intrspec *ispec; 985 ddi_intr_handle_impl_t info_hdl; 986 int ret; 987 apic_get_type_t type_info; 988 989 if (psm_intr_ops == NULL) 990 return (DDI_FAILURE); 991 992 /* 993 * If the PSM module is "APIX" then pass the request for it 994 * to free up the vector now. 995 */ 996 bzero(&info_hdl, sizeof (ddi_intr_handle_impl_t)); 997 info_hdl.ih_private = &type_info; 998 if ((*psm_intr_ops)(NULL, &info_hdl, PSM_INTR_OP_APIC_TYPE, NULL) == 999 PSM_SUCCESS && strcmp(type_info.avgi_type, APIC_APIX_NAME) == 0) { 1000 if ((ispec = isa_get_ispec(rdip, hdlp->ih_inum)) == NULL) 1001 return (DDI_FAILURE); 1002 ((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispec; 1003 ret = (*psm_intr_ops)(rdip, hdlp, 1004 PSM_INTR_OP_FREE_VECTORS, NULL); 1005 } else { 1006 /* 1007 * No APIX module; fall back to the old scheme where 1008 * the interrupt vector was already freed during 1009 * ddi_disable_intr() call. 1010 */ 1011 ret = DDI_SUCCESS; 1012 } 1013 1014 return (ret); 1015 } 1016 1017 static void 1018 isa_vendor(uint32_t id, char *vendor) 1019 { 1020 vendor[0] = '@' + ((id >> 26) & 0x1f); 1021 vendor[1] = '@' + ((id >> 21) & 0x1f); 1022 vendor[2] = '@' + ((id >> 16) & 0x1f); 1023 vendor[3] = 0; 1024 } 1025 1026 /* 1027 * Name a child 1028 */ 1029 static int 1030 isa_name_child(dev_info_t *child, char *name, int namelen) 1031 { 1032 char vendor[8]; 1033 int device; 1034 uint32_t serial; 1035 int func; 1036 int bustype; 1037 uint32_t base; 1038 int proplen; 1039 int pnpisa = 0; 1040 isa_regs_t *isa_regs; 1041 1042 void make_ddi_ppd(dev_info_t *, struct ddi_parent_private_data **); 1043 1044 /* 1045 * older drivers aren't expecting the "standard" device 1046 * node format used by the hardware nodes. these drivers 1047 * only expect their own properties set in their driver.conf 1048 * files. so they tell us not to call them with hardware 1049 * nodes by setting the property "ignore-hardware-nodes". 1050 */ 1051 if (old_driver(child)) 1052 return (DDI_FAILURE); 1053 1054 /* 1055 * Fill in parent-private data 1056 */ 1057 if (ddi_get_parent_data(child) == NULL) { 1058 struct ddi_parent_private_data *pdptr; 1059 make_ddi_ppd(child, &pdptr); 1060 ddi_set_parent_data(child, pdptr); 1061 } 1062 1063 if (ndi_dev_is_persistent_node(child) == 0) { 1064 /* 1065 * For .conf nodes, generate name from parent private data 1066 */ 1067 name[0] = '\0'; 1068 if (sparc_pd_getnreg(child) > 0) { 1069 (void) snprintf(name, namelen, "%x,%x", 1070 (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype, 1071 (uint_t)sparc_pd_getreg(child, 0)->regspec_addr); 1072 } 1073 return (DDI_SUCCESS); 1074 } 1075 1076 /* 1077 * For hw nodes, look up "reg" property 1078 */ 1079 if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, "reg", 1080 (caddr_t)&isa_regs, &proplen) != DDI_PROP_SUCCESS) { 1081 return (DDI_FAILURE); 1082 } 1083 1084 /* 1085 * extract the device identifications 1086 */ 1087 pnpisa = isa_regs[0].phys_hi & 0x80000000; 1088 if (pnpisa) { 1089 isa_vendor(isa_regs[0].phys_hi, vendor); 1090 device = isa_regs[0].phys_hi & 0xffff; 1091 serial = isa_regs[0].phys_lo; 1092 func = (isa_regs[0].size >> 24) & 0xff; 1093 if (func != 0) 1094 (void) snprintf(name, namelen, "pnp%s,%04x,%x,%x", 1095 vendor, device, serial, func); 1096 else 1097 (void) snprintf(name, namelen, "pnp%s,%04x,%x", 1098 vendor, device, serial); 1099 } else { 1100 bustype = isa_regs[0].phys_hi; 1101 base = isa_regs[0].phys_lo; 1102 (void) sprintf(name, "%x,%x", bustype, base); 1103 } 1104 1105 /* 1106 * free the memory allocated by ddi_getlongprop(). 1107 */ 1108 kmem_free(isa_regs, proplen); 1109 1110 return (DDI_SUCCESS); 1111 } 1112 1113 static int 1114 isa_initchild(dev_info_t *child) 1115 { 1116 char name[80]; 1117 1118 if (isa_name_child(child, name, 80) != DDI_SUCCESS) 1119 return (DDI_FAILURE); 1120 ddi_set_name_addr(child, name); 1121 1122 if (ndi_dev_is_persistent_node(child) != 0) 1123 return (DDI_SUCCESS); 1124 1125 /* 1126 * This is a .conf node, try merge properties onto a 1127 * hw node with the same name. 1128 */ 1129 if (ndi_merge_node(child, isa_name_child) == DDI_SUCCESS) { 1130 /* 1131 * Return failure to remove node 1132 */ 1133 impl_ddi_sunbus_removechild(child); 1134 return (DDI_FAILURE); 1135 } 1136 /* 1137 * Cannot merge node, permit pseudo children 1138 */ 1139 return (DDI_SUCCESS); 1140 } 1141 1142 /* 1143 * called when ACPI enumeration is not used 1144 */ 1145 static void 1146 add_known_used_resources(void) 1147 { 1148 /* needs to be in increasing order */ 1149 int intr[] = {0x1, 0x3, 0x4, 0x6, 0x7, 0xc}; 1150 int dma[] = {0x2}; 1151 int io[] = {0x60, 0x1, 0x64, 0x1, 0x2f8, 0x8, 0x378, 0x8, 0x3f0, 0x10, 1152 0x778, 0x4}; 1153 dev_info_t *usedrdip; 1154 1155 usedrdip = ddi_find_devinfo(USED_RESOURCES, -1, 0); 1156 1157 if (usedrdip == NULL) { 1158 (void) ndi_devi_alloc_sleep(ddi_root_node(), USED_RESOURCES, 1159 (pnode_t)DEVI_SID_NODEID, &usedrdip); 1160 } 1161 1162 (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip, 1163 "interrupts", (int *)intr, (int)(sizeof (intr) / sizeof (int))); 1164 (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip, 1165 "io-space", (int *)io, (int)(sizeof (io) / sizeof (int))); 1166 (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, usedrdip, 1167 "dma-channels", (int *)dma, (int)(sizeof (dma) / sizeof (int))); 1168 (void) ndi_devi_bind_driver(usedrdip, 0); 1169 1170 } 1171 1172 /* 1173 * Return non-zero if UART device exists. 1174 */ 1175 static int 1176 uart_exists(ushort_t port) 1177 { 1178 outb(port + COM_SCR, (char)0x5a); 1179 outb(port + COM_ISR, (char)0x00); 1180 return (inb(port + COM_SCR) == (char)0x5a); 1181 } 1182 1183 static void 1184 isa_enumerate(int reprogram) 1185 { 1186 int circ, i; 1187 dev_info_t *xdip; 1188 dev_info_t *isa_dip = ddi_find_devinfo("isa", -1, 0); 1189 1190 struct regspec i8042_regs[] = { 1191 {1, 0x60, 0x1}, 1192 {1, 0x64, 0x1} 1193 }; 1194 int i8042_intrs[] = {0x1, 0xc}; 1195 char *acpi_prop; 1196 int acpi_enum = 1; /* ACPI is default to be on */ 1197 #if defined(__xpv) 1198 int cons, ttyn; 1199 1200 cons = console_hypervisor_dev_type(&ttyn); 1201 #endif 1202 if (reprogram || !isa_dip) 1203 return; 1204 1205 bzero(isa_extra_resource, MAX_EXTRA_RESOURCE * sizeof (struct regspec)); 1206 1207 ndi_devi_enter(isa_dip, &circ); 1208 1209 if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 1210 DDI_PROP_DONTPASS, "acpi-enum", &acpi_prop) == DDI_PROP_SUCCESS) { 1211 acpi_enum = strcmp("off", acpi_prop); 1212 ddi_prop_free(acpi_prop); 1213 } 1214 1215 if (acpi_enum) { 1216 if (acpi_isa_device_enum(isa_dip)) { 1217 ndi_devi_exit(isa_dip, circ); 1218 if (isa_resource_setup() != NDI_SUCCESS) { 1219 cmn_err(CE_WARN, "isa nexus: isa " 1220 "resource setup failed"); 1221 } 1222 1223 /* serial ports? */ 1224 enumerate_BIOS_serial(isa_dip); 1225 1226 /* adjust parallel port size */ 1227 adjust_prtsz(isa_dip); 1228 1229 isa_create_ranges_prop(isa_dip); 1230 return; 1231 } 1232 cmn_err(CE_NOTE, "!Solaris did not detect ACPI BIOS"); 1233 } 1234 cmn_err(CE_NOTE, "!ACPI is off"); 1235 1236 /* serial ports */ 1237 for (i = 0; i < min_BIOS_serial; i++) { 1238 ushort_t addr = asy_regs[i].regspec_addr; 1239 if (!uart_exists(addr)) 1240 continue; 1241 #if defined(__xpv) 1242 if (cons == CONS_TTY && ttyn == i) 1243 continue; 1244 #endif 1245 ndi_devi_alloc_sleep(isa_dip, "asy", 1246 (pnode_t)DEVI_SID_NODEID, &xdip); 1247 (void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip, 1248 "compatible", "PNP0500"); 1249 /* This should be gotten from master file: */ 1250 (void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip, 1251 "model", "Standard PC COM port"); 1252 (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 1253 "reg", (int *)&asy_regs[i], 3); 1254 (void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip, 1255 "interrupts", asy_intrs[i]); 1256 (void) ndi_devi_bind_driver(xdip, 0); 1257 /* Adjusting isa_extra here causes a kernel dump later. */ 1258 } 1259 1260 /* i8042 node */ 1261 ndi_devi_alloc_sleep(isa_dip, "i8042", 1262 (pnode_t)DEVI_SID_NODEID, &xdip); 1263 (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 1264 "reg", (int *)i8042_regs, 6); 1265 (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 1266 "interrupts", (int *)i8042_intrs, 2); 1267 (void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip, 1268 "unit-address", "1,60"); 1269 (void) ndi_devi_bind_driver(xdip, 0); 1270 1271 add_known_used_resources(); 1272 1273 ndi_devi_exit(isa_dip, circ); 1274 1275 isa_create_ranges_prop(isa_dip); 1276 } 1277 1278 /* 1279 * On some machines, serial port 2 isn't listed in the ACPI table. 1280 * This function goes through the base I/O addresses and makes sure all 1281 * the serial ports there are in the dev_info tree. If any are missing, 1282 * this function will add them. 1283 */ 1284 1285 static void 1286 enumerate_BIOS_serial(dev_info_t *isa_dip) 1287 { 1288 int i; 1289 dev_info_t *xdip; 1290 int found; 1291 int ret; 1292 struct regspec *tmpregs; 1293 int tmpregs_len; 1294 #if defined(__xpv) 1295 int cons, ttyn; 1296 1297 cons = console_hypervisor_dev_type(&ttyn); 1298 #endif 1299 1300 /* 1301 * Scan the base I/O addresses of the first four serial ports. 1302 */ 1303 for (i = 0; i < num_BIOS_serial; i++) { 1304 ushort_t addr = asy_regs[i].regspec_addr; 1305 1306 /* Look for it in the dev_info tree */ 1307 found = 0; 1308 for (xdip = ddi_get_child(isa_dip); xdip != NULL; 1309 xdip = ddi_get_next_sibling(xdip)) { 1310 if (strncmp(ddi_node_name(xdip), "asy", 3) != 0) { 1311 /* skip non asy */ 1312 continue; 1313 } 1314 1315 /* Match by addr */ 1316 ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, xdip, 1317 DDI_PROP_DONTPASS, "reg", (int **)&tmpregs, 1318 (uint_t *)&tmpregs_len); 1319 if (ret != DDI_PROP_SUCCESS) { 1320 /* error */ 1321 continue; 1322 } 1323 1324 if (tmpregs->regspec_addr == addr) 1325 found = 1; 1326 1327 /* 1328 * Free the memory allocated by 1329 * ddi_prop_lookup_int_array(). 1330 */ 1331 ddi_prop_free(tmpregs); 1332 1333 if (found) { 1334 if (asy_intr_override & 1<<i) { 1335 (void) ndi_prop_update_int( 1336 DDI_DEV_T_NONE, xdip, 1337 "interrupts", asy_intrs[i]); 1338 } 1339 1340 break; 1341 } 1342 } 1343 1344 /* If not found, then add it */ 1345 if (!found && uart_exists(addr)) { 1346 ndi_devi_alloc_sleep(isa_dip, "asy", 1347 (pnode_t)DEVI_SID_NODEID, &xdip); 1348 (void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip, 1349 "compatible", "PNP0500"); 1350 /* This should be gotten from master file: */ 1351 (void) ndi_prop_update_string(DDI_DEV_T_NONE, xdip, 1352 "model", "Standard PC COM port"); 1353 (void) ndi_prop_update_int_array(DDI_DEV_T_NONE, xdip, 1354 "reg", (int *)&asy_regs[i], 3); 1355 (void) ndi_prop_update_int(DDI_DEV_T_NONE, xdip, 1356 "interrupts", asy_intrs[i]); 1357 (void) ndi_devi_bind_driver(xdip, 0); 1358 1359 ASSERT(isa_extra_count < MAX_EXTRA_RESOURCE); 1360 bcopy(&asy_regs[i], 1361 isa_extra_resource + isa_extra_count, 1362 sizeof (struct regspec)); 1363 isa_extra_count++; 1364 } 1365 } 1366 1367 /* 1368 * An asy node may have been attached via ACPI enumeration, or 1369 * directly from this file. Check each serial port to see if it 1370 * is in use by the hypervisor. If it is in use, then remove 1371 * the node from the device tree. 1372 */ 1373 #if defined(__xpv) 1374 i = 0; 1375 1376 for (xdip = ddi_get_child(isa_dip); xdip != NULL; ) { 1377 dev_info_t *curdip; 1378 1379 curdip = xdip; 1380 xdip = ddi_get_next_sibling(xdip); 1381 1382 if (strncmp(ddi_node_name(curdip), "asy", 3) != 0) 1383 continue; 1384 1385 if (cons == CONS_TTY && ttyn == i) { 1386 ret = ndi_devi_free(curdip); 1387 if (ret != DDI_SUCCESS) { 1388 cmn_err(CE_WARN, 1389 "could not remove asy%d node", i); 1390 } 1391 1392 cmn_err(CE_NOTE, "!asy%d unavailable, reserved" 1393 " to hypervisor", i); 1394 } 1395 1396 i++; 1397 } 1398 #endif 1399 1400 } 1401 1402 /* 1403 * Some machine comes with an illegal parallel port size of 3 1404 * bytes in ACPI, even parallel port mode is ECP. 1405 */ 1406 #define DEFAULT_PRT_SIZE 8 1407 static void 1408 adjust_prtsz(dev_info_t *isa_dip) 1409 { 1410 dev_info_t *cdip; 1411 struct regspec *regs_p, *extreg_p; 1412 int regs_len, nreg, i; 1413 char *name; 1414 1415 for (cdip = ddi_get_child(isa_dip); cdip != NULL; 1416 cdip = ddi_get_next_sibling(cdip)) { 1417 name = ddi_node_name(cdip); 1418 if ((strncmp(name, "lp", 2) != 0) || (strnlen(name, 3) != 2)) 1419 continue; /* skip non parallel */ 1420 1421 if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, cdip, 1422 DDI_PROP_DONTPASS, "reg", (int **)®s_p, 1423 (uint_t *)®s_len) != DDI_PROP_SUCCESS) 1424 continue; 1425 1426 nreg = regs_len / (sizeof (struct regspec) / sizeof (int)); 1427 for (i = 0; i < nreg; i++) { 1428 if (regs_p[i].regspec_size == DEFAULT_PRT_SIZE) 1429 continue; 1430 1431 ASSERT(isa_extra_count < MAX_EXTRA_RESOURCE); 1432 extreg_p = &isa_extra_resource[isa_extra_count++]; 1433 extreg_p->regspec_bustype = ISA_ADDR_IO; 1434 extreg_p->regspec_addr = regs_p[i].regspec_addr; 1435 extreg_p->regspec_size = DEFAULT_PRT_SIZE; 1436 } 1437 1438 ddi_prop_free(regs_p); 1439 } 1440 } 1441