10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51865Sdilpreet * Common Development and Distribution License (the "License"). 61865Sdilpreet * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 21*1900Seota 220Sstevel@tonic-gate /* 231242Scth * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * PC specific DDI implementation 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate #include <sys/types.h> 330Sstevel@tonic-gate #include <sys/autoconf.h> 340Sstevel@tonic-gate #include <sys/avintr.h> 350Sstevel@tonic-gate #include <sys/bootconf.h> 360Sstevel@tonic-gate #include <sys/conf.h> 370Sstevel@tonic-gate #include <sys/cpuvar.h> 380Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 390Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 400Sstevel@tonic-gate #include <sys/ethernet.h> 410Sstevel@tonic-gate #include <sys/fp.h> 420Sstevel@tonic-gate #include <sys/instance.h> 430Sstevel@tonic-gate #include <sys/kmem.h> 440Sstevel@tonic-gate #include <sys/machsystm.h> 450Sstevel@tonic-gate #include <sys/modctl.h> 460Sstevel@tonic-gate #include <sys/promif.h> 470Sstevel@tonic-gate #include <sys/prom_plat.h> 480Sstevel@tonic-gate #include <sys/sunndi.h> 490Sstevel@tonic-gate #include <sys/ndi_impldefs.h> 500Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 510Sstevel@tonic-gate #include <sys/sysmacros.h> 520Sstevel@tonic-gate #include <sys/systeminfo.h> 530Sstevel@tonic-gate #include <sys/utsname.h> 540Sstevel@tonic-gate #include <sys/atomic.h> 550Sstevel@tonic-gate #include <sys/spl.h> 560Sstevel@tonic-gate #include <sys/archsystm.h> 570Sstevel@tonic-gate #include <vm/seg_kmem.h> 580Sstevel@tonic-gate #include <sys/ontrap.h> 591865Sdilpreet #include <sys/fm/protocol.h> 600Sstevel@tonic-gate #include <sys/ramdisk.h> 610Sstevel@tonic-gate #include <sys/sunndi.h> 620Sstevel@tonic-gate #include <sys/vmem.h> 630Sstevel@tonic-gate #include <sys/pci_impl.h> 64916Sschwartz #include <sys/mach_intr.h> 65*1900Seota #include <vm/hat_i86.h> 66*1900Seota #include <sys/x86_archext.h> 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * DDI Boot Configuration 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate 720Sstevel@tonic-gate /* 730Sstevel@tonic-gate * No platform drivers on this platform 740Sstevel@tonic-gate */ 750Sstevel@tonic-gate char *platform_module_list[] = { 760Sstevel@tonic-gate (char *)0 770Sstevel@tonic-gate }; 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* pci bus resource maps */ 800Sstevel@tonic-gate struct pci_bus_resource *pci_bus_res; 810Sstevel@tonic-gate 820Sstevel@tonic-gate extern int root_is_svm; 830Sstevel@tonic-gate uint64_t ramdisk_start, ramdisk_end; 840Sstevel@tonic-gate 850Sstevel@tonic-gate /* 860Sstevel@tonic-gate * Forward declarations 870Sstevel@tonic-gate */ 880Sstevel@tonic-gate static int getlongprop_buf(); 890Sstevel@tonic-gate static void get_boot_properties(void); 900Sstevel@tonic-gate static void impl_bus_initialprobe(void); 910Sstevel@tonic-gate static void impl_bus_reprobe(void); 920Sstevel@tonic-gate 930Sstevel@tonic-gate static int poke_mem(peekpoke_ctlops_t *in_args); 940Sstevel@tonic-gate static int peek_mem(peekpoke_ctlops_t *in_args); 950Sstevel@tonic-gate 96*1900Seota static int kmem_override_cache_attrs(caddr_t, size_t, uint_t); 97*1900Seota 980Sstevel@tonic-gate #define CTGENTRIES 15 990Sstevel@tonic-gate 1000Sstevel@tonic-gate static struct ctgas { 1010Sstevel@tonic-gate struct ctgas *ctg_next; 1020Sstevel@tonic-gate int ctg_index; 1030Sstevel@tonic-gate void *ctg_addr[CTGENTRIES]; 1040Sstevel@tonic-gate size_t ctg_size[CTGENTRIES]; 1050Sstevel@tonic-gate } ctglist; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate static kmutex_t ctgmutex; 1080Sstevel@tonic-gate #define CTGLOCK() mutex_enter(&ctgmutex) 1090Sstevel@tonic-gate #define CTGUNLOCK() mutex_exit(&ctgmutex) 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * Minimum pfn value of page_t's put on the free list. This is to simplify 1130Sstevel@tonic-gate * support of ddi dma memory requests which specify small, non-zero addr_lo 1140Sstevel@tonic-gate * values. 1150Sstevel@tonic-gate * 1160Sstevel@tonic-gate * The default value of 2, which corresponds to the only known non-zero addr_lo 1170Sstevel@tonic-gate * value used, means a single page will be sacrificed (pfn typically starts 1180Sstevel@tonic-gate * at 1). ddiphysmin can be set to 0 to disable. It cannot be set above 0x100 1190Sstevel@tonic-gate * otherwise mp startup panics. 1200Sstevel@tonic-gate */ 1210Sstevel@tonic-gate pfn_t ddiphysmin = 2; 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate static void 1240Sstevel@tonic-gate check_driver_disable(void) 1250Sstevel@tonic-gate { 1260Sstevel@tonic-gate int proplen = 128; 1270Sstevel@tonic-gate char *prop_name; 1280Sstevel@tonic-gate char *drv_name, *propval; 1290Sstevel@tonic-gate major_t major; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate prop_name = kmem_alloc(proplen, KM_SLEEP); 1320Sstevel@tonic-gate for (major = 0; major < devcnt; major++) { 1330Sstevel@tonic-gate drv_name = ddi_major_to_name(major); 1340Sstevel@tonic-gate if (drv_name == NULL) 1350Sstevel@tonic-gate continue; 1360Sstevel@tonic-gate (void) snprintf(prop_name, proplen, "disable-%s", drv_name); 1370Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 1380Sstevel@tonic-gate DDI_PROP_DONTPASS, prop_name, &propval) == DDI_SUCCESS) { 1390Sstevel@tonic-gate if (strcmp(propval, "true") == 0) { 1400Sstevel@tonic-gate devnamesp[major].dn_flags |= DN_DRIVER_REMOVED; 1410Sstevel@tonic-gate cmn_err(CE_NOTE, "driver %s disabled", 1420Sstevel@tonic-gate drv_name); 1430Sstevel@tonic-gate } 1440Sstevel@tonic-gate ddi_prop_free(propval); 1450Sstevel@tonic-gate } 1460Sstevel@tonic-gate } 1470Sstevel@tonic-gate kmem_free(prop_name, proplen); 1480Sstevel@tonic-gate } 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* 1520Sstevel@tonic-gate * Configure the hardware on the system. 1530Sstevel@tonic-gate * Called before the rootfs is mounted 1540Sstevel@tonic-gate */ 1550Sstevel@tonic-gate void 1560Sstevel@tonic-gate configure(void) 1570Sstevel@tonic-gate { 1580Sstevel@tonic-gate extern void i_ddi_init_root(); 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate #if defined(__i386) 1610Sstevel@tonic-gate extern int fpu_pentium_fdivbug; 1620Sstevel@tonic-gate #endif /* __i386 */ 1630Sstevel@tonic-gate extern int fpu_ignored; 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate /* 1660Sstevel@tonic-gate * Determine if an FPU is attached 1670Sstevel@tonic-gate */ 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate fpu_probe(); 1700Sstevel@tonic-gate 1710Sstevel@tonic-gate #if defined(__i386) 1720Sstevel@tonic-gate if (fpu_pentium_fdivbug) { 1730Sstevel@tonic-gate printf("\ 1740Sstevel@tonic-gate FP hardware exhibits Pentium floating point divide problem\n"); 1750Sstevel@tonic-gate } 1760Sstevel@tonic-gate #endif /* __i386 */ 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate if (fpu_ignored) { 1790Sstevel@tonic-gate printf("FP hardware will not be used\n"); 1800Sstevel@tonic-gate } else if (!fpu_exists) { 1810Sstevel@tonic-gate printf("No FPU in configuration\n"); 1820Sstevel@tonic-gate } 1830Sstevel@tonic-gate 1840Sstevel@tonic-gate /* 1850Sstevel@tonic-gate * Initialize devices on the machine. 1860Sstevel@tonic-gate * Uses configuration tree built by the PROMs to determine what 1870Sstevel@tonic-gate * is present, and builds a tree of prototype dev_info nodes 1880Sstevel@tonic-gate * corresponding to the hardware which identified itself. 1890Sstevel@tonic-gate */ 1900Sstevel@tonic-gate #if !defined(SAS) && !defined(MPSAS) 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * Check for disabled drivers and initialize root node. 1930Sstevel@tonic-gate */ 1940Sstevel@tonic-gate check_driver_disable(); 1950Sstevel@tonic-gate i_ddi_init_root(); 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate /* 1980Sstevel@tonic-gate * attach the isa nexus to get ACPI resource usage 1990Sstevel@tonic-gate * isa is "kind of" a pseudo node 2000Sstevel@tonic-gate */ 2010Sstevel@tonic-gate (void) i_ddi_attach_pseudo_node("isa"); 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* reprogram devices not set up by firmware (BIOS) */ 2040Sstevel@tonic-gate impl_bus_reprobe(); 2050Sstevel@tonic-gate #endif /* !SAS && !MPSAS */ 2060Sstevel@tonic-gate } 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /* 2090Sstevel@tonic-gate * The "status" property indicates the operational status of a device. 2100Sstevel@tonic-gate * If this property is present, the value is a string indicating the 2110Sstevel@tonic-gate * status of the device as follows: 2120Sstevel@tonic-gate * 2130Sstevel@tonic-gate * "okay" operational. 2140Sstevel@tonic-gate * "disabled" not operational, but might become operational. 2150Sstevel@tonic-gate * "fail" not operational because a fault has been detected, 2160Sstevel@tonic-gate * and it is unlikely that the device will become 2170Sstevel@tonic-gate * operational without repair. no additional details 2180Sstevel@tonic-gate * are available. 2190Sstevel@tonic-gate * "fail-xxx" not operational because a fault has been detected, 2200Sstevel@tonic-gate * and it is unlikely that the device will become 2210Sstevel@tonic-gate * operational without repair. "xxx" is additional 2220Sstevel@tonic-gate * human-readable information about the particular 2230Sstevel@tonic-gate * fault condition that was detected. 2240Sstevel@tonic-gate * 2250Sstevel@tonic-gate * The absence of this property means that the operational status is 2260Sstevel@tonic-gate * unknown or okay. 2270Sstevel@tonic-gate * 2280Sstevel@tonic-gate * This routine checks the status property of the specified device node 2290Sstevel@tonic-gate * and returns 0 if the operational status indicates failure, and 1 otherwise. 2300Sstevel@tonic-gate * 2310Sstevel@tonic-gate * The property may exist on plug-in cards the existed before IEEE 1275-1994. 2320Sstevel@tonic-gate * And, in that case, the property may not even be a string. So we carefully 2330Sstevel@tonic-gate * check for the value "fail", in the beginning of the string, noting 2340Sstevel@tonic-gate * the property length. 2350Sstevel@tonic-gate */ 2360Sstevel@tonic-gate int 2370Sstevel@tonic-gate status_okay(int id, char *buf, int buflen) 2380Sstevel@tonic-gate { 2390Sstevel@tonic-gate char status_buf[OBP_MAXPROPNAME]; 2400Sstevel@tonic-gate char *bufp = buf; 2410Sstevel@tonic-gate int len = buflen; 2420Sstevel@tonic-gate int proplen; 2430Sstevel@tonic-gate static const char *status = "status"; 2440Sstevel@tonic-gate static const char *fail = "fail"; 2450Sstevel@tonic-gate int fail_len = (int)strlen(fail); 2460Sstevel@tonic-gate 2470Sstevel@tonic-gate /* 2480Sstevel@tonic-gate * Get the proplen ... if it's smaller than "fail", 2490Sstevel@tonic-gate * or doesn't exist ... then we don't care, since 2500Sstevel@tonic-gate * the value can't begin with the char string "fail". 2510Sstevel@tonic-gate * 2520Sstevel@tonic-gate * NB: proplen, if it's a string, includes the NULL in the 2530Sstevel@tonic-gate * the size of the property, and fail_len does not. 2540Sstevel@tonic-gate */ 255789Sahrens proplen = prom_getproplen((pnode_t)id, (caddr_t)status); 2560Sstevel@tonic-gate if (proplen <= fail_len) /* nonexistant or uninteresting len */ 2570Sstevel@tonic-gate return (1); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate /* 2600Sstevel@tonic-gate * if a buffer was provided, use it 2610Sstevel@tonic-gate */ 2620Sstevel@tonic-gate if ((buf == (char *)NULL) || (buflen <= 0)) { 2630Sstevel@tonic-gate bufp = status_buf; 2640Sstevel@tonic-gate len = sizeof (status_buf); 2650Sstevel@tonic-gate } 2660Sstevel@tonic-gate *bufp = (char)0; 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate /* 2690Sstevel@tonic-gate * Get the property into the buffer, to the extent of the buffer, 2700Sstevel@tonic-gate * and in case the buffer is smaller than the property size, 2710Sstevel@tonic-gate * NULL terminate the buffer. (This handles the case where 2720Sstevel@tonic-gate * a buffer was passed in and the caller wants to print the 2730Sstevel@tonic-gate * value, but the buffer was too small). 2740Sstevel@tonic-gate */ 275789Sahrens (void) prom_bounded_getprop((pnode_t)id, (caddr_t)status, 2760Sstevel@tonic-gate (caddr_t)bufp, len); 2770Sstevel@tonic-gate *(bufp + len - 1) = (char)0; 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate /* 2800Sstevel@tonic-gate * If the value begins with the char string "fail", 2810Sstevel@tonic-gate * then it means the node is failed. We don't care 2820Sstevel@tonic-gate * about any other values. We assume the node is ok 2830Sstevel@tonic-gate * although it might be 'disabled'. 2840Sstevel@tonic-gate */ 2850Sstevel@tonic-gate if (strncmp(bufp, fail, fail_len) == 0) 2860Sstevel@tonic-gate return (0); 2870Sstevel@tonic-gate 2880Sstevel@tonic-gate return (1); 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate /* 2920Sstevel@tonic-gate * Check the status of the device node passed as an argument. 2930Sstevel@tonic-gate * 2940Sstevel@tonic-gate * if ((status is OKAY) || (status is DISABLED)) 2950Sstevel@tonic-gate * return DDI_SUCCESS 2960Sstevel@tonic-gate * else 2970Sstevel@tonic-gate * print a warning and return DDI_FAILURE 2980Sstevel@tonic-gate */ 2990Sstevel@tonic-gate /*ARGSUSED1*/ 3000Sstevel@tonic-gate int 3010Sstevel@tonic-gate check_status(int id, char *name, dev_info_t *parent) 3020Sstevel@tonic-gate { 3030Sstevel@tonic-gate char status_buf[64]; 3040Sstevel@tonic-gate char devtype_buf[OBP_MAXPROPNAME]; 3050Sstevel@tonic-gate int retval = DDI_FAILURE; 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate /* 3080Sstevel@tonic-gate * is the status okay? 3090Sstevel@tonic-gate */ 3100Sstevel@tonic-gate if (status_okay(id, status_buf, sizeof (status_buf))) 3110Sstevel@tonic-gate return (DDI_SUCCESS); 3120Sstevel@tonic-gate 3130Sstevel@tonic-gate /* 3140Sstevel@tonic-gate * a status property indicating bad memory will be associated 3150Sstevel@tonic-gate * with a node which has a "device_type" property with a value of 3160Sstevel@tonic-gate * "memory-controller". in this situation, return DDI_SUCCESS 3170Sstevel@tonic-gate */ 3180Sstevel@tonic-gate if (getlongprop_buf(id, OBP_DEVICETYPE, devtype_buf, 3190Sstevel@tonic-gate sizeof (devtype_buf)) > 0) { 3200Sstevel@tonic-gate if (strcmp(devtype_buf, "memory-controller") == 0) 3210Sstevel@tonic-gate retval = DDI_SUCCESS; 3220Sstevel@tonic-gate } 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate /* 3250Sstevel@tonic-gate * print the status property information 3260Sstevel@tonic-gate */ 3270Sstevel@tonic-gate cmn_err(CE_WARN, "status '%s' for '%s'", status_buf, name); 3280Sstevel@tonic-gate return (retval); 3290Sstevel@tonic-gate } 3300Sstevel@tonic-gate 3310Sstevel@tonic-gate /*ARGSUSED*/ 3320Sstevel@tonic-gate uint_t 3330Sstevel@tonic-gate softlevel1(caddr_t arg1, caddr_t arg2) 3340Sstevel@tonic-gate { 3350Sstevel@tonic-gate softint(); 3360Sstevel@tonic-gate return (1); 3370Sstevel@tonic-gate } 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate /* 3400Sstevel@tonic-gate * Allow for implementation specific correction of PROM property values. 3410Sstevel@tonic-gate */ 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate /*ARGSUSED*/ 3440Sstevel@tonic-gate void 3450Sstevel@tonic-gate impl_fix_props(dev_info_t *dip, dev_info_t *ch_dip, char *name, int len, 3460Sstevel@tonic-gate caddr_t buffer) 3470Sstevel@tonic-gate { 3480Sstevel@tonic-gate /* 3490Sstevel@tonic-gate * There are no adjustments needed in this implementation. 3500Sstevel@tonic-gate */ 3510Sstevel@tonic-gate } 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate static int 3540Sstevel@tonic-gate getlongprop_buf(int id, char *name, char *buf, int maxlen) 3550Sstevel@tonic-gate { 3560Sstevel@tonic-gate int size; 3570Sstevel@tonic-gate 358789Sahrens size = prom_getproplen((pnode_t)id, name); 3590Sstevel@tonic-gate if (size <= 0 || (size > maxlen - 1)) 3600Sstevel@tonic-gate return (-1); 3610Sstevel@tonic-gate 362789Sahrens if (-1 == prom_getprop((pnode_t)id, name, buf)) 3630Sstevel@tonic-gate return (-1); 3640Sstevel@tonic-gate 3650Sstevel@tonic-gate if (strcmp("name", name) == 0) { 3660Sstevel@tonic-gate if (buf[size - 1] != '\0') { 3670Sstevel@tonic-gate buf[size] = '\0'; 3680Sstevel@tonic-gate size += 1; 3690Sstevel@tonic-gate } 3700Sstevel@tonic-gate } 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate return (size); 3730Sstevel@tonic-gate } 3740Sstevel@tonic-gate 3750Sstevel@tonic-gate static int 3760Sstevel@tonic-gate get_prop_int_array(dev_info_t *di, char *pname, int **pval, uint_t *plen) 3770Sstevel@tonic-gate { 3780Sstevel@tonic-gate int ret; 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate if ((ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, di, 3810Sstevel@tonic-gate DDI_PROP_DONTPASS, pname, pval, plen)) 3820Sstevel@tonic-gate == DDI_PROP_SUCCESS) { 3830Sstevel@tonic-gate *plen = (*plen) * (sizeof (int)); 3840Sstevel@tonic-gate } 3850Sstevel@tonic-gate return (ret); 3860Sstevel@tonic-gate } 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate 3890Sstevel@tonic-gate /* 3900Sstevel@tonic-gate * Node Configuration 3910Sstevel@tonic-gate */ 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate struct prop_ispec { 3940Sstevel@tonic-gate uint_t pri, vec; 3950Sstevel@tonic-gate }; 3960Sstevel@tonic-gate 3970Sstevel@tonic-gate /* 398693Sgovinda * For the x86, we're prepared to claim that the interrupt string 399693Sgovinda * is in the form of a list of <ipl,vec> specifications. 400693Sgovinda */ 401693Sgovinda 402693Sgovinda #define VEC_MIN 1 403693Sgovinda #define VEC_MAX 255 404693Sgovinda 405693Sgovinda static int 406693Sgovinda impl_xlate_intrs(dev_info_t *child, int *in, 407693Sgovinda struct ddi_parent_private_data *pdptr) 408693Sgovinda { 409693Sgovinda size_t size; 410693Sgovinda int n; 411693Sgovinda struct intrspec *new; 412693Sgovinda caddr_t got_prop; 413693Sgovinda int *inpri; 414693Sgovinda int got_len; 415693Sgovinda extern int ignore_hardware_nodes; /* force flag from ddi_impl.c */ 416693Sgovinda 417693Sgovinda static char bad_intr_fmt[] = 418693Sgovinda "bad interrupt spec from %s%d - ipl %d, irq %d\n"; 419693Sgovinda 420693Sgovinda /* 421693Sgovinda * determine if the driver is expecting the new style "interrupts" 422693Sgovinda * property which just contains the IRQ, or the old style which 423693Sgovinda * contains pairs of <IPL,IRQ>. if it is the new style, we always 424693Sgovinda * assign IPL 5 unless an "interrupt-priorities" property exists. 425693Sgovinda * in that case, the "interrupt-priorities" property contains the 426693Sgovinda * IPL values that match, one for one, the IRQ values in the 427693Sgovinda * "interrupts" property. 428693Sgovinda */ 429693Sgovinda inpri = NULL; 430693Sgovinda if ((ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 431693Sgovinda "ignore-hardware-nodes", -1) != -1) || ignore_hardware_nodes) { 432693Sgovinda /* the old style "interrupts" property... */ 433693Sgovinda 434693Sgovinda /* 435693Sgovinda * The list consists of <ipl,vec> elements 436693Sgovinda */ 437693Sgovinda if ((n = (*in++ >> 1)) < 1) 438693Sgovinda return (DDI_FAILURE); 439693Sgovinda 440693Sgovinda pdptr->par_nintr = n; 441693Sgovinda size = n * sizeof (struct intrspec); 442693Sgovinda new = pdptr->par_intr = kmem_zalloc(size, KM_SLEEP); 443693Sgovinda 444693Sgovinda while (n--) { 445693Sgovinda int level = *in++; 446693Sgovinda int vec = *in++; 447693Sgovinda 448693Sgovinda if (level < 1 || level > MAXIPL || 449693Sgovinda vec < VEC_MIN || vec > VEC_MAX) { 450693Sgovinda cmn_err(CE_CONT, bad_intr_fmt, 451693Sgovinda DEVI(child)->devi_name, 452693Sgovinda DEVI(child)->devi_instance, level, vec); 453693Sgovinda goto broken; 454693Sgovinda } 455693Sgovinda new->intrspec_pri = level; 456693Sgovinda if (vec != 2) 457693Sgovinda new->intrspec_vec = vec; 458693Sgovinda else 459693Sgovinda /* 460693Sgovinda * irq 2 on the PC bus is tied to irq 9 461693Sgovinda * on ISA, EISA and MicroChannel 462693Sgovinda */ 463693Sgovinda new->intrspec_vec = 9; 464693Sgovinda new++; 465693Sgovinda } 466693Sgovinda 467693Sgovinda return (DDI_SUCCESS); 468693Sgovinda } else { 469693Sgovinda /* the new style "interrupts" property... */ 470693Sgovinda 471693Sgovinda /* 472693Sgovinda * The list consists of <vec> elements 473693Sgovinda */ 474693Sgovinda if ((n = (*in++)) < 1) 475693Sgovinda return (DDI_FAILURE); 476693Sgovinda 477693Sgovinda pdptr->par_nintr = n; 478693Sgovinda size = n * sizeof (struct intrspec); 479693Sgovinda new = pdptr->par_intr = kmem_zalloc(size, KM_SLEEP); 480693Sgovinda 481693Sgovinda /* XXX check for "interrupt-priorities" property... */ 482693Sgovinda if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 483693Sgovinda "interrupt-priorities", (caddr_t)&got_prop, &got_len) 484693Sgovinda == DDI_PROP_SUCCESS) { 485693Sgovinda if (n != (got_len / sizeof (int))) { 486693Sgovinda cmn_err(CE_CONT, 487693Sgovinda "bad interrupt-priorities length" 488693Sgovinda " from %s%d: expected %d, got %d\n", 489693Sgovinda DEVI(child)->devi_name, 490693Sgovinda DEVI(child)->devi_instance, n, 491693Sgovinda (int)(got_len / sizeof (int))); 492693Sgovinda goto broken; 493693Sgovinda } 494693Sgovinda inpri = (int *)got_prop; 495693Sgovinda } 496693Sgovinda 497693Sgovinda while (n--) { 498693Sgovinda int level; 499693Sgovinda int vec = *in++; 500693Sgovinda 501693Sgovinda if (inpri == NULL) 502693Sgovinda level = 5; 503693Sgovinda else 504693Sgovinda level = *inpri++; 505693Sgovinda 506693Sgovinda if (level < 1 || level > MAXIPL || 507693Sgovinda vec < VEC_MIN || vec > VEC_MAX) { 508693Sgovinda cmn_err(CE_CONT, bad_intr_fmt, 509693Sgovinda DEVI(child)->devi_name, 510693Sgovinda DEVI(child)->devi_instance, level, vec); 511693Sgovinda goto broken; 512693Sgovinda } 513693Sgovinda new->intrspec_pri = level; 514693Sgovinda if (vec != 2) 515693Sgovinda new->intrspec_vec = vec; 516693Sgovinda else 517693Sgovinda /* 518693Sgovinda * irq 2 on the PC bus is tied to irq 9 519693Sgovinda * on ISA, EISA and MicroChannel 520693Sgovinda */ 521693Sgovinda new->intrspec_vec = 9; 522693Sgovinda new++; 523693Sgovinda } 524693Sgovinda 525693Sgovinda if (inpri != NULL) 526693Sgovinda kmem_free(got_prop, got_len); 527693Sgovinda return (DDI_SUCCESS); 528693Sgovinda } 529693Sgovinda 530693Sgovinda broken: 531693Sgovinda kmem_free(pdptr->par_intr, size); 532693Sgovinda pdptr->par_intr = NULL; 533693Sgovinda pdptr->par_nintr = 0; 534693Sgovinda if (inpri != NULL) 535693Sgovinda kmem_free(got_prop, got_len); 536693Sgovinda 537693Sgovinda return (DDI_FAILURE); 538693Sgovinda } 539693Sgovinda 540693Sgovinda /* 5410Sstevel@tonic-gate * Create a ddi_parent_private_data structure from the ddi properties of 5420Sstevel@tonic-gate * the dev_info node. 5430Sstevel@tonic-gate * 5440Sstevel@tonic-gate * The "reg" and either an "intr" or "interrupts" properties are required 5450Sstevel@tonic-gate * if the driver wishes to create mappings or field interrupts on behalf 5460Sstevel@tonic-gate * of the device. 5470Sstevel@tonic-gate * 5480Sstevel@tonic-gate * The "reg" property is assumed to be a list of at least one triple 5490Sstevel@tonic-gate * 5500Sstevel@tonic-gate * <bustype, address, size>*1 5510Sstevel@tonic-gate * 5520Sstevel@tonic-gate * The "intr" property is assumed to be a list of at least one duple 5530Sstevel@tonic-gate * 5540Sstevel@tonic-gate * <SPARC ipl, vector#>*1 5550Sstevel@tonic-gate * 5560Sstevel@tonic-gate * The "interrupts" property is assumed to be a list of at least one 5570Sstevel@tonic-gate * n-tuples that describes the interrupt capabilities of the bus the device 5580Sstevel@tonic-gate * is connected to. For SBus, this looks like 5590Sstevel@tonic-gate * 5600Sstevel@tonic-gate * <SBus-level>*1 5610Sstevel@tonic-gate * 5620Sstevel@tonic-gate * (This property obsoletes the 'intr' property). 5630Sstevel@tonic-gate * 5640Sstevel@tonic-gate * The "ranges" property is optional. 5650Sstevel@tonic-gate */ 5660Sstevel@tonic-gate void 5670Sstevel@tonic-gate make_ddi_ppd(dev_info_t *child, struct ddi_parent_private_data **ppd) 5680Sstevel@tonic-gate { 5690Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 5700Sstevel@tonic-gate int n; 5710Sstevel@tonic-gate int *reg_prop, *rng_prop, *intr_prop, *irupts_prop; 5720Sstevel@tonic-gate uint_t reg_len, rng_len, intr_len, irupts_len; 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate *ppd = pdptr = kmem_zalloc(sizeof (*pdptr), KM_SLEEP); 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate /* 5770Sstevel@tonic-gate * Handle the 'reg' property. 5780Sstevel@tonic-gate */ 5790Sstevel@tonic-gate if ((get_prop_int_array(child, "reg", ®_prop, ®_len) == 5800Sstevel@tonic-gate DDI_PROP_SUCCESS) && (reg_len != 0)) { 5810Sstevel@tonic-gate pdptr->par_nreg = reg_len / (int)sizeof (struct regspec); 5820Sstevel@tonic-gate pdptr->par_reg = (struct regspec *)reg_prop; 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate /* 5860Sstevel@tonic-gate * See if I have a range (adding one where needed - this 5870Sstevel@tonic-gate * means to add one for sbus node in sun4c, when romvec > 0, 5880Sstevel@tonic-gate * if no range is already defined in the PROM node. 5890Sstevel@tonic-gate * (Currently no sun4c PROMS define range properties, 5900Sstevel@tonic-gate * but they should and may in the future.) For the SBus 5910Sstevel@tonic-gate * node, the range is defined by the SBus reg property. 5920Sstevel@tonic-gate */ 5930Sstevel@tonic-gate if (get_prop_int_array(child, "ranges", &rng_prop, &rng_len) 5940Sstevel@tonic-gate == DDI_PROP_SUCCESS) { 5950Sstevel@tonic-gate pdptr->par_nrng = rng_len / (int)(sizeof (struct rangespec)); 5960Sstevel@tonic-gate pdptr->par_rng = (struct rangespec *)rng_prop; 5970Sstevel@tonic-gate } 5980Sstevel@tonic-gate 5990Sstevel@tonic-gate /* 6000Sstevel@tonic-gate * Handle the 'intr' and 'interrupts' properties 6010Sstevel@tonic-gate */ 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate /* 6040Sstevel@tonic-gate * For backwards compatibility 6050Sstevel@tonic-gate * we first look for the 'intr' property for the device. 6060Sstevel@tonic-gate */ 6070Sstevel@tonic-gate if (get_prop_int_array(child, "intr", &intr_prop, &intr_len) 6080Sstevel@tonic-gate != DDI_PROP_SUCCESS) { 6090Sstevel@tonic-gate intr_len = 0; 6100Sstevel@tonic-gate } 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate /* 6130Sstevel@tonic-gate * If we're to support bus adapters and future platforms cleanly, 6140Sstevel@tonic-gate * we need to support the generalized 'interrupts' property. 6150Sstevel@tonic-gate */ 6160Sstevel@tonic-gate if (get_prop_int_array(child, "interrupts", &irupts_prop, 6170Sstevel@tonic-gate &irupts_len) != DDI_PROP_SUCCESS) { 6180Sstevel@tonic-gate irupts_len = 0; 6190Sstevel@tonic-gate } else if (intr_len != 0) { 6200Sstevel@tonic-gate /* 6210Sstevel@tonic-gate * If both 'intr' and 'interrupts' are defined, 6220Sstevel@tonic-gate * then 'interrupts' wins and we toss the 'intr' away. 6230Sstevel@tonic-gate */ 6240Sstevel@tonic-gate ddi_prop_free((void *)intr_prop); 6250Sstevel@tonic-gate intr_len = 0; 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate 6280Sstevel@tonic-gate if (intr_len != 0) { 6290Sstevel@tonic-gate 6300Sstevel@tonic-gate /* 6310Sstevel@tonic-gate * Translate the 'intr' property into an array 6320Sstevel@tonic-gate * an array of struct intrspec's. There's not really 6330Sstevel@tonic-gate * very much to do here except copy what's out there. 6340Sstevel@tonic-gate */ 6350Sstevel@tonic-gate 6360Sstevel@tonic-gate struct intrspec *new; 6370Sstevel@tonic-gate struct prop_ispec *l; 6380Sstevel@tonic-gate 6390Sstevel@tonic-gate n = pdptr->par_nintr = 6400Sstevel@tonic-gate intr_len / sizeof (struct prop_ispec); 6410Sstevel@tonic-gate l = (struct prop_ispec *)intr_prop; 6420Sstevel@tonic-gate pdptr->par_intr = 6430Sstevel@tonic-gate new = kmem_zalloc(n * sizeof (struct intrspec), KM_SLEEP); 6440Sstevel@tonic-gate while (n--) { 6450Sstevel@tonic-gate new->intrspec_pri = l->pri; 6460Sstevel@tonic-gate new->intrspec_vec = l->vec; 6470Sstevel@tonic-gate new++; 6480Sstevel@tonic-gate l++; 6490Sstevel@tonic-gate } 6500Sstevel@tonic-gate ddi_prop_free((void *)intr_prop); 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate } else if ((n = irupts_len) != 0) { 6530Sstevel@tonic-gate size_t size; 6540Sstevel@tonic-gate int *out; 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate /* 6570Sstevel@tonic-gate * Translate the 'interrupts' property into an array 6580Sstevel@tonic-gate * of intrspecs for the rest of the DDI framework to 6590Sstevel@tonic-gate * toy with. Only our ancestors really know how to 6600Sstevel@tonic-gate * do this, so ask 'em. We massage the 'interrupts' 6610Sstevel@tonic-gate * property so that it is pre-pended by a count of 6620Sstevel@tonic-gate * the number of integers in the argument. 6630Sstevel@tonic-gate */ 6640Sstevel@tonic-gate size = sizeof (int) + n; 6650Sstevel@tonic-gate out = kmem_alloc(size, KM_SLEEP); 6660Sstevel@tonic-gate *out = n / sizeof (int); 6670Sstevel@tonic-gate bcopy(irupts_prop, out + 1, (size_t)n); 6680Sstevel@tonic-gate ddi_prop_free((void *)irupts_prop); 669693Sgovinda if (impl_xlate_intrs(child, out, pdptr) != DDI_SUCCESS) { 6700Sstevel@tonic-gate cmn_err(CE_CONT, 6710Sstevel@tonic-gate "Unable to translate 'interrupts' for %s%d\n", 6720Sstevel@tonic-gate DEVI(child)->devi_binding_name, 6730Sstevel@tonic-gate DEVI(child)->devi_instance); 6740Sstevel@tonic-gate } 6750Sstevel@tonic-gate kmem_free(out, size); 6760Sstevel@tonic-gate } 6770Sstevel@tonic-gate } 6780Sstevel@tonic-gate 6790Sstevel@tonic-gate /* 6800Sstevel@tonic-gate * Name a child 6810Sstevel@tonic-gate */ 6820Sstevel@tonic-gate static int 6830Sstevel@tonic-gate impl_sunbus_name_child(dev_info_t *child, char *name, int namelen) 6840Sstevel@tonic-gate { 6850Sstevel@tonic-gate /* 6860Sstevel@tonic-gate * Fill in parent-private data and this function returns to us 6870Sstevel@tonic-gate * an indication if it used "registers" to fill in the data. 6880Sstevel@tonic-gate */ 6890Sstevel@tonic-gate if (ddi_get_parent_data(child) == NULL) { 6900Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 6910Sstevel@tonic-gate make_ddi_ppd(child, &pdptr); 6920Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate name[0] = '\0'; 6960Sstevel@tonic-gate if (sparc_pd_getnreg(child) > 0) { 6970Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 6980Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype, 6990Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_addr); 7000Sstevel@tonic-gate } 7010Sstevel@tonic-gate 7020Sstevel@tonic-gate return (DDI_SUCCESS); 7030Sstevel@tonic-gate } 7040Sstevel@tonic-gate 7050Sstevel@tonic-gate /* 7060Sstevel@tonic-gate * Called from the bus_ctl op of sunbus (sbus, obio, etc) nexus drivers 7070Sstevel@tonic-gate * to implement the DDI_CTLOPS_INITCHILD operation. That is, it names 7080Sstevel@tonic-gate * the children of sun busses based on the reg spec. 7090Sstevel@tonic-gate * 7100Sstevel@tonic-gate * Handles the following properties (in make_ddi_ppd): 7110Sstevel@tonic-gate * Property value 7120Sstevel@tonic-gate * Name type 7130Sstevel@tonic-gate * reg register spec 7140Sstevel@tonic-gate * intr old-form interrupt spec 7150Sstevel@tonic-gate * interrupts new (bus-oriented) interrupt spec 7160Sstevel@tonic-gate * ranges range spec 7170Sstevel@tonic-gate */ 7180Sstevel@tonic-gate int 7190Sstevel@tonic-gate impl_ddi_sunbus_initchild(dev_info_t *child) 7200Sstevel@tonic-gate { 7210Sstevel@tonic-gate char name[MAXNAMELEN]; 7220Sstevel@tonic-gate void impl_ddi_sunbus_removechild(dev_info_t *); 7230Sstevel@tonic-gate 7240Sstevel@tonic-gate /* 7250Sstevel@tonic-gate * Name the child, also makes parent private data 7260Sstevel@tonic-gate */ 7270Sstevel@tonic-gate (void) impl_sunbus_name_child(child, name, MAXNAMELEN); 7280Sstevel@tonic-gate ddi_set_name_addr(child, name); 7290Sstevel@tonic-gate 7300Sstevel@tonic-gate /* 7310Sstevel@tonic-gate * Attempt to merge a .conf node; if successful, remove the 7320Sstevel@tonic-gate * .conf node. 7330Sstevel@tonic-gate */ 7340Sstevel@tonic-gate if ((ndi_dev_is_persistent_node(child) == 0) && 7350Sstevel@tonic-gate (ndi_merge_node(child, impl_sunbus_name_child) == DDI_SUCCESS)) { 7360Sstevel@tonic-gate /* 7370Sstevel@tonic-gate * Return failure to remove node 7380Sstevel@tonic-gate */ 7390Sstevel@tonic-gate impl_ddi_sunbus_removechild(child); 7400Sstevel@tonic-gate return (DDI_FAILURE); 7410Sstevel@tonic-gate } 7420Sstevel@tonic-gate return (DDI_SUCCESS); 7430Sstevel@tonic-gate } 7440Sstevel@tonic-gate 7450Sstevel@tonic-gate void 7460Sstevel@tonic-gate impl_free_ddi_ppd(dev_info_t *dip) 7470Sstevel@tonic-gate { 7480Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 7490Sstevel@tonic-gate size_t n; 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate if ((pdptr = ddi_get_parent_data(dip)) == NULL) 7520Sstevel@tonic-gate return; 7530Sstevel@tonic-gate 7540Sstevel@tonic-gate if ((n = (size_t)pdptr->par_nintr) != 0) 7550Sstevel@tonic-gate /* 7560Sstevel@tonic-gate * Note that kmem_free is used here (instead of 7570Sstevel@tonic-gate * ddi_prop_free) because the contents of the 7580Sstevel@tonic-gate * property were placed into a separate buffer and 7590Sstevel@tonic-gate * mucked with a bit before being stored in par_intr. 7600Sstevel@tonic-gate * The actual return value from the prop lookup 7610Sstevel@tonic-gate * was freed with ddi_prop_free previously. 7620Sstevel@tonic-gate */ 7630Sstevel@tonic-gate kmem_free(pdptr->par_intr, n * sizeof (struct intrspec)); 7640Sstevel@tonic-gate 7650Sstevel@tonic-gate if ((n = (size_t)pdptr->par_nrng) != 0) 7660Sstevel@tonic-gate ddi_prop_free((void *)pdptr->par_rng); 7670Sstevel@tonic-gate 7680Sstevel@tonic-gate if ((n = pdptr->par_nreg) != 0) 7690Sstevel@tonic-gate ddi_prop_free((void *)pdptr->par_reg); 7700Sstevel@tonic-gate 7710Sstevel@tonic-gate kmem_free(pdptr, sizeof (*pdptr)); 7720Sstevel@tonic-gate ddi_set_parent_data(dip, NULL); 7730Sstevel@tonic-gate } 7740Sstevel@tonic-gate 7750Sstevel@tonic-gate void 7760Sstevel@tonic-gate impl_ddi_sunbus_removechild(dev_info_t *dip) 7770Sstevel@tonic-gate { 7780Sstevel@tonic-gate impl_free_ddi_ppd(dip); 7790Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 7800Sstevel@tonic-gate /* 7810Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form 7820Sstevel@tonic-gate */ 7830Sstevel@tonic-gate impl_rem_dev_props(dip); 7840Sstevel@tonic-gate } 7850Sstevel@tonic-gate 7860Sstevel@tonic-gate /* 7870Sstevel@tonic-gate * DDI Interrupt 7880Sstevel@tonic-gate */ 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate /* 7910Sstevel@tonic-gate * turn this on to force isa, eisa, and mca device to ignore the new 7920Sstevel@tonic-gate * hardware nodes in the device tree (normally turned on only for 7930Sstevel@tonic-gate * drivers that need it by setting the property "ignore-hardware-nodes" 7940Sstevel@tonic-gate * in their driver.conf file). 7950Sstevel@tonic-gate * 7960Sstevel@tonic-gate * 7/31/96 -- Turned off globally. Leaving variable in for the moment 7970Sstevel@tonic-gate * as safety valve. 7980Sstevel@tonic-gate */ 7990Sstevel@tonic-gate int ignore_hardware_nodes = 0; 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate /* 8020Sstevel@tonic-gate * Local data 8030Sstevel@tonic-gate */ 8040Sstevel@tonic-gate static struct impl_bus_promops *impl_busp; 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate 8070Sstevel@tonic-gate /* 8080Sstevel@tonic-gate * New DDI interrupt framework 8090Sstevel@tonic-gate */ 8100Sstevel@tonic-gate 8110Sstevel@tonic-gate /* 8120Sstevel@tonic-gate * i_ddi_intr_ops: 8130Sstevel@tonic-gate * 8140Sstevel@tonic-gate * This is the interrupt operator function wrapper for the bus function 8150Sstevel@tonic-gate * bus_intr_op. 8160Sstevel@tonic-gate */ 8170Sstevel@tonic-gate int 8180Sstevel@tonic-gate i_ddi_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op, 8190Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void * result) 8200Sstevel@tonic-gate { 8210Sstevel@tonic-gate dev_info_t *pdip = (dev_info_t *)DEVI(dip)->devi_parent; 8220Sstevel@tonic-gate int ret = DDI_FAILURE; 8230Sstevel@tonic-gate 8240Sstevel@tonic-gate /* request parent to process this interrupt op */ 8250Sstevel@tonic-gate if (NEXUS_HAS_INTR_OP(pdip)) 8260Sstevel@tonic-gate ret = (*(DEVI(pdip)->devi_ops->devo_bus_ops->bus_intr_op))( 8270Sstevel@tonic-gate pdip, rdip, op, hdlp, result); 8280Sstevel@tonic-gate else 8290Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to process interrupt " 8300Sstevel@tonic-gate "for %s%d due to down-rev nexus driver %s%d", 8310Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip), 8320Sstevel@tonic-gate ddi_get_name(pdip), ddi_get_instance(pdip)); 8330Sstevel@tonic-gate return (ret); 8340Sstevel@tonic-gate } 8350Sstevel@tonic-gate 8360Sstevel@tonic-gate /* 8370Sstevel@tonic-gate * i_ddi_add_softint - allocate and add a soft interrupt to the system 8380Sstevel@tonic-gate */ 8390Sstevel@tonic-gate int 8400Sstevel@tonic-gate i_ddi_add_softint(ddi_softint_hdl_impl_t *hdlp) 8410Sstevel@tonic-gate { 8420Sstevel@tonic-gate int ret; 8430Sstevel@tonic-gate 8440Sstevel@tonic-gate /* add soft interrupt handler */ 8450Sstevel@tonic-gate ret = add_avsoftintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func, 8460Sstevel@tonic-gate DEVI(hdlp->ih_dip)->devi_name, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 8470Sstevel@tonic-gate return (ret ? DDI_SUCCESS : DDI_FAILURE); 8480Sstevel@tonic-gate } 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate void 8520Sstevel@tonic-gate i_ddi_remove_softint(ddi_softint_hdl_impl_t *hdlp) 8530Sstevel@tonic-gate { 8540Sstevel@tonic-gate (void) rem_avsoftintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func); 8550Sstevel@tonic-gate } 8560Sstevel@tonic-gate 8570Sstevel@tonic-gate 858999Slq150181 extern void (*setsoftint)(int, struct av_softinfo *); 859999Slq150181 extern boolean_t av_check_softint_pending(struct av_softinfo *, boolean_t); 8600Sstevel@tonic-gate 8610Sstevel@tonic-gate int 862278Sgovinda i_ddi_trigger_softint(ddi_softint_hdl_impl_t *hdlp, void *arg2) 8630Sstevel@tonic-gate { 864999Slq150181 if (av_check_softint_pending(hdlp->ih_pending, B_FALSE)) 865999Slq150181 return (DDI_EPENDING); 866278Sgovinda 867999Slq150181 update_avsoftintr_args((void *)hdlp, hdlp->ih_pri, arg2); 868278Sgovinda 869999Slq150181 (*setsoftint)(hdlp->ih_pri, hdlp->ih_pending); 870999Slq150181 return (DDI_SUCCESS); 8710Sstevel@tonic-gate } 8720Sstevel@tonic-gate 8730Sstevel@tonic-gate /* 8740Sstevel@tonic-gate * i_ddi_set_softint_pri: 8750Sstevel@tonic-gate * 8760Sstevel@tonic-gate * The way this works is that it first tries to add a softint vector 8770Sstevel@tonic-gate * at the new priority in hdlp. If that succeeds; then it removes the 8780Sstevel@tonic-gate * existing softint vector at the old priority. 8790Sstevel@tonic-gate */ 8800Sstevel@tonic-gate int 8810Sstevel@tonic-gate i_ddi_set_softint_pri(ddi_softint_hdl_impl_t *hdlp, uint_t old_pri) 8820Sstevel@tonic-gate { 883999Slq150181 int ret; 884999Slq150181 8850Sstevel@tonic-gate /* 8860Sstevel@tonic-gate * If a softint is pending at the old priority then fail the request. 8870Sstevel@tonic-gate */ 888999Slq150181 if (av_check_softint_pending(hdlp->ih_pending, B_TRUE)) 8890Sstevel@tonic-gate return (DDI_FAILURE); 8900Sstevel@tonic-gate 891999Slq150181 ret = av_softint_movepri((void *)hdlp, old_pri); 892999Slq150181 return (ret ? DDI_SUCCESS : DDI_FAILURE); 8930Sstevel@tonic-gate } 8940Sstevel@tonic-gate 895916Sschwartz void 896916Sschwartz i_ddi_alloc_intr_phdl(ddi_intr_handle_impl_t *hdlp) 897916Sschwartz { 898916Sschwartz hdlp->ih_private = (void *)kmem_zalloc(sizeof (ihdl_plat_t), KM_SLEEP); 899916Sschwartz } 900916Sschwartz 901916Sschwartz void 902916Sschwartz i_ddi_free_intr_phdl(ddi_intr_handle_impl_t *hdlp) 903916Sschwartz { 904916Sschwartz kmem_free(hdlp->ih_private, sizeof (ihdl_plat_t)); 905916Sschwartz hdlp->ih_private = NULL; 906916Sschwartz } 907916Sschwartz 9080Sstevel@tonic-gate /* 9090Sstevel@tonic-gate * DDI Memory/DMA 9100Sstevel@tonic-gate */ 9110Sstevel@tonic-gate 9120Sstevel@tonic-gate /* 9130Sstevel@tonic-gate * Support for allocating DMAable memory to implement 9140Sstevel@tonic-gate * ddi_dma_mem_alloc(9F) interface. 9150Sstevel@tonic-gate */ 9160Sstevel@tonic-gate 9170Sstevel@tonic-gate #define KA_ALIGN_SHIFT 7 9180Sstevel@tonic-gate #define KA_ALIGN (1 << KA_ALIGN_SHIFT) 9190Sstevel@tonic-gate #define KA_NCACHE (PAGESHIFT + 1 - KA_ALIGN_SHIFT) 9200Sstevel@tonic-gate 9210Sstevel@tonic-gate /* 9220Sstevel@tonic-gate * Dummy DMA attribute template for kmem_io[].kmem_io_attr. We only 9230Sstevel@tonic-gate * care about addr_lo, addr_hi, and align. addr_hi will be dynamically set. 9240Sstevel@tonic-gate */ 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate static ddi_dma_attr_t kmem_io_attr = { 9270Sstevel@tonic-gate DMA_ATTR_V0, 9280Sstevel@tonic-gate 0x0000000000000000ULL, /* dma_attr_addr_lo */ 9290Sstevel@tonic-gate 0x0000000000000000ULL, /* dma_attr_addr_hi */ 9300Sstevel@tonic-gate 0x00ffffff, 9310Sstevel@tonic-gate 0x1000, /* dma_attr_align */ 9320Sstevel@tonic-gate 1, 1, 0xffffffffULL, 0xffffffffULL, 0x1, 1, 0 9330Sstevel@tonic-gate }; 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate /* kmem io memory ranges and indices */ 9360Sstevel@tonic-gate enum { 9370Sstevel@tonic-gate IO_4P, IO_64G, IO_4G, IO_2G, IO_1G, IO_512M, 9380Sstevel@tonic-gate IO_256M, IO_128M, IO_64M, IO_32M, IO_16M, MAX_MEM_RANGES 9390Sstevel@tonic-gate }; 9400Sstevel@tonic-gate 9410Sstevel@tonic-gate static struct { 9420Sstevel@tonic-gate vmem_t *kmem_io_arena; 9430Sstevel@tonic-gate kmem_cache_t *kmem_io_cache[KA_NCACHE]; 9440Sstevel@tonic-gate ddi_dma_attr_t kmem_io_attr; 9450Sstevel@tonic-gate } kmem_io[MAX_MEM_RANGES]; 9460Sstevel@tonic-gate 9470Sstevel@tonic-gate static int kmem_io_idx; /* index of first populated kmem_io[] */ 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate static page_t * 9500Sstevel@tonic-gate page_create_io_wrapper(void *addr, size_t len, int vmflag, void *arg) 9510Sstevel@tonic-gate { 9520Sstevel@tonic-gate extern page_t *page_create_io(vnode_t *, u_offset_t, uint_t, 9530Sstevel@tonic-gate uint_t, struct as *, caddr_t, ddi_dma_attr_t *); 9540Sstevel@tonic-gate 9550Sstevel@tonic-gate return (page_create_io(&kvp, (u_offset_t)(uintptr_t)addr, len, 9560Sstevel@tonic-gate PG_EXCL | ((vmflag & VM_NOSLEEP) ? 0 : PG_WAIT), &kas, addr, arg)); 9570Sstevel@tonic-gate } 9580Sstevel@tonic-gate 9590Sstevel@tonic-gate static void * 9600Sstevel@tonic-gate segkmem_alloc_io_4P(vmem_t *vmp, size_t size, int vmflag) 9610Sstevel@tonic-gate { 9620Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 9630Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_4P].kmem_io_attr)); 9640Sstevel@tonic-gate } 9650Sstevel@tonic-gate 9660Sstevel@tonic-gate static void * 9670Sstevel@tonic-gate segkmem_alloc_io_64G(vmem_t *vmp, size_t size, int vmflag) 9680Sstevel@tonic-gate { 9690Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 9700Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_64G].kmem_io_attr)); 9710Sstevel@tonic-gate } 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate static void * 9740Sstevel@tonic-gate segkmem_alloc_io_4G(vmem_t *vmp, size_t size, int vmflag) 9750Sstevel@tonic-gate { 9760Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 9770Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_4G].kmem_io_attr)); 9780Sstevel@tonic-gate } 9790Sstevel@tonic-gate 9800Sstevel@tonic-gate static void * 9810Sstevel@tonic-gate segkmem_alloc_io_2G(vmem_t *vmp, size_t size, int vmflag) 9820Sstevel@tonic-gate { 9830Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 9840Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_2G].kmem_io_attr)); 9850Sstevel@tonic-gate } 9860Sstevel@tonic-gate 9870Sstevel@tonic-gate static void * 9880Sstevel@tonic-gate segkmem_alloc_io_1G(vmem_t *vmp, size_t size, int vmflag) 9890Sstevel@tonic-gate { 9900Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 9910Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_1G].kmem_io_attr)); 9920Sstevel@tonic-gate } 9930Sstevel@tonic-gate 9940Sstevel@tonic-gate static void * 9950Sstevel@tonic-gate segkmem_alloc_io_512M(vmem_t *vmp, size_t size, int vmflag) 9960Sstevel@tonic-gate { 9970Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 9980Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_512M].kmem_io_attr)); 9990Sstevel@tonic-gate } 10000Sstevel@tonic-gate 10010Sstevel@tonic-gate static void * 10020Sstevel@tonic-gate segkmem_alloc_io_256M(vmem_t *vmp, size_t size, int vmflag) 10030Sstevel@tonic-gate { 10040Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10050Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_256M].kmem_io_attr)); 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate static void * 10090Sstevel@tonic-gate segkmem_alloc_io_128M(vmem_t *vmp, size_t size, int vmflag) 10100Sstevel@tonic-gate { 10110Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10120Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_128M].kmem_io_attr)); 10130Sstevel@tonic-gate } 10140Sstevel@tonic-gate 10150Sstevel@tonic-gate static void * 10160Sstevel@tonic-gate segkmem_alloc_io_64M(vmem_t *vmp, size_t size, int vmflag) 10170Sstevel@tonic-gate { 10180Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10190Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_64M].kmem_io_attr)); 10200Sstevel@tonic-gate } 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate static void * 10230Sstevel@tonic-gate segkmem_alloc_io_32M(vmem_t *vmp, size_t size, int vmflag) 10240Sstevel@tonic-gate { 10250Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10260Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_32M].kmem_io_attr)); 10270Sstevel@tonic-gate } 10280Sstevel@tonic-gate 10290Sstevel@tonic-gate static void * 10300Sstevel@tonic-gate segkmem_alloc_io_16M(vmem_t *vmp, size_t size, int vmflag) 10310Sstevel@tonic-gate { 10320Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10330Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_16M].kmem_io_attr)); 10340Sstevel@tonic-gate } 10350Sstevel@tonic-gate 10360Sstevel@tonic-gate struct { 10370Sstevel@tonic-gate uint64_t io_limit; 10380Sstevel@tonic-gate char *io_name; 10390Sstevel@tonic-gate void *(*io_alloc)(vmem_t *, size_t, int); 10400Sstevel@tonic-gate int io_initial; /* kmem_io_init during startup */ 10410Sstevel@tonic-gate } io_arena_params[MAX_MEM_RANGES] = { 10420Sstevel@tonic-gate {0x000fffffffffffffULL, "kmem_io_4P", segkmem_alloc_io_4P, 1}, 10430Sstevel@tonic-gate {0x0000000fffffffffULL, "kmem_io_64G", segkmem_alloc_io_64G, 0}, 10440Sstevel@tonic-gate {0x00000000ffffffffULL, "kmem_io_4G", segkmem_alloc_io_4G, 1}, 10450Sstevel@tonic-gate {0x000000007fffffffULL, "kmem_io_2G", segkmem_alloc_io_2G, 1}, 10460Sstevel@tonic-gate {0x000000003fffffffULL, "kmem_io_1G", segkmem_alloc_io_1G, 0}, 10470Sstevel@tonic-gate {0x000000001fffffffULL, "kmem_io_512M", segkmem_alloc_io_512M, 0}, 10480Sstevel@tonic-gate {0x000000000fffffffULL, "kmem_io_256M", segkmem_alloc_io_256M, 0}, 10490Sstevel@tonic-gate {0x0000000007ffffffULL, "kmem_io_128M", segkmem_alloc_io_128M, 0}, 10500Sstevel@tonic-gate {0x0000000003ffffffULL, "kmem_io_64M", segkmem_alloc_io_64M, 0}, 10510Sstevel@tonic-gate {0x0000000001ffffffULL, "kmem_io_32M", segkmem_alloc_io_32M, 0}, 10520Sstevel@tonic-gate {0x0000000000ffffffULL, "kmem_io_16M", segkmem_alloc_io_16M, 1} 10530Sstevel@tonic-gate }; 10540Sstevel@tonic-gate 10550Sstevel@tonic-gate void 10560Sstevel@tonic-gate kmem_io_init(int a) 10570Sstevel@tonic-gate { 10580Sstevel@tonic-gate int c; 10590Sstevel@tonic-gate char name[40]; 10600Sstevel@tonic-gate 10610Sstevel@tonic-gate kmem_io[a].kmem_io_arena = vmem_create(io_arena_params[a].io_name, 10620Sstevel@tonic-gate NULL, 0, PAGESIZE, io_arena_params[a].io_alloc, 10630Sstevel@tonic-gate segkmem_free, heap_arena, 0, VM_SLEEP); 10640Sstevel@tonic-gate for (c = 0; c < KA_NCACHE; c++) { 10650Sstevel@tonic-gate size_t size = KA_ALIGN << c; 10660Sstevel@tonic-gate (void) sprintf(name, "%s_%lu", 10670Sstevel@tonic-gate io_arena_params[a].io_name, size); 10680Sstevel@tonic-gate kmem_io[a].kmem_io_cache[c] = kmem_cache_create(name, 10690Sstevel@tonic-gate size, size, NULL, NULL, NULL, NULL, 10700Sstevel@tonic-gate kmem_io[a].kmem_io_arena, 0); 10710Sstevel@tonic-gate } 10720Sstevel@tonic-gate } 10730Sstevel@tonic-gate 10740Sstevel@tonic-gate /* 10750Sstevel@tonic-gate * Return the index of the highest memory range for addr. 10760Sstevel@tonic-gate */ 10770Sstevel@tonic-gate static int 10780Sstevel@tonic-gate kmem_io_index(uint64_t addr) 10790Sstevel@tonic-gate { 10800Sstevel@tonic-gate int n; 10810Sstevel@tonic-gate 10820Sstevel@tonic-gate for (n = kmem_io_idx; n < MAX_MEM_RANGES; n++) { 10830Sstevel@tonic-gate if (kmem_io[n].kmem_io_attr.dma_attr_addr_hi <= addr) { 10840Sstevel@tonic-gate if (kmem_io[n].kmem_io_arena == NULL) 10850Sstevel@tonic-gate kmem_io_init(n); 10860Sstevel@tonic-gate return (n); 10870Sstevel@tonic-gate } 10880Sstevel@tonic-gate } 10890Sstevel@tonic-gate panic("kmem_io_index: invalid addr - must be at least 16m"); 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate /*NOTREACHED*/ 10920Sstevel@tonic-gate } 10930Sstevel@tonic-gate 10940Sstevel@tonic-gate /* 10950Sstevel@tonic-gate * Return the index of the next kmem_io populated memory range 10960Sstevel@tonic-gate * after curindex. 10970Sstevel@tonic-gate */ 10980Sstevel@tonic-gate static int 10990Sstevel@tonic-gate kmem_io_index_next(int curindex) 11000Sstevel@tonic-gate { 11010Sstevel@tonic-gate int n; 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate for (n = curindex + 1; n < MAX_MEM_RANGES; n++) { 11040Sstevel@tonic-gate if (kmem_io[n].kmem_io_arena) 11050Sstevel@tonic-gate return (n); 11060Sstevel@tonic-gate } 11070Sstevel@tonic-gate return (-1); 11080Sstevel@tonic-gate } 11090Sstevel@tonic-gate 1110*1900Seota /* 1111*1900Seota * allow kmem to be mapped in with different PTE cache attribute settings. 1112*1900Seota * Used by i_ddi_mem_alloc() 1113*1900Seota */ 1114*1900Seota int 1115*1900Seota kmem_override_cache_attrs(caddr_t kva, size_t size, uint_t order) 1116*1900Seota { 1117*1900Seota uint_t hat_flags; 1118*1900Seota caddr_t kva_end; 1119*1900Seota uint_t hat_attr; 1120*1900Seota pfn_t pfn; 1121*1900Seota 1122*1900Seota if (hat_getattr(kas.a_hat, kva, &hat_attr) == -1) { 1123*1900Seota return (-1); 1124*1900Seota } 1125*1900Seota 1126*1900Seota hat_attr &= ~HAT_ORDER_MASK; 1127*1900Seota hat_attr |= order | HAT_NOSYNC; 1128*1900Seota hat_flags = HAT_LOAD_LOCK; 1129*1900Seota 1130*1900Seota kva_end = (caddr_t)(((uintptr_t)kva + size + PAGEOFFSET) & 1131*1900Seota (uintptr_t)PAGEMASK); 1132*1900Seota kva = (caddr_t)((uintptr_t)kva & (uintptr_t)PAGEMASK); 1133*1900Seota 1134*1900Seota while (kva < kva_end) { 1135*1900Seota pfn = hat_getpfnum(kas.a_hat, kva); 1136*1900Seota hat_unload(kas.a_hat, kva, PAGESIZE, HAT_UNLOAD_UNLOCK); 1137*1900Seota hat_devload(kas.a_hat, kva, PAGESIZE, pfn, hat_attr, hat_flags); 1138*1900Seota kva += MMU_PAGESIZE; 1139*1900Seota } 1140*1900Seota 1141*1900Seota return (0); 1142*1900Seota } 1143*1900Seota 11440Sstevel@tonic-gate void 11450Sstevel@tonic-gate ka_init(void) 11460Sstevel@tonic-gate { 11470Sstevel@tonic-gate int a; 11480Sstevel@tonic-gate extern pfn_t physmax; 11490Sstevel@tonic-gate uint64_t maxphysaddr = mmu_ptob((uint64_t)physmax + 1) - 1; 11500Sstevel@tonic-gate 11510Sstevel@tonic-gate ASSERT(maxphysaddr <= io_arena_params[0].io_limit); 11520Sstevel@tonic-gate 11530Sstevel@tonic-gate for (a = 0; a < MAX_MEM_RANGES; a++) { 11540Sstevel@tonic-gate if (maxphysaddr >= io_arena_params[a + 1].io_limit) { 11550Sstevel@tonic-gate if (maxphysaddr > io_arena_params[a + 1].io_limit) 11560Sstevel@tonic-gate io_arena_params[a].io_limit = maxphysaddr; 11570Sstevel@tonic-gate else 11580Sstevel@tonic-gate a++; 11590Sstevel@tonic-gate break; 11600Sstevel@tonic-gate } 11610Sstevel@tonic-gate } 11620Sstevel@tonic-gate kmem_io_idx = a; 11630Sstevel@tonic-gate 11640Sstevel@tonic-gate for (; a < MAX_MEM_RANGES; a++) { 11650Sstevel@tonic-gate kmem_io[a].kmem_io_attr = kmem_io_attr; 11660Sstevel@tonic-gate kmem_io[a].kmem_io_attr.dma_attr_addr_hi = 11670Sstevel@tonic-gate io_arena_params[a].io_limit; 11680Sstevel@tonic-gate /* 11690Sstevel@tonic-gate * initialize kmem_io[] arena/cache corresponding to 11700Sstevel@tonic-gate * maxphysaddr and to the "common" io memory ranges that 11710Sstevel@tonic-gate * have io_initial set to a non-zero value. 11720Sstevel@tonic-gate */ 11730Sstevel@tonic-gate if (io_arena_params[a].io_initial || a == kmem_io_idx) 11740Sstevel@tonic-gate kmem_io_init(a); 11750Sstevel@tonic-gate } 11760Sstevel@tonic-gate } 11770Sstevel@tonic-gate 11780Sstevel@tonic-gate /* 11790Sstevel@tonic-gate * put contig address/size 11800Sstevel@tonic-gate */ 11810Sstevel@tonic-gate static void * 11820Sstevel@tonic-gate putctgas(void *addr, size_t size) 11830Sstevel@tonic-gate { 11840Sstevel@tonic-gate struct ctgas *ctgp = &ctglist; 11850Sstevel@tonic-gate int i; 11860Sstevel@tonic-gate 11870Sstevel@tonic-gate CTGLOCK(); 11880Sstevel@tonic-gate do { 11890Sstevel@tonic-gate if ((i = ctgp->ctg_index) < CTGENTRIES) { 11900Sstevel@tonic-gate ctgp->ctg_addr[i] = addr; 11910Sstevel@tonic-gate ctgp->ctg_size[i] = size; 11920Sstevel@tonic-gate ctgp->ctg_index++; 11930Sstevel@tonic-gate break; 11940Sstevel@tonic-gate } 11950Sstevel@tonic-gate if (!ctgp->ctg_next) 11960Sstevel@tonic-gate ctgp->ctg_next = kmem_zalloc(sizeof (struct ctgas), 11970Sstevel@tonic-gate KM_NOSLEEP); 11980Sstevel@tonic-gate ctgp = ctgp->ctg_next; 11990Sstevel@tonic-gate } while (ctgp); 12000Sstevel@tonic-gate 12010Sstevel@tonic-gate CTGUNLOCK(); 12020Sstevel@tonic-gate return (ctgp); 12030Sstevel@tonic-gate } 12040Sstevel@tonic-gate 12050Sstevel@tonic-gate /* 12060Sstevel@tonic-gate * get contig size by addr 12070Sstevel@tonic-gate */ 12080Sstevel@tonic-gate static size_t 12090Sstevel@tonic-gate getctgsz(void *addr) 12100Sstevel@tonic-gate { 12110Sstevel@tonic-gate struct ctgas *ctgp = &ctglist; 12120Sstevel@tonic-gate int i, j; 12130Sstevel@tonic-gate size_t sz; 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate ASSERT(addr); 12160Sstevel@tonic-gate CTGLOCK(); 12170Sstevel@tonic-gate 12180Sstevel@tonic-gate while (ctgp) { 12190Sstevel@tonic-gate for (i = 0; i < ctgp->ctg_index; i++) { 12200Sstevel@tonic-gate if (addr != ctgp->ctg_addr[i]) 12210Sstevel@tonic-gate continue; 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate sz = ctgp->ctg_size[i]; 12240Sstevel@tonic-gate j = --ctgp->ctg_index; 12250Sstevel@tonic-gate if (i != j) { 12260Sstevel@tonic-gate ctgp->ctg_size[i] = ctgp->ctg_size[j]; 12270Sstevel@tonic-gate ctgp->ctg_addr[i] = ctgp->ctg_addr[j]; 12280Sstevel@tonic-gate } 12290Sstevel@tonic-gate CTGUNLOCK(); 12300Sstevel@tonic-gate return (sz); 12310Sstevel@tonic-gate } 12320Sstevel@tonic-gate ctgp = ctgp->ctg_next; 12330Sstevel@tonic-gate } 12340Sstevel@tonic-gate 12350Sstevel@tonic-gate CTGUNLOCK(); 12360Sstevel@tonic-gate return (0); 12370Sstevel@tonic-gate } 12380Sstevel@tonic-gate 12390Sstevel@tonic-gate /* 12400Sstevel@tonic-gate * contig_alloc: 12410Sstevel@tonic-gate * 12420Sstevel@tonic-gate * allocates contiguous memory to satisfy the 'size' and dma attributes 12430Sstevel@tonic-gate * specified in 'attr'. 12440Sstevel@tonic-gate * 12450Sstevel@tonic-gate * Not all of memory need to be physically contiguous if the 12460Sstevel@tonic-gate * scatter-gather list length is greater than 1. 12470Sstevel@tonic-gate */ 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate /*ARGSUSED*/ 12500Sstevel@tonic-gate void * 12510Sstevel@tonic-gate contig_alloc(size_t size, ddi_dma_attr_t *attr, uintptr_t align, int cansleep) 12520Sstevel@tonic-gate { 12530Sstevel@tonic-gate pgcnt_t pgcnt = btopr(size); 12540Sstevel@tonic-gate size_t asize = pgcnt * PAGESIZE; 12550Sstevel@tonic-gate page_t *ppl; 12560Sstevel@tonic-gate int pflag; 12570Sstevel@tonic-gate void *addr; 12580Sstevel@tonic-gate 12590Sstevel@tonic-gate extern page_t *page_create_io(vnode_t *, u_offset_t, uint_t, 12600Sstevel@tonic-gate uint_t, struct as *, caddr_t, ddi_dma_attr_t *); 12610Sstevel@tonic-gate 12620Sstevel@tonic-gate /* segkmem_xalloc */ 12630Sstevel@tonic-gate 12640Sstevel@tonic-gate if (align <= PAGESIZE) 12650Sstevel@tonic-gate addr = vmem_alloc(heap_arena, asize, 12660Sstevel@tonic-gate (cansleep) ? VM_SLEEP : VM_NOSLEEP); 12670Sstevel@tonic-gate else 12680Sstevel@tonic-gate addr = vmem_xalloc(heap_arena, asize, align, 0, 0, NULL, NULL, 12690Sstevel@tonic-gate (cansleep) ? VM_SLEEP : VM_NOSLEEP); 12700Sstevel@tonic-gate if (addr) { 12710Sstevel@tonic-gate ASSERT(!((uintptr_t)addr & (align - 1))); 12720Sstevel@tonic-gate 12730Sstevel@tonic-gate if (page_resv(pgcnt, 12740Sstevel@tonic-gate (cansleep) ? KM_SLEEP : KM_NOSLEEP) == 0) { 12750Sstevel@tonic-gate 12760Sstevel@tonic-gate vmem_free(heap_arena, addr, asize); 12770Sstevel@tonic-gate return (NULL); 12780Sstevel@tonic-gate } 12790Sstevel@tonic-gate pflag = PG_EXCL; 12800Sstevel@tonic-gate 12810Sstevel@tonic-gate if (cansleep) 12820Sstevel@tonic-gate pflag |= PG_WAIT; 12830Sstevel@tonic-gate 12840Sstevel@tonic-gate /* 4k req gets from freelists rather than pfn search */ 12850Sstevel@tonic-gate if (pgcnt > 1 || align > PAGESIZE) 12860Sstevel@tonic-gate pflag |= PG_PHYSCONTIG; 12870Sstevel@tonic-gate 12880Sstevel@tonic-gate ppl = page_create_io(&kvp, (u_offset_t)(uintptr_t)addr, 12890Sstevel@tonic-gate asize, pflag, &kas, (caddr_t)addr, attr); 12900Sstevel@tonic-gate 12910Sstevel@tonic-gate if (!ppl) { 12920Sstevel@tonic-gate vmem_free(heap_arena, addr, asize); 12930Sstevel@tonic-gate page_unresv(pgcnt); 12940Sstevel@tonic-gate return (NULL); 12950Sstevel@tonic-gate } 12960Sstevel@tonic-gate 12970Sstevel@tonic-gate while (ppl != NULL) { 12980Sstevel@tonic-gate page_t *pp = ppl; 12990Sstevel@tonic-gate page_sub(&ppl, pp); 13000Sstevel@tonic-gate ASSERT(page_iolock_assert(pp)); 13010Sstevel@tonic-gate page_io_unlock(pp); 13020Sstevel@tonic-gate page_downgrade(pp); 13030Sstevel@tonic-gate hat_memload(kas.a_hat, (caddr_t)(uintptr_t)pp->p_offset, 13040Sstevel@tonic-gate pp, (PROT_ALL & ~PROT_USER) | 13050Sstevel@tonic-gate HAT_NOSYNC, HAT_LOAD_LOCK); 13060Sstevel@tonic-gate } 13070Sstevel@tonic-gate } 13080Sstevel@tonic-gate return (addr); 13090Sstevel@tonic-gate } 13100Sstevel@tonic-gate 13110Sstevel@tonic-gate static void 13120Sstevel@tonic-gate contig_free(void *addr, size_t size) 13130Sstevel@tonic-gate { 13140Sstevel@tonic-gate pgcnt_t pgcnt = btopr(size); 13150Sstevel@tonic-gate size_t asize = pgcnt * PAGESIZE; 13160Sstevel@tonic-gate caddr_t a, ea; 13170Sstevel@tonic-gate page_t *pp; 13180Sstevel@tonic-gate 13190Sstevel@tonic-gate hat_unload(kas.a_hat, addr, asize, HAT_UNLOAD_UNLOCK); 13200Sstevel@tonic-gate 13210Sstevel@tonic-gate for (a = addr, ea = a + asize; a < ea; a += PAGESIZE) { 13220Sstevel@tonic-gate pp = page_find(&kvp, 13230Sstevel@tonic-gate (u_offset_t)(uintptr_t)a); 13240Sstevel@tonic-gate if (!pp) 13250Sstevel@tonic-gate panic("contig_free: contig pp not found"); 13260Sstevel@tonic-gate 13270Sstevel@tonic-gate if (!page_tryupgrade(pp)) { 13280Sstevel@tonic-gate page_unlock(pp); 13290Sstevel@tonic-gate pp = page_lookup(&kvp, 13300Sstevel@tonic-gate (u_offset_t)(uintptr_t)a, SE_EXCL); 13310Sstevel@tonic-gate if (pp == NULL) 13320Sstevel@tonic-gate panic("contig_free: page freed"); 13330Sstevel@tonic-gate } 13340Sstevel@tonic-gate page_destroy(pp, 0); 13350Sstevel@tonic-gate } 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate page_unresv(pgcnt); 13380Sstevel@tonic-gate vmem_free(heap_arena, addr, asize); 13390Sstevel@tonic-gate } 13400Sstevel@tonic-gate 13410Sstevel@tonic-gate /* 13420Sstevel@tonic-gate * Allocate from the system, aligned on a specific boundary. 13430Sstevel@tonic-gate * The alignment, if non-zero, must be a power of 2. 13440Sstevel@tonic-gate */ 13450Sstevel@tonic-gate static void * 13460Sstevel@tonic-gate kalloca(size_t size, size_t align, int cansleep, int physcontig, 13470Sstevel@tonic-gate ddi_dma_attr_t *attr) 13480Sstevel@tonic-gate { 13490Sstevel@tonic-gate size_t *addr, *raddr, rsize; 13500Sstevel@tonic-gate size_t hdrsize = 4 * sizeof (size_t); /* must be power of 2 */ 13510Sstevel@tonic-gate int a, i, c; 13520Sstevel@tonic-gate vmem_t *vmp; 13530Sstevel@tonic-gate kmem_cache_t *cp = NULL; 13540Sstevel@tonic-gate 13551242Scth if (attr->dma_attr_addr_lo > mmu_ptob((uint64_t)ddiphysmin)) 13561242Scth return (NULL); 13571242Scth 13580Sstevel@tonic-gate align = MAX(align, hdrsize); 13590Sstevel@tonic-gate ASSERT((align & (align - 1)) == 0); 13600Sstevel@tonic-gate 13610Sstevel@tonic-gate /* 13620Sstevel@tonic-gate * All of our allocators guarantee 16-byte alignment, so we don't 13630Sstevel@tonic-gate * need to reserve additional space for the header. 13640Sstevel@tonic-gate * To simplify picking the correct kmem_io_cache, we round up to 13650Sstevel@tonic-gate * a multiple of KA_ALIGN. 13660Sstevel@tonic-gate */ 13670Sstevel@tonic-gate rsize = P2ROUNDUP_TYPED(size + align, KA_ALIGN, size_t); 13680Sstevel@tonic-gate 13690Sstevel@tonic-gate if (physcontig && rsize > PAGESIZE) { 13700Sstevel@tonic-gate if (addr = contig_alloc(size, attr, align, cansleep)) { 13710Sstevel@tonic-gate if (!putctgas(addr, size)) 13720Sstevel@tonic-gate contig_free(addr, size); 13730Sstevel@tonic-gate else 13740Sstevel@tonic-gate return (addr); 13750Sstevel@tonic-gate } 13760Sstevel@tonic-gate return (NULL); 13770Sstevel@tonic-gate } 13780Sstevel@tonic-gate 13790Sstevel@tonic-gate a = kmem_io_index(attr->dma_attr_addr_hi); 13800Sstevel@tonic-gate 13810Sstevel@tonic-gate if (rsize > PAGESIZE) { 13820Sstevel@tonic-gate vmp = kmem_io[a].kmem_io_arena; 13830Sstevel@tonic-gate raddr = vmem_alloc(vmp, rsize, 13840Sstevel@tonic-gate (cansleep) ? VM_SLEEP : VM_NOSLEEP); 13850Sstevel@tonic-gate } else { 13860Sstevel@tonic-gate c = highbit((rsize >> KA_ALIGN_SHIFT) - 1); 13870Sstevel@tonic-gate cp = kmem_io[a].kmem_io_cache[c]; 13880Sstevel@tonic-gate raddr = kmem_cache_alloc(cp, (cansleep) ? KM_SLEEP : 13890Sstevel@tonic-gate KM_NOSLEEP); 13900Sstevel@tonic-gate } 13910Sstevel@tonic-gate 13920Sstevel@tonic-gate if (raddr == NULL) { 13930Sstevel@tonic-gate int na; 13940Sstevel@tonic-gate 13950Sstevel@tonic-gate ASSERT(cansleep == 0); 13960Sstevel@tonic-gate if (rsize > PAGESIZE) 13970Sstevel@tonic-gate return (NULL); 13980Sstevel@tonic-gate /* 13990Sstevel@tonic-gate * System does not have memory in the requested range. 14000Sstevel@tonic-gate * Try smaller kmem io ranges and larger cache sizes 14010Sstevel@tonic-gate * to see if there might be memory available in 14020Sstevel@tonic-gate * these other caches. 14030Sstevel@tonic-gate */ 14040Sstevel@tonic-gate 14050Sstevel@tonic-gate for (na = kmem_io_index_next(a); na >= 0; 14060Sstevel@tonic-gate na = kmem_io_index_next(na)) { 14070Sstevel@tonic-gate ASSERT(kmem_io[na].kmem_io_arena); 14080Sstevel@tonic-gate cp = kmem_io[na].kmem_io_cache[c]; 14090Sstevel@tonic-gate raddr = kmem_cache_alloc(cp, KM_NOSLEEP); 14100Sstevel@tonic-gate if (raddr) 14110Sstevel@tonic-gate goto kallocdone; 14120Sstevel@tonic-gate } 14130Sstevel@tonic-gate /* now try the larger kmem io cache sizes */ 14140Sstevel@tonic-gate for (na = a; na >= 0; na = kmem_io_index_next(na)) { 14150Sstevel@tonic-gate for (i = c + 1; i < KA_NCACHE; i++) { 14160Sstevel@tonic-gate cp = kmem_io[na].kmem_io_cache[i]; 14170Sstevel@tonic-gate raddr = kmem_cache_alloc(cp, KM_NOSLEEP); 14180Sstevel@tonic-gate if (raddr) 14190Sstevel@tonic-gate goto kallocdone; 14200Sstevel@tonic-gate } 14210Sstevel@tonic-gate } 14220Sstevel@tonic-gate return (NULL); 14230Sstevel@tonic-gate } 14240Sstevel@tonic-gate 14250Sstevel@tonic-gate kallocdone: 14260Sstevel@tonic-gate ASSERT(!P2CROSS((uintptr_t)raddr, (uintptr_t)raddr + rsize - 1, 14270Sstevel@tonic-gate PAGESIZE) || rsize > PAGESIZE); 14280Sstevel@tonic-gate 14290Sstevel@tonic-gate addr = (size_t *)P2ROUNDUP((uintptr_t)raddr + hdrsize, align); 14300Sstevel@tonic-gate ASSERT((uintptr_t)addr + size - (uintptr_t)raddr <= rsize); 14310Sstevel@tonic-gate 14320Sstevel@tonic-gate addr[-4] = (size_t)cp; 14330Sstevel@tonic-gate addr[-3] = (size_t)vmp; 14340Sstevel@tonic-gate addr[-2] = (size_t)raddr; 14350Sstevel@tonic-gate addr[-1] = rsize; 14360Sstevel@tonic-gate 14370Sstevel@tonic-gate return (addr); 14380Sstevel@tonic-gate } 14390Sstevel@tonic-gate 14400Sstevel@tonic-gate static void 14410Sstevel@tonic-gate kfreea(void *addr) 14420Sstevel@tonic-gate { 14430Sstevel@tonic-gate size_t size; 14440Sstevel@tonic-gate 14450Sstevel@tonic-gate if (!((uintptr_t)addr & PAGEOFFSET) && (size = getctgsz(addr))) { 14460Sstevel@tonic-gate contig_free(addr, size); 14470Sstevel@tonic-gate } else { 14480Sstevel@tonic-gate size_t *saddr = addr; 14490Sstevel@tonic-gate if (saddr[-4] == 0) 14500Sstevel@tonic-gate vmem_free((vmem_t *)saddr[-3], (void *)saddr[-2], 14510Sstevel@tonic-gate saddr[-1]); 14520Sstevel@tonic-gate else 14530Sstevel@tonic-gate kmem_cache_free((kmem_cache_t *)saddr[-4], 14540Sstevel@tonic-gate (void *)saddr[-2]); 14550Sstevel@tonic-gate } 14560Sstevel@tonic-gate } 14570Sstevel@tonic-gate 14580Sstevel@tonic-gate /* 1459*1900Seota * Check if the endianess attribute is supported on the platform. 1460*1900Seota * This function must be called before i_ddi_devacc_to_hatacc(). 1461*1900Seota */ 1462*1900Seota boolean_t 1463*1900Seota i_ddi_check_endian_attr(ddi_device_acc_attr_t *devaccp) 1464*1900Seota { 1465*1900Seota /* 1466*1900Seota * Big endianess is not supported on X86. 1467*1900Seota */ 1468*1900Seota if (devaccp != NULL && 1469*1900Seota devaccp->devacc_attr_endian_flags == DDI_STRUCTURE_BE_ACC) 1470*1900Seota return (B_FALSE); 1471*1900Seota 1472*1900Seota return (B_TRUE); 1473*1900Seota } 1474*1900Seota 1475*1900Seota /* set HAT endianess attributes from ddi_device_acc_attr */ 1476*1900Seota void 1477*1900Seota i_ddi_devacc_to_hatacc(ddi_device_acc_attr_t *devaccp, uint_t *hataccp) 1478*1900Seota { 1479*1900Seota #if defined(lint) 1480*1900Seota *hataccp = *hataccp; 1481*1900Seota #endif 1482*1900Seota static char *fname = "i_ddi_devacc_to_hatacc"; 1483*1900Seota /* 1484*1900Seota * This case must not occur because the endianess is examined 1485*1900Seota * before this function is called. 1486*1900Seota */ 1487*1900Seota if (devaccp != NULL && 1488*1900Seota devaccp->devacc_attr_endian_flags == DDI_STRUCTURE_BE_ACC) { 1489*1900Seota cmn_err(CE_WARN, 1490*1900Seota "%s: devacc_attr_endian_flags=0x%x is ignored.", 1491*1900Seota fname, devaccp->devacc_attr_endian_flags); 1492*1900Seota } 1493*1900Seota } 1494*1900Seota 1495*1900Seota /* 1496*1900Seota * Check if the specified cache attribute is supported on the platform. 1497*1900Seota * This function must be called before i_ddi_cacheattr_to_hatacc(). 1498*1900Seota */ 1499*1900Seota boolean_t 1500*1900Seota i_ddi_check_cache_attr(uint_t flags) 1501*1900Seota { 1502*1900Seota /* 1503*1900Seota * The cache attributes are mutually exclusive. Any combination of 1504*1900Seota * the attributes leads to a failure. 1505*1900Seota */ 1506*1900Seota uint_t cache_attr = IOMEM_CACHE_ATTR(flags); 1507*1900Seota if ((cache_attr != 0) && ((cache_attr & (cache_attr - 1)) != 0)) 1508*1900Seota return (B_FALSE); 1509*1900Seota 1510*1900Seota /* All cache attributes are supported on X86/X64 */ 1511*1900Seota if (cache_attr & (IOMEM_DATA_UNCACHED | IOMEM_DATA_CACHED | 1512*1900Seota IOMEM_DATA_UC_WR_COMBINE)) 1513*1900Seota return (B_TRUE); 1514*1900Seota 1515*1900Seota /* undefined attributes */ 1516*1900Seota return (B_FALSE); 1517*1900Seota } 1518*1900Seota 1519*1900Seota /* set HAT cache attributes from the cache attributes */ 1520*1900Seota void 1521*1900Seota i_ddi_cacheattr_to_hatacc(uint_t flags, uint_t *hataccp) 1522*1900Seota { 1523*1900Seota uint_t cache_attr = IOMEM_CACHE_ATTR(flags); 1524*1900Seota static char *fname = "i_ddi_cacheattr_to_hatacc"; 1525*1900Seota 1526*1900Seota /* 1527*1900Seota * If write-combining is not supported, then it falls back 1528*1900Seota * to uncacheable. 1529*1900Seota */ 1530*1900Seota if (cache_attr == IOMEM_DATA_UC_WR_COMBINE && !(x86_feature & X86_PAT)) 1531*1900Seota cache_attr = IOMEM_DATA_UNCACHED; 1532*1900Seota 1533*1900Seota /* 1534*1900Seota * set HAT attrs according to the cache attrs. 1535*1900Seota */ 1536*1900Seota switch (cache_attr) { 1537*1900Seota case IOMEM_DATA_UNCACHED: 1538*1900Seota *hataccp &= ~HAT_ORDER_MASK; 1539*1900Seota *hataccp |= (HAT_STRICTORDER | HAT_PLAT_NOCACHE); 1540*1900Seota break; 1541*1900Seota case IOMEM_DATA_UC_WR_COMBINE: 1542*1900Seota *hataccp &= ~HAT_ORDER_MASK; 1543*1900Seota *hataccp |= (HAT_MERGING_OK | HAT_PLAT_NOCACHE); 1544*1900Seota break; 1545*1900Seota case IOMEM_DATA_CACHED: 1546*1900Seota *hataccp &= ~HAT_ORDER_MASK; 1547*1900Seota *hataccp |= HAT_UNORDERED_OK; 1548*1900Seota break; 1549*1900Seota /* 1550*1900Seota * This case must not occur because the cache attribute is scrutinized 1551*1900Seota * before this function is called. 1552*1900Seota */ 1553*1900Seota default: 1554*1900Seota /* 1555*1900Seota * set cacheable to hat attrs. 1556*1900Seota */ 1557*1900Seota *hataccp &= ~HAT_ORDER_MASK; 1558*1900Seota *hataccp |= HAT_UNORDERED_OK; 1559*1900Seota cmn_err(CE_WARN, "%s: cache_attr=0x%x is ignored.", 1560*1900Seota fname, cache_attr); 1561*1900Seota } 1562*1900Seota } 1563*1900Seota 1564*1900Seota /* 15650Sstevel@tonic-gate * This should actually be called i_ddi_dma_mem_alloc. There should 15660Sstevel@tonic-gate * also be an i_ddi_pio_mem_alloc. i_ddi_dma_mem_alloc should call 15670Sstevel@tonic-gate * through the device tree with the DDI_CTLOPS_DMA_ALIGN ctl ops to 15680Sstevel@tonic-gate * get alignment requirements for DMA memory. i_ddi_pio_mem_alloc 15690Sstevel@tonic-gate * should use DDI_CTLOPS_PIO_ALIGN. Since we only have i_ddi_mem_alloc 15700Sstevel@tonic-gate * so far which is used for both, DMA and PIO, we have to use the DMA 15710Sstevel@tonic-gate * ctl ops to make everybody happy. 15720Sstevel@tonic-gate */ 15730Sstevel@tonic-gate /*ARGSUSED*/ 15740Sstevel@tonic-gate int 15750Sstevel@tonic-gate i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attr, 1576*1900Seota size_t length, int cansleep, int flags, 15770Sstevel@tonic-gate ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, 15780Sstevel@tonic-gate size_t *real_length, ddi_acc_hdl_t *ap) 15790Sstevel@tonic-gate { 15800Sstevel@tonic-gate caddr_t a; 15810Sstevel@tonic-gate int iomin; 15820Sstevel@tonic-gate ddi_acc_impl_t *iap; 15830Sstevel@tonic-gate int physcontig = 0; 15840Sstevel@tonic-gate pgcnt_t npages; 15850Sstevel@tonic-gate pgcnt_t minctg; 1586*1900Seota uint_t order; 1587*1900Seota int e; 15880Sstevel@tonic-gate 15890Sstevel@tonic-gate /* 15900Sstevel@tonic-gate * Check legality of arguments 15910Sstevel@tonic-gate */ 15920Sstevel@tonic-gate if (length == 0 || kaddrp == NULL || attr == NULL) { 15930Sstevel@tonic-gate return (DDI_FAILURE); 15940Sstevel@tonic-gate } 1595*1900Seota 15960Sstevel@tonic-gate if (attr->dma_attr_minxfer == 0 || attr->dma_attr_align == 0 || 15970Sstevel@tonic-gate (attr->dma_attr_align & (attr->dma_attr_align - 1)) || 15980Sstevel@tonic-gate (attr->dma_attr_minxfer & (attr->dma_attr_minxfer - 1))) { 15990Sstevel@tonic-gate return (DDI_FAILURE); 16000Sstevel@tonic-gate } 16010Sstevel@tonic-gate 16020Sstevel@tonic-gate /* 16030Sstevel@tonic-gate * figure out most restrictive alignment requirement 16040Sstevel@tonic-gate */ 16050Sstevel@tonic-gate iomin = attr->dma_attr_minxfer; 16060Sstevel@tonic-gate iomin = maxbit(iomin, attr->dma_attr_align); 16070Sstevel@tonic-gate if (iomin == 0) 16080Sstevel@tonic-gate return (DDI_FAILURE); 16090Sstevel@tonic-gate 16100Sstevel@tonic-gate ASSERT((iomin & (iomin - 1)) == 0); 16110Sstevel@tonic-gate 1612*1900Seota /* 1613*1900Seota * if we allocate memory with IOMEM_DATA_UNCACHED or 1614*1900Seota * IOMEM_DATA_UC_WR_COMBINE, make sure we allocate a page aligned 1615*1900Seota * memory that ends on a page boundry. 1616*1900Seota * Don't want to have to different cache mappings to the same 1617*1900Seota * physical page. 1618*1900Seota */ 1619*1900Seota if (OVERRIDE_CACHE_ATTR(flags)) { 1620*1900Seota iomin = (iomin + MMU_PAGEOFFSET) & MMU_PAGEMASK; 1621*1900Seota length = (length + MMU_PAGEOFFSET) & (size_t)MMU_PAGEMASK; 1622*1900Seota } 16230Sstevel@tonic-gate 16240Sstevel@tonic-gate /* 16250Sstevel@tonic-gate * Determine if we need to satisfy the request for physically 16260Sstevel@tonic-gate * contiguous memory or alignments larger than pagesize. 16270Sstevel@tonic-gate */ 16280Sstevel@tonic-gate npages = btopr(length + attr->dma_attr_align); 16290Sstevel@tonic-gate minctg = howmany(npages, attr->dma_attr_sgllen); 16300Sstevel@tonic-gate 16310Sstevel@tonic-gate if (minctg > 1) { 16320Sstevel@tonic-gate uint64_t pfnseg = attr->dma_attr_seg >> PAGESHIFT; 16330Sstevel@tonic-gate /* 16340Sstevel@tonic-gate * verify that the minimum contig requirement for the 16350Sstevel@tonic-gate * actual length does not cross segment boundary. 16360Sstevel@tonic-gate */ 16370Sstevel@tonic-gate length = P2ROUNDUP_TYPED(length, attr->dma_attr_minxfer, 16380Sstevel@tonic-gate size_t); 16390Sstevel@tonic-gate npages = btopr(length); 16400Sstevel@tonic-gate minctg = howmany(npages, attr->dma_attr_sgllen); 16410Sstevel@tonic-gate if (minctg > pfnseg + 1) 16420Sstevel@tonic-gate return (DDI_FAILURE); 16430Sstevel@tonic-gate physcontig = 1; 16440Sstevel@tonic-gate } else { 16450Sstevel@tonic-gate length = P2ROUNDUP_TYPED(length, iomin, size_t); 16460Sstevel@tonic-gate } 16470Sstevel@tonic-gate 16480Sstevel@tonic-gate /* 16490Sstevel@tonic-gate * Allocate the requested amount from the system. 16500Sstevel@tonic-gate */ 16510Sstevel@tonic-gate a = kalloca(length, iomin, cansleep, physcontig, attr); 16520Sstevel@tonic-gate 16530Sstevel@tonic-gate if ((*kaddrp = a) == NULL) 16540Sstevel@tonic-gate return (DDI_FAILURE); 16550Sstevel@tonic-gate 1656*1900Seota /* 1657*1900Seota * if we to modify the cache attributes, go back and muck with the 1658*1900Seota * mappings. 1659*1900Seota */ 1660*1900Seota if (OVERRIDE_CACHE_ATTR(flags)) { 1661*1900Seota order = 0; 1662*1900Seota i_ddi_cacheattr_to_hatacc(flags, &order); 1663*1900Seota e = kmem_override_cache_attrs(a, length, order); 1664*1900Seota if (e != 0) { 1665*1900Seota kfreea(a); 1666*1900Seota return (DDI_FAILURE); 1667*1900Seota } 1668*1900Seota } 1669*1900Seota 16700Sstevel@tonic-gate if (real_length) { 16710Sstevel@tonic-gate *real_length = length; 16720Sstevel@tonic-gate } 16730Sstevel@tonic-gate if (ap) { 16740Sstevel@tonic-gate /* 16750Sstevel@tonic-gate * initialize access handle 16760Sstevel@tonic-gate */ 16770Sstevel@tonic-gate iap = (ddi_acc_impl_t *)ap->ah_platform_private; 16780Sstevel@tonic-gate iap->ahi_acc_attr |= DDI_ACCATTR_CPU_VADDR; 16790Sstevel@tonic-gate impl_acc_hdl_init(ap); 16800Sstevel@tonic-gate } 1681*1900Seota 16820Sstevel@tonic-gate return (DDI_SUCCESS); 16830Sstevel@tonic-gate } 16840Sstevel@tonic-gate 16850Sstevel@tonic-gate /* 16860Sstevel@tonic-gate * covert old DMA limits structure to DMA attribute structure 16870Sstevel@tonic-gate * and continue 16880Sstevel@tonic-gate */ 16890Sstevel@tonic-gate int 16900Sstevel@tonic-gate i_ddi_mem_alloc_lim(dev_info_t *dip, ddi_dma_lim_t *limits, 16910Sstevel@tonic-gate size_t length, int cansleep, int streaming, 16920Sstevel@tonic-gate ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, 16930Sstevel@tonic-gate uint_t *real_length, ddi_acc_hdl_t *ap) 16940Sstevel@tonic-gate { 16950Sstevel@tonic-gate ddi_dma_attr_t dma_attr, *attrp; 16960Sstevel@tonic-gate size_t rlen; 16970Sstevel@tonic-gate int ret; 16980Sstevel@tonic-gate 16990Sstevel@tonic-gate if (limits == NULL) { 17000Sstevel@tonic-gate return (DDI_FAILURE); 17010Sstevel@tonic-gate } 17020Sstevel@tonic-gate 17030Sstevel@tonic-gate /* 17040Sstevel@tonic-gate * set up DMA attribute structure to pass to i_ddi_mem_alloc() 17050Sstevel@tonic-gate */ 17060Sstevel@tonic-gate attrp = &dma_attr; 17070Sstevel@tonic-gate attrp->dma_attr_version = DMA_ATTR_V0; 17080Sstevel@tonic-gate attrp->dma_attr_addr_lo = (uint64_t)limits->dlim_addr_lo; 17090Sstevel@tonic-gate attrp->dma_attr_addr_hi = (uint64_t)limits->dlim_addr_hi; 17100Sstevel@tonic-gate attrp->dma_attr_count_max = (uint64_t)limits->dlim_ctreg_max; 17110Sstevel@tonic-gate attrp->dma_attr_align = 1; 17120Sstevel@tonic-gate attrp->dma_attr_burstsizes = (uint_t)limits->dlim_burstsizes; 17130Sstevel@tonic-gate attrp->dma_attr_minxfer = (uint32_t)limits->dlim_minxfer; 17140Sstevel@tonic-gate attrp->dma_attr_maxxfer = (uint64_t)limits->dlim_reqsize; 17150Sstevel@tonic-gate attrp->dma_attr_seg = (uint64_t)limits->dlim_adreg_max; 17160Sstevel@tonic-gate attrp->dma_attr_sgllen = limits->dlim_sgllen; 17170Sstevel@tonic-gate attrp->dma_attr_granular = (uint32_t)limits->dlim_granular; 17180Sstevel@tonic-gate attrp->dma_attr_flags = 0; 17190Sstevel@tonic-gate 17200Sstevel@tonic-gate ret = i_ddi_mem_alloc(dip, attrp, length, cansleep, streaming, 17210Sstevel@tonic-gate accattrp, kaddrp, &rlen, ap); 17220Sstevel@tonic-gate if (ret == DDI_SUCCESS) { 17230Sstevel@tonic-gate if (real_length) 17240Sstevel@tonic-gate *real_length = (uint_t)rlen; 17250Sstevel@tonic-gate } 17260Sstevel@tonic-gate return (ret); 17270Sstevel@tonic-gate } 17280Sstevel@tonic-gate 17290Sstevel@tonic-gate /* ARGSUSED */ 17300Sstevel@tonic-gate void 1731*1900Seota i_ddi_mem_free(caddr_t kaddr, ddi_acc_hdl_t *ap) 17320Sstevel@tonic-gate { 1733*1900Seota if (ap != NULL) { 1734*1900Seota /* 1735*1900Seota * if we modified the cache attributes on alloc, go back and 1736*1900Seota * fix them since this memory could be returned to the 1737*1900Seota * general pool. 1738*1900Seota */ 1739*1900Seota if (OVERRIDE_CACHE_ATTR(ap->ah_xfermodes)) { 1740*1900Seota uint_t order = 0; 1741*1900Seota int e; 1742*1900Seota i_ddi_cacheattr_to_hatacc(IOMEM_DATA_CACHED, &order); 1743*1900Seota e = kmem_override_cache_attrs(kaddr, ap->ah_len, order); 1744*1900Seota if (e != 0) { 1745*1900Seota cmn_err(CE_WARN, "i_ddi_mem_free() failed to " 1746*1900Seota "override cache attrs, memory leaked\n"); 1747*1900Seota return; 1748*1900Seota } 1749*1900Seota } 1750*1900Seota } 17510Sstevel@tonic-gate kfreea(kaddr); 17520Sstevel@tonic-gate } 17530Sstevel@tonic-gate 17540Sstevel@tonic-gate /* 17550Sstevel@tonic-gate * Access Barriers 17560Sstevel@tonic-gate * 17570Sstevel@tonic-gate */ 17580Sstevel@tonic-gate /*ARGSUSED*/ 17590Sstevel@tonic-gate int 17600Sstevel@tonic-gate i_ddi_ontrap(ddi_acc_handle_t hp) 17610Sstevel@tonic-gate { 17620Sstevel@tonic-gate return (DDI_FAILURE); 17630Sstevel@tonic-gate } 17640Sstevel@tonic-gate 17650Sstevel@tonic-gate /*ARGSUSED*/ 17660Sstevel@tonic-gate void 17670Sstevel@tonic-gate i_ddi_notrap(ddi_acc_handle_t hp) 17680Sstevel@tonic-gate { 17690Sstevel@tonic-gate } 17700Sstevel@tonic-gate 17710Sstevel@tonic-gate 17720Sstevel@tonic-gate /* 17730Sstevel@tonic-gate * Misc Functions 17740Sstevel@tonic-gate */ 17750Sstevel@tonic-gate 17760Sstevel@tonic-gate /* 17770Sstevel@tonic-gate * Implementation instance override functions 17780Sstevel@tonic-gate * 17790Sstevel@tonic-gate * No override on i86pc 17800Sstevel@tonic-gate */ 17810Sstevel@tonic-gate /*ARGSUSED*/ 17820Sstevel@tonic-gate uint_t 17830Sstevel@tonic-gate impl_assign_instance(dev_info_t *dip) 17840Sstevel@tonic-gate { 17850Sstevel@tonic-gate return ((uint_t)-1); 17860Sstevel@tonic-gate } 17870Sstevel@tonic-gate 17880Sstevel@tonic-gate /*ARGSUSED*/ 17890Sstevel@tonic-gate int 17900Sstevel@tonic-gate impl_keep_instance(dev_info_t *dip) 17910Sstevel@tonic-gate { 17920Sstevel@tonic-gate return (DDI_FAILURE); 17930Sstevel@tonic-gate } 17940Sstevel@tonic-gate 17950Sstevel@tonic-gate /*ARGSUSED*/ 17960Sstevel@tonic-gate int 17970Sstevel@tonic-gate impl_free_instance(dev_info_t *dip) 17980Sstevel@tonic-gate { 17990Sstevel@tonic-gate return (DDI_FAILURE); 18000Sstevel@tonic-gate } 18010Sstevel@tonic-gate 18020Sstevel@tonic-gate /*ARGSUSED*/ 18030Sstevel@tonic-gate int 18040Sstevel@tonic-gate impl_check_cpu(dev_info_t *devi) 18050Sstevel@tonic-gate { 18060Sstevel@tonic-gate return (DDI_SUCCESS); 18070Sstevel@tonic-gate } 18080Sstevel@tonic-gate 18090Sstevel@tonic-gate /* 18100Sstevel@tonic-gate * Referenced in common/cpr_driver.c: Power off machine. 18110Sstevel@tonic-gate * Don't know how to power off i86pc. 18120Sstevel@tonic-gate */ 18130Sstevel@tonic-gate void 18140Sstevel@tonic-gate arch_power_down() 18150Sstevel@tonic-gate {} 18160Sstevel@tonic-gate 18170Sstevel@tonic-gate /* 18180Sstevel@tonic-gate * Copy name to property_name, since name 18190Sstevel@tonic-gate * is in the low address range below kernelbase. 18200Sstevel@tonic-gate */ 18210Sstevel@tonic-gate static void 18220Sstevel@tonic-gate copy_boot_str(const char *boot_str, char *kern_str, int len) 18230Sstevel@tonic-gate { 18240Sstevel@tonic-gate int i = 0; 18250Sstevel@tonic-gate 18260Sstevel@tonic-gate while (i < len - 1 && boot_str[i] != '\0') { 18270Sstevel@tonic-gate kern_str[i] = boot_str[i]; 18280Sstevel@tonic-gate i++; 18290Sstevel@tonic-gate } 18300Sstevel@tonic-gate 18310Sstevel@tonic-gate kern_str[i] = 0; /* null terminate */ 18320Sstevel@tonic-gate if (boot_str[i] != '\0') 18330Sstevel@tonic-gate cmn_err(CE_WARN, 18340Sstevel@tonic-gate "boot property string is truncated to %s", kern_str); 18350Sstevel@tonic-gate } 18360Sstevel@tonic-gate 18370Sstevel@tonic-gate static void 18380Sstevel@tonic-gate get_boot_properties(void) 18390Sstevel@tonic-gate { 18400Sstevel@tonic-gate extern char hw_provider[]; 18410Sstevel@tonic-gate dev_info_t *devi; 18420Sstevel@tonic-gate char *name; 18430Sstevel@tonic-gate int length; 18440Sstevel@tonic-gate char property_name[50], property_val[50]; 18450Sstevel@tonic-gate void *bop_staging_area; 18460Sstevel@tonic-gate 18470Sstevel@tonic-gate bop_staging_area = kmem_zalloc(MMU_PAGESIZE, KM_NOSLEEP); 18480Sstevel@tonic-gate 18490Sstevel@tonic-gate /* 18500Sstevel@tonic-gate * Import "root" properties from the boot. 18510Sstevel@tonic-gate * 18520Sstevel@tonic-gate * We do this by invoking BOP_NEXTPROP until the list 18530Sstevel@tonic-gate * is completely copied in. 18540Sstevel@tonic-gate */ 18550Sstevel@tonic-gate 18560Sstevel@tonic-gate devi = ddi_root_node(); 18570Sstevel@tonic-gate for (name = BOP_NEXTPROP(bootops, ""); /* get first */ 18580Sstevel@tonic-gate name; /* NULL => DONE */ 18590Sstevel@tonic-gate name = BOP_NEXTPROP(bootops, name)) { /* get next */ 18600Sstevel@tonic-gate 18610Sstevel@tonic-gate /* copy string to memory above kernelbase */ 18620Sstevel@tonic-gate copy_boot_str(name, property_name, 50); 18630Sstevel@tonic-gate 18640Sstevel@tonic-gate /* 18650Sstevel@tonic-gate * Skip vga properties. They will be picked up later 18660Sstevel@tonic-gate * by get_vga_properties. 18670Sstevel@tonic-gate */ 18680Sstevel@tonic-gate if (strcmp(property_name, "display-edif-block") == 0 || 18690Sstevel@tonic-gate strcmp(property_name, "display-edif-id") == 0) { 18700Sstevel@tonic-gate continue; 18710Sstevel@tonic-gate } 18720Sstevel@tonic-gate 18730Sstevel@tonic-gate length = BOP_GETPROPLEN(bootops, property_name); 18740Sstevel@tonic-gate if (length == 0) 18750Sstevel@tonic-gate continue; 18760Sstevel@tonic-gate if (length > MMU_PAGESIZE) { 18770Sstevel@tonic-gate cmn_err(CE_NOTE, 18780Sstevel@tonic-gate "boot property %s longer than 0x%x, ignored\n", 18790Sstevel@tonic-gate property_name, MMU_PAGESIZE); 18800Sstevel@tonic-gate continue; 18810Sstevel@tonic-gate } 18820Sstevel@tonic-gate BOP_GETPROP(bootops, property_name, bop_staging_area); 18830Sstevel@tonic-gate 18840Sstevel@tonic-gate /* 18850Sstevel@tonic-gate * special properties: 18860Sstevel@tonic-gate * si-machine, si-hw-provider 18870Sstevel@tonic-gate * goes to kernel data structures. 18880Sstevel@tonic-gate * bios-boot-device and stdout 18890Sstevel@tonic-gate * goes to hardware property list so it may show up 18900Sstevel@tonic-gate * in the prtconf -vp output. This is needed by 18910Sstevel@tonic-gate * Install/Upgrade. Once we fix install upgrade, 18920Sstevel@tonic-gate * this can be taken out. 18930Sstevel@tonic-gate */ 18940Sstevel@tonic-gate if (strcmp(name, "si-machine") == 0) { 18950Sstevel@tonic-gate (void) strncpy(utsname.machine, bop_staging_area, 18960Sstevel@tonic-gate SYS_NMLN); 18970Sstevel@tonic-gate utsname.machine[SYS_NMLN - 1] = (char)NULL; 18980Sstevel@tonic-gate } else if (strcmp(name, "si-hw-provider") == 0) { 18990Sstevel@tonic-gate (void) strncpy(hw_provider, bop_staging_area, SYS_NMLN); 19000Sstevel@tonic-gate hw_provider[SYS_NMLN - 1] = (char)NULL; 19010Sstevel@tonic-gate } else if (strcmp(name, "bios-boot-device") == 0) { 19020Sstevel@tonic-gate copy_boot_str(bop_staging_area, property_val, 50); 19030Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, devi, 19040Sstevel@tonic-gate property_name, property_val); 19050Sstevel@tonic-gate } else if (strcmp(name, "stdout") == 0) { 19060Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, 19070Sstevel@tonic-gate property_name, *((int *)bop_staging_area)); 19080Sstevel@tonic-gate } else { 19090Sstevel@tonic-gate /* Property type unknown, use old prop interface */ 19100Sstevel@tonic-gate (void) e_ddi_prop_create(DDI_DEV_T_NONE, devi, 19110Sstevel@tonic-gate DDI_PROP_CANSLEEP, property_name, bop_staging_area, 19120Sstevel@tonic-gate length); 19130Sstevel@tonic-gate } 19140Sstevel@tonic-gate } 19150Sstevel@tonic-gate 19160Sstevel@tonic-gate kmem_free(bop_staging_area, MMU_PAGESIZE); 19170Sstevel@tonic-gate } 19180Sstevel@tonic-gate 19190Sstevel@tonic-gate static void 19200Sstevel@tonic-gate get_vga_properties(void) 19210Sstevel@tonic-gate { 19220Sstevel@tonic-gate dev_info_t *devi; 19230Sstevel@tonic-gate major_t major; 19240Sstevel@tonic-gate char *name; 19250Sstevel@tonic-gate int length; 19260Sstevel@tonic-gate char property_val[50]; 19270Sstevel@tonic-gate void *bop_staging_area; 19280Sstevel@tonic-gate 19290Sstevel@tonic-gate major = ddi_name_to_major("vgatext"); 19300Sstevel@tonic-gate if (major == (major_t)-1) 19310Sstevel@tonic-gate return; 19320Sstevel@tonic-gate devi = devnamesp[major].dn_head; 19330Sstevel@tonic-gate if (devi == NULL) 19340Sstevel@tonic-gate return; 19350Sstevel@tonic-gate 19360Sstevel@tonic-gate bop_staging_area = kmem_zalloc(MMU_PAGESIZE, KM_SLEEP); 19370Sstevel@tonic-gate 19380Sstevel@tonic-gate /* 19390Sstevel@tonic-gate * Import "vga" properties from the boot. 19400Sstevel@tonic-gate */ 19410Sstevel@tonic-gate name = "display-edif-block"; 19420Sstevel@tonic-gate length = BOP_GETPROPLEN(bootops, name); 19430Sstevel@tonic-gate if (length > 0 && length < MMU_PAGESIZE) { 19440Sstevel@tonic-gate BOP_GETPROP(bootops, name, bop_staging_area); 19450Sstevel@tonic-gate (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE, 19460Sstevel@tonic-gate devi, name, bop_staging_area, length); 19470Sstevel@tonic-gate } 19480Sstevel@tonic-gate 19490Sstevel@tonic-gate /* 19500Sstevel@tonic-gate * kdmconfig is also looking for display-type and 19510Sstevel@tonic-gate * video-adapter-type. We default to color and svga. 19520Sstevel@tonic-gate * 19530Sstevel@tonic-gate * Could it be "monochrome", "vga"? 19540Sstevel@tonic-gate * Nah, you've got to come to the 21st century... 19550Sstevel@tonic-gate * And you can set monitor type manually in kdmconfig 19560Sstevel@tonic-gate * if you are really an old junky. 19570Sstevel@tonic-gate */ 19580Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 19590Sstevel@tonic-gate devi, "display-type", "color"); 19600Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 19610Sstevel@tonic-gate devi, "video-adapter-type", "svga"); 19620Sstevel@tonic-gate 19630Sstevel@tonic-gate name = "display-edif-id"; 19640Sstevel@tonic-gate length = BOP_GETPROPLEN(bootops, name); 19650Sstevel@tonic-gate if (length > 0 && length < MMU_PAGESIZE) { 19660Sstevel@tonic-gate BOP_GETPROP(bootops, name, bop_staging_area); 19670Sstevel@tonic-gate copy_boot_str(bop_staging_area, property_val, length); 19680Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 19690Sstevel@tonic-gate devi, name, property_val); 19700Sstevel@tonic-gate } 19710Sstevel@tonic-gate 19720Sstevel@tonic-gate kmem_free(bop_staging_area, MMU_PAGESIZE); 19730Sstevel@tonic-gate } 19740Sstevel@tonic-gate 19750Sstevel@tonic-gate 19760Sstevel@tonic-gate /* 19770Sstevel@tonic-gate * This is temporary, but absolutely necessary. If we are being 19780Sstevel@tonic-gate * booted with a device tree created by the DevConf project's bootconf 19790Sstevel@tonic-gate * program, then we have device information nodes that reflect 19800Sstevel@tonic-gate * reality. At this point in time in the Solaris release schedule, the 19810Sstevel@tonic-gate * kernel drivers aren't prepared for reality. They still depend on their 19820Sstevel@tonic-gate * own ad-hoc interpretations of the properties created when their .conf 19830Sstevel@tonic-gate * files were interpreted. These drivers use an "ignore-hardware-nodes" 19840Sstevel@tonic-gate * property to prevent them from using the nodes passed up from the bootconf 19850Sstevel@tonic-gate * device tree. 19860Sstevel@tonic-gate * 19870Sstevel@tonic-gate * Trying to assemble root file system drivers as we are booting from 19880Sstevel@tonic-gate * devconf will fail if the kernel driver is basing its name_addr's on the 19890Sstevel@tonic-gate * psuedo-node device info while the bootpath passed up from bootconf is using 19900Sstevel@tonic-gate * reality-based name_addrs. We help the boot along in this case by 19910Sstevel@tonic-gate * looking at the pre-bootconf bootpath and determining if we would have 19920Sstevel@tonic-gate * successfully matched if that had been the bootpath we had chosen. 19930Sstevel@tonic-gate * 19940Sstevel@tonic-gate * Note that we only even perform this extra check if we've booted 19950Sstevel@tonic-gate * using bootconf's 1275 compliant bootpath, this is the boot device, and 19960Sstevel@tonic-gate * we're trying to match the name_addr specified in the 1275 bootpath. 19970Sstevel@tonic-gate */ 19980Sstevel@tonic-gate 19990Sstevel@tonic-gate #define MAXCOMPONENTLEN 32 20000Sstevel@tonic-gate 20010Sstevel@tonic-gate int 20020Sstevel@tonic-gate x86_old_bootpath_name_addr_match(dev_info_t *cdip, char *caddr, char *naddr) 20030Sstevel@tonic-gate { 20040Sstevel@tonic-gate /* 20050Sstevel@tonic-gate * There are multiple criteria to be met before we can even 20060Sstevel@tonic-gate * consider allowing a name_addr match here. 20070Sstevel@tonic-gate * 20080Sstevel@tonic-gate * 1) We must have been booted such that the bootconf program 20090Sstevel@tonic-gate * created device tree nodes and properties. This can be 20100Sstevel@tonic-gate * determined by examining the 'bootpath' property. This 20110Sstevel@tonic-gate * property will be a non-null string iff bootconf was 20120Sstevel@tonic-gate * involved in the boot. 20130Sstevel@tonic-gate * 20140Sstevel@tonic-gate * 2) The module that we want to match must be the boot device. 20150Sstevel@tonic-gate * 20160Sstevel@tonic-gate * 3) The instance of the module we are thinking of letting be 20170Sstevel@tonic-gate * our match must be ignoring hardware nodes. 20180Sstevel@tonic-gate * 20190Sstevel@tonic-gate * 4) The name_addr we want to match must be the name_addr 20200Sstevel@tonic-gate * specified in the 1275 bootpath. 20210Sstevel@tonic-gate */ 20220Sstevel@tonic-gate static char bootdev_module[MAXCOMPONENTLEN]; 20230Sstevel@tonic-gate static char bootdev_oldmod[MAXCOMPONENTLEN]; 20240Sstevel@tonic-gate static char bootdev_newaddr[MAXCOMPONENTLEN]; 20250Sstevel@tonic-gate static char bootdev_oldaddr[MAXCOMPONENTLEN]; 20260Sstevel@tonic-gate static int quickexit; 20270Sstevel@tonic-gate 20280Sstevel@tonic-gate char *daddr; 20290Sstevel@tonic-gate int dlen; 20300Sstevel@tonic-gate 20310Sstevel@tonic-gate char *lkupname; 20320Sstevel@tonic-gate int rv = DDI_FAILURE; 20330Sstevel@tonic-gate 20340Sstevel@tonic-gate if ((ddi_getlongprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 20350Sstevel@tonic-gate "devconf-addr", (caddr_t)&daddr, &dlen) == DDI_PROP_SUCCESS) && 20360Sstevel@tonic-gate (ddi_getprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 20370Sstevel@tonic-gate "ignore-hardware-nodes", -1) != -1)) { 20380Sstevel@tonic-gate if (strcmp(daddr, caddr) == 0) { 20390Sstevel@tonic-gate return (DDI_SUCCESS); 20400Sstevel@tonic-gate } 20410Sstevel@tonic-gate } 20420Sstevel@tonic-gate 20430Sstevel@tonic-gate if (quickexit) 20440Sstevel@tonic-gate return (rv); 20450Sstevel@tonic-gate 20460Sstevel@tonic-gate if (bootdev_module[0] == '\0') { 20470Sstevel@tonic-gate char *addrp, *eoaddrp; 20480Sstevel@tonic-gate char *busp, *modp, *atp; 20490Sstevel@tonic-gate char *bp1275, *bp; 20500Sstevel@tonic-gate int bp1275len, bplen; 20510Sstevel@tonic-gate 20520Sstevel@tonic-gate bp1275 = bp = addrp = eoaddrp = busp = modp = atp = NULL; 20530Sstevel@tonic-gate 20540Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, 20550Sstevel@tonic-gate ddi_root_node(), 0, "bootpath", 20560Sstevel@tonic-gate (caddr_t)&bp1275, &bp1275len) != DDI_PROP_SUCCESS || 20570Sstevel@tonic-gate bp1275len <= 1) { 20580Sstevel@tonic-gate /* 20590Sstevel@tonic-gate * We didn't boot from bootconf so we never need to 20600Sstevel@tonic-gate * do any special matches. 20610Sstevel@tonic-gate */ 20620Sstevel@tonic-gate quickexit = 1; 20630Sstevel@tonic-gate if (bp1275) 20640Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 20650Sstevel@tonic-gate return (rv); 20660Sstevel@tonic-gate } 20670Sstevel@tonic-gate 20680Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, 20690Sstevel@tonic-gate ddi_root_node(), 0, "boot-path", 20700Sstevel@tonic-gate (caddr_t)&bp, &bplen) != DDI_PROP_SUCCESS || bplen <= 1) { 20710Sstevel@tonic-gate /* 20720Sstevel@tonic-gate * No fallback position for matching. This is 20730Sstevel@tonic-gate * certainly unexpected, but we'll handle it 20740Sstevel@tonic-gate * just in case. 20750Sstevel@tonic-gate */ 20760Sstevel@tonic-gate quickexit = 1; 20770Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 20780Sstevel@tonic-gate if (bp) 20790Sstevel@tonic-gate kmem_free(bp, bplen); 20800Sstevel@tonic-gate return (rv); 20810Sstevel@tonic-gate } 20820Sstevel@tonic-gate 20830Sstevel@tonic-gate /* 20840Sstevel@tonic-gate * Determine boot device module and 1275 name_addr 20850Sstevel@tonic-gate * 20860Sstevel@tonic-gate * bootpath assumed to be of the form /bus/module@name_addr 20870Sstevel@tonic-gate */ 20880Sstevel@tonic-gate if (busp = strchr(bp1275, '/')) { 20890Sstevel@tonic-gate if (modp = strchr(busp + 1, '/')) { 20900Sstevel@tonic-gate if (atp = strchr(modp + 1, '@')) { 20910Sstevel@tonic-gate *atp = '\0'; 20920Sstevel@tonic-gate addrp = atp + 1; 20930Sstevel@tonic-gate if (eoaddrp = strchr(addrp, '/')) 20940Sstevel@tonic-gate *eoaddrp = '\0'; 20950Sstevel@tonic-gate } 20960Sstevel@tonic-gate } 20970Sstevel@tonic-gate } 20980Sstevel@tonic-gate 20990Sstevel@tonic-gate if (modp && addrp) { 21000Sstevel@tonic-gate (void) strncpy(bootdev_module, modp + 1, 21010Sstevel@tonic-gate MAXCOMPONENTLEN); 21020Sstevel@tonic-gate bootdev_module[MAXCOMPONENTLEN - 1] = '\0'; 21030Sstevel@tonic-gate 21040Sstevel@tonic-gate (void) strncpy(bootdev_newaddr, addrp, MAXCOMPONENTLEN); 21050Sstevel@tonic-gate bootdev_newaddr[MAXCOMPONENTLEN - 1] = '\0'; 21060Sstevel@tonic-gate } else { 21070Sstevel@tonic-gate quickexit = 1; 21080Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 21090Sstevel@tonic-gate kmem_free(bp, bplen); 21100Sstevel@tonic-gate return (rv); 21110Sstevel@tonic-gate } 21120Sstevel@tonic-gate 21130Sstevel@tonic-gate /* 21140Sstevel@tonic-gate * Determine fallback name_addr 21150Sstevel@tonic-gate * 21160Sstevel@tonic-gate * 10/3/96 - Also save fallback module name because it 21170Sstevel@tonic-gate * might actually be different than the current module 21180Sstevel@tonic-gate * name. E.G., ISA pnp drivers have new names. 21190Sstevel@tonic-gate * 21200Sstevel@tonic-gate * bootpath assumed to be of the form /bus/module@name_addr 21210Sstevel@tonic-gate */ 21220Sstevel@tonic-gate addrp = NULL; 21230Sstevel@tonic-gate if (busp = strchr(bp, '/')) { 21240Sstevel@tonic-gate if (modp = strchr(busp + 1, '/')) { 21250Sstevel@tonic-gate if (atp = strchr(modp + 1, '@')) { 21260Sstevel@tonic-gate *atp = '\0'; 21270Sstevel@tonic-gate addrp = atp + 1; 21280Sstevel@tonic-gate if (eoaddrp = strchr(addrp, '/')) 21290Sstevel@tonic-gate *eoaddrp = '\0'; 21300Sstevel@tonic-gate } 21310Sstevel@tonic-gate } 21320Sstevel@tonic-gate } 21330Sstevel@tonic-gate 21340Sstevel@tonic-gate if (modp && addrp) { 21350Sstevel@tonic-gate (void) strncpy(bootdev_oldmod, modp + 1, 21360Sstevel@tonic-gate MAXCOMPONENTLEN); 21370Sstevel@tonic-gate bootdev_module[MAXCOMPONENTLEN - 1] = '\0'; 21380Sstevel@tonic-gate 21390Sstevel@tonic-gate (void) strncpy(bootdev_oldaddr, addrp, MAXCOMPONENTLEN); 21400Sstevel@tonic-gate bootdev_oldaddr[MAXCOMPONENTLEN - 1] = '\0'; 21410Sstevel@tonic-gate } 21420Sstevel@tonic-gate 21430Sstevel@tonic-gate /* Free up the bootpath storage now that we're done with it. */ 21440Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 21450Sstevel@tonic-gate kmem_free(bp, bplen); 21460Sstevel@tonic-gate 21470Sstevel@tonic-gate if (bootdev_oldaddr[0] == '\0') { 21480Sstevel@tonic-gate quickexit = 1; 21490Sstevel@tonic-gate return (rv); 21500Sstevel@tonic-gate } 21510Sstevel@tonic-gate } 21520Sstevel@tonic-gate 21530Sstevel@tonic-gate if (((lkupname = ddi_get_name(cdip)) != NULL) && 21540Sstevel@tonic-gate (strcmp(bootdev_module, lkupname) == 0 || 21550Sstevel@tonic-gate strcmp(bootdev_oldmod, lkupname) == 0) && 21560Sstevel@tonic-gate ((ddi_getprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 21570Sstevel@tonic-gate "ignore-hardware-nodes", -1) != -1) || 21580Sstevel@tonic-gate ignore_hardware_nodes) && 21590Sstevel@tonic-gate strcmp(bootdev_newaddr, caddr) == 0 && 21600Sstevel@tonic-gate strcmp(bootdev_oldaddr, naddr) == 0) { 21610Sstevel@tonic-gate rv = DDI_SUCCESS; 21620Sstevel@tonic-gate } 21630Sstevel@tonic-gate 21640Sstevel@tonic-gate return (rv); 21650Sstevel@tonic-gate } 21660Sstevel@tonic-gate 21670Sstevel@tonic-gate /* 21680Sstevel@tonic-gate * Perform a copy from a memory mapped device (whose devinfo pointer is devi) 21690Sstevel@tonic-gate * separately mapped at devaddr in the kernel to a kernel buffer at kaddr. 21700Sstevel@tonic-gate */ 21710Sstevel@tonic-gate /*ARGSUSED*/ 21720Sstevel@tonic-gate int 21730Sstevel@tonic-gate e_ddi_copyfromdev(dev_info_t *devi, 21740Sstevel@tonic-gate off_t off, const void *devaddr, void *kaddr, size_t len) 21750Sstevel@tonic-gate { 21760Sstevel@tonic-gate bcopy(devaddr, kaddr, len); 21770Sstevel@tonic-gate return (0); 21780Sstevel@tonic-gate } 21790Sstevel@tonic-gate 21800Sstevel@tonic-gate /* 21810Sstevel@tonic-gate * Perform a copy to a memory mapped device (whose devinfo pointer is devi) 21820Sstevel@tonic-gate * separately mapped at devaddr in the kernel from a kernel buffer at kaddr. 21830Sstevel@tonic-gate */ 21840Sstevel@tonic-gate /*ARGSUSED*/ 21850Sstevel@tonic-gate int 21860Sstevel@tonic-gate e_ddi_copytodev(dev_info_t *devi, 21870Sstevel@tonic-gate off_t off, const void *kaddr, void *devaddr, size_t len) 21880Sstevel@tonic-gate { 21890Sstevel@tonic-gate bcopy(kaddr, devaddr, len); 21900Sstevel@tonic-gate return (0); 21910Sstevel@tonic-gate } 21920Sstevel@tonic-gate 21930Sstevel@tonic-gate 21940Sstevel@tonic-gate static int 21950Sstevel@tonic-gate poke_mem(peekpoke_ctlops_t *in_args) 21960Sstevel@tonic-gate { 21970Sstevel@tonic-gate int err = DDI_SUCCESS; 21980Sstevel@tonic-gate on_trap_data_t otd; 21990Sstevel@tonic-gate 22000Sstevel@tonic-gate /* Set up protected environment. */ 22010Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 22020Sstevel@tonic-gate switch (in_args->size) { 22030Sstevel@tonic-gate case sizeof (uint8_t): 22040Sstevel@tonic-gate *(uint8_t *)(in_args->dev_addr) = 22050Sstevel@tonic-gate *(uint8_t *)in_args->host_addr; 22060Sstevel@tonic-gate break; 22070Sstevel@tonic-gate 22080Sstevel@tonic-gate case sizeof (uint16_t): 22090Sstevel@tonic-gate *(uint16_t *)(in_args->dev_addr) = 22100Sstevel@tonic-gate *(uint16_t *)in_args->host_addr; 22110Sstevel@tonic-gate break; 22120Sstevel@tonic-gate 22130Sstevel@tonic-gate case sizeof (uint32_t): 22140Sstevel@tonic-gate *(uint32_t *)(in_args->dev_addr) = 22150Sstevel@tonic-gate *(uint32_t *)in_args->host_addr; 22160Sstevel@tonic-gate break; 22170Sstevel@tonic-gate 22180Sstevel@tonic-gate case sizeof (uint64_t): 22190Sstevel@tonic-gate *(uint64_t *)(in_args->dev_addr) = 22200Sstevel@tonic-gate *(uint64_t *)in_args->host_addr; 22210Sstevel@tonic-gate break; 22220Sstevel@tonic-gate 22230Sstevel@tonic-gate default: 22240Sstevel@tonic-gate err = DDI_FAILURE; 22250Sstevel@tonic-gate break; 22260Sstevel@tonic-gate } 22270Sstevel@tonic-gate } else 22280Sstevel@tonic-gate err = DDI_FAILURE; 22290Sstevel@tonic-gate 22300Sstevel@tonic-gate /* Take down protected environment. */ 22310Sstevel@tonic-gate no_trap(); 22320Sstevel@tonic-gate 22330Sstevel@tonic-gate return (err); 22340Sstevel@tonic-gate } 22350Sstevel@tonic-gate 22360Sstevel@tonic-gate 22370Sstevel@tonic-gate static int 22380Sstevel@tonic-gate peek_mem(peekpoke_ctlops_t *in_args) 22390Sstevel@tonic-gate { 22400Sstevel@tonic-gate int err = DDI_SUCCESS; 22410Sstevel@tonic-gate on_trap_data_t otd; 22420Sstevel@tonic-gate 22430Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 22440Sstevel@tonic-gate switch (in_args->size) { 22450Sstevel@tonic-gate case sizeof (uint8_t): 22460Sstevel@tonic-gate *(uint8_t *)in_args->host_addr = 22470Sstevel@tonic-gate *(uint8_t *)in_args->dev_addr; 22480Sstevel@tonic-gate break; 22490Sstevel@tonic-gate 22500Sstevel@tonic-gate case sizeof (uint16_t): 22510Sstevel@tonic-gate *(uint16_t *)in_args->host_addr = 22520Sstevel@tonic-gate *(uint16_t *)in_args->dev_addr; 22530Sstevel@tonic-gate break; 22540Sstevel@tonic-gate 22550Sstevel@tonic-gate case sizeof (uint32_t): 22560Sstevel@tonic-gate *(uint32_t *)in_args->host_addr = 22570Sstevel@tonic-gate *(uint32_t *)in_args->dev_addr; 22580Sstevel@tonic-gate break; 22590Sstevel@tonic-gate 22600Sstevel@tonic-gate case sizeof (uint64_t): 22610Sstevel@tonic-gate *(uint64_t *)in_args->host_addr = 22620Sstevel@tonic-gate *(uint64_t *)in_args->dev_addr; 22630Sstevel@tonic-gate break; 22640Sstevel@tonic-gate 22650Sstevel@tonic-gate default: 22660Sstevel@tonic-gate err = DDI_FAILURE; 22670Sstevel@tonic-gate break; 22680Sstevel@tonic-gate } 22690Sstevel@tonic-gate } else 22700Sstevel@tonic-gate err = DDI_FAILURE; 22710Sstevel@tonic-gate 22720Sstevel@tonic-gate no_trap(); 22730Sstevel@tonic-gate return (err); 22740Sstevel@tonic-gate } 22750Sstevel@tonic-gate 22760Sstevel@tonic-gate 22770Sstevel@tonic-gate /* 22780Sstevel@tonic-gate * This is called only to process peek/poke when the DIP is NULL. 22790Sstevel@tonic-gate * Assume that this is for memory, as nexi take care of device safe accesses. 22800Sstevel@tonic-gate */ 22810Sstevel@tonic-gate int 22820Sstevel@tonic-gate peekpoke_mem(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args) 22830Sstevel@tonic-gate { 22840Sstevel@tonic-gate return (cmd == DDI_CTLOPS_PEEK ? peek_mem(in_args) : poke_mem(in_args)); 22850Sstevel@tonic-gate } 22860Sstevel@tonic-gate 22871865Sdilpreet /* 22881865Sdilpreet * we've just done a cautious put/get. Check if it was successful by 22891865Sdilpreet * calling pci_ereport_post() on all puts and for any gets that return -1 22901865Sdilpreet */ 22911865Sdilpreet static int 22921865Sdilpreet pci_peekpoke_check_fma(dev_info_t *dip, void *arg, ddi_ctl_enum_t ctlop) 22931865Sdilpreet { 22941865Sdilpreet int rval = DDI_SUCCESS; 22951865Sdilpreet peekpoke_ctlops_t *in_args = (peekpoke_ctlops_t *)arg; 22961865Sdilpreet ddi_fm_error_t de; 22971865Sdilpreet ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 22981865Sdilpreet ddi_acc_hdl_t *hdlp = (ddi_acc_hdl_t *)in_args->handle; 22991865Sdilpreet int check_err = 0; 23001865Sdilpreet int repcount = in_args->repcount; 23011865Sdilpreet 23021865Sdilpreet if (ctlop == DDI_CTLOPS_PEEK && 23031865Sdilpreet hdlp->ah_acc.devacc_attr_access != DDI_CAUTIOUS_ACC) { 23041865Sdilpreet for (; repcount; repcount--) { 23051865Sdilpreet switch (in_args->size) { 23061865Sdilpreet case sizeof (uint8_t): 23071865Sdilpreet if (*(uint8_t *)in_args->host_addr == 0xff) 23081865Sdilpreet check_err = 1; 23091865Sdilpreet break; 23101865Sdilpreet case sizeof (uint16_t): 23111865Sdilpreet if (*(uint16_t *)in_args->host_addr == 0xffff) 23121865Sdilpreet check_err = 1; 23131865Sdilpreet break; 23141865Sdilpreet case sizeof (uint32_t): 23151865Sdilpreet if (*(uint32_t *)in_args->host_addr == 23161865Sdilpreet 0xffffffff) 23171865Sdilpreet check_err = 1; 23181865Sdilpreet break; 23191865Sdilpreet case sizeof (uint64_t): 23201865Sdilpreet if (*(uint64_t *)in_args->host_addr == 23211865Sdilpreet 0xffffffffffffffff) 23221865Sdilpreet check_err = 1; 23231865Sdilpreet break; 23241865Sdilpreet } 23251865Sdilpreet } 23261865Sdilpreet if (check_err == 0) 23271865Sdilpreet return (DDI_SUCCESS); 23281865Sdilpreet } 23291865Sdilpreet /* 23301865Sdilpreet * for a cautious put or get or a non-cautious get that returned -1 call 23311865Sdilpreet * io framework to see if there really was an error 23321865Sdilpreet */ 23331865Sdilpreet bzero(&de, sizeof (ddi_fm_error_t)); 23341865Sdilpreet de.fme_ena = fm_ena_generate(0, FM_ENA_FMT1); 23351865Sdilpreet de.fme_bus_specific = (void *)in_args->dev_addr; 23361865Sdilpreet if (hdlp->ah_acc.devacc_attr_access == DDI_CAUTIOUS_ACC) { 23371865Sdilpreet de.fme_flag = DDI_FM_ERR_EXPECTED; 23381865Sdilpreet de.fme_acc_handle = in_args->handle; 23391865Sdilpreet } else if (hdlp->ah_acc.devacc_attr_access == DDI_DEFAULT_ACC) { 23401865Sdilpreet /* 23411865Sdilpreet * We only get here with DDI_DEFAULT_ACC for config space gets. 23421865Sdilpreet * Non-hardened drivers may be probing the hardware and 23431865Sdilpreet * expecting -1 returned. So need to treat errors on 23441865Sdilpreet * DDI_DEFAULT_ACC as DDI_FM_ERR_EXPECTED. 23451865Sdilpreet */ 23461865Sdilpreet de.fme_flag = DDI_FM_ERR_EXPECTED; 23471865Sdilpreet de.fme_acc_handle = in_args->handle; 23481865Sdilpreet } else { 23491865Sdilpreet /* 23501865Sdilpreet * Hardened driver doing protected accesses shouldn't 23511865Sdilpreet * get errors unless there's a hardware problem. Treat 23521865Sdilpreet * as nonfatal if there's an error, but set UNEXPECTED 23531865Sdilpreet * so we raise ereports on any errors and potentially 23541865Sdilpreet * fault the device 23551865Sdilpreet */ 23561865Sdilpreet de.fme_flag = DDI_FM_ERR_UNEXPECTED; 23571865Sdilpreet } 23581865Sdilpreet pci_ereport_post(dip, &de, NULL); 23591865Sdilpreet if (hdlp->ah_acc.devacc_attr_access != DDI_DEFAULT_ACC && 23601865Sdilpreet de.fme_status != DDI_FM_OK) { 23611865Sdilpreet ndi_err_t *errp = (ndi_err_t *)hp->ahi_err; 23621865Sdilpreet rval = DDI_FAILURE; 23631865Sdilpreet errp->err_ena = de.fme_ena; 23641865Sdilpreet errp->err_expected = de.fme_flag; 23651865Sdilpreet errp->err_status = DDI_FM_NONFATAL; 23661865Sdilpreet } 23671865Sdilpreet return (rval); 23681865Sdilpreet } 23691865Sdilpreet 23701865Sdilpreet /* 23711865Sdilpreet * pci_peekpoke_check_nofma() is for when an error occurs on a register access 23721865Sdilpreet * during pci_ereport_post(). We can't call pci_ereport_post() again or we'd 23731865Sdilpreet * recurse, so assume all puts are OK and gets have failed if they return -1 23741865Sdilpreet */ 23751865Sdilpreet static int 23761865Sdilpreet pci_peekpoke_check_nofma(void *arg, ddi_ctl_enum_t ctlop) 23771865Sdilpreet { 23781865Sdilpreet int rval = DDI_SUCCESS; 23791865Sdilpreet peekpoke_ctlops_t *in_args = (peekpoke_ctlops_t *)arg; 23801865Sdilpreet ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 23811865Sdilpreet ddi_acc_hdl_t *hdlp = (ddi_acc_hdl_t *)in_args->handle; 23821865Sdilpreet int repcount = in_args->repcount; 23831865Sdilpreet 23841865Sdilpreet if (ctlop == DDI_CTLOPS_POKE) 23851865Sdilpreet return (rval); 23861865Sdilpreet 23871865Sdilpreet for (; repcount; repcount--) { 23881865Sdilpreet switch (in_args->size) { 23891865Sdilpreet case sizeof (uint8_t): 23901865Sdilpreet if (*(uint8_t *)in_args->host_addr == 0xff) 23911865Sdilpreet rval = DDI_FAILURE; 23921865Sdilpreet break; 23931865Sdilpreet case sizeof (uint16_t): 23941865Sdilpreet if (*(uint16_t *)in_args->host_addr == 0xffff) 23951865Sdilpreet rval = DDI_FAILURE; 23961865Sdilpreet break; 23971865Sdilpreet case sizeof (uint32_t): 23981865Sdilpreet if (*(uint32_t *)in_args->host_addr == 0xffffffff) 23991865Sdilpreet rval = DDI_FAILURE; 24001865Sdilpreet break; 24011865Sdilpreet case sizeof (uint64_t): 24021865Sdilpreet if (*(uint64_t *)in_args->host_addr == 24031865Sdilpreet 0xffffffffffffffff) 24041865Sdilpreet rval = DDI_FAILURE; 24051865Sdilpreet break; 24061865Sdilpreet } 24071865Sdilpreet } 24081865Sdilpreet if (hdlp->ah_acc.devacc_attr_access != DDI_DEFAULT_ACC && 24091865Sdilpreet rval == DDI_FAILURE) { 24101865Sdilpreet ndi_err_t *errp = (ndi_err_t *)hp->ahi_err; 24111865Sdilpreet errp->err_ena = fm_ena_generate(0, FM_ENA_FMT1); 24121865Sdilpreet errp->err_expected = DDI_FM_ERR_UNEXPECTED; 24131865Sdilpreet errp->err_status = DDI_FM_NONFATAL; 24141865Sdilpreet } 24151865Sdilpreet return (rval); 24161865Sdilpreet } 24171865Sdilpreet 24181865Sdilpreet int 24191865Sdilpreet pci_peekpoke_check(dev_info_t *dip, dev_info_t *rdip, 24201865Sdilpreet ddi_ctl_enum_t ctlop, void *arg, void *result, 24211865Sdilpreet int (*handler)(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, 24221865Sdilpreet void *), kmutex_t *err_mutexp, kmutex_t *peek_poke_mutexp) 24231865Sdilpreet { 24241865Sdilpreet int rval; 24251865Sdilpreet peekpoke_ctlops_t *in_args = (peekpoke_ctlops_t *)arg; 24261865Sdilpreet ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 24271865Sdilpreet 24281865Sdilpreet if (hp->ahi_acc_attr & DDI_ACCATTR_CONFIG_SPACE) { 24291865Sdilpreet if (!mutex_tryenter(err_mutexp)) { 24301865Sdilpreet /* 24311865Sdilpreet * As this may be a recursive call from within 24321865Sdilpreet * pci_ereport_post() we can't wait for the mutexes. 24331865Sdilpreet * Fortunately we know someone is already calling 24341865Sdilpreet * pci_ereport_post() which will handle the error bits 24351865Sdilpreet * for us, and as this is a config space access we can 24361865Sdilpreet * just do the access and check return value for -1 24371865Sdilpreet * using pci_peekpoke_check_nofma(). 24381865Sdilpreet */ 24391865Sdilpreet rval = handler(dip, rdip, ctlop, arg, result); 24401865Sdilpreet if (rval == DDI_SUCCESS) 24411865Sdilpreet rval = pci_peekpoke_check_nofma(arg, ctlop); 24421865Sdilpreet return (rval); 24431865Sdilpreet } 24441865Sdilpreet /* 24451865Sdilpreet * This can't be a recursive call. Drop the err_mutex and get 24461865Sdilpreet * both mutexes in the right order. If an error hasn't already 24471865Sdilpreet * been detected by the ontrap code, use pci_peekpoke_check_fma 24481865Sdilpreet * which will call pci_ereport_post() to check error status. 24491865Sdilpreet */ 24501865Sdilpreet mutex_exit(err_mutexp); 24511865Sdilpreet } 24521865Sdilpreet mutex_enter(peek_poke_mutexp); 24531865Sdilpreet rval = handler(dip, rdip, ctlop, arg, result); 24541865Sdilpreet if (rval == DDI_SUCCESS) { 24551865Sdilpreet mutex_enter(err_mutexp); 24561865Sdilpreet rval = pci_peekpoke_check_fma(dip, arg, ctlop); 24571865Sdilpreet mutex_exit(err_mutexp); 24581865Sdilpreet } 24591865Sdilpreet mutex_exit(peek_poke_mutexp); 24601865Sdilpreet return (rval); 24611865Sdilpreet } 24621865Sdilpreet 24630Sstevel@tonic-gate void 24640Sstevel@tonic-gate impl_setup_ddi(void) 24650Sstevel@tonic-gate { 24660Sstevel@tonic-gate dev_info_t *xdip, *isa_dip; 24670Sstevel@tonic-gate rd_existing_t rd_mem_prop; 24680Sstevel@tonic-gate int err; 24690Sstevel@tonic-gate 24700Sstevel@tonic-gate ndi_devi_alloc_sleep(ddi_root_node(), "ramdisk", 2471789Sahrens (pnode_t)DEVI_SID_NODEID, &xdip); 24720Sstevel@tonic-gate 24730Sstevel@tonic-gate (void) BOP_GETPROP(bootops, 24740Sstevel@tonic-gate "ramdisk_start", (void *)&ramdisk_start); 24750Sstevel@tonic-gate (void) BOP_GETPROP(bootops, 24760Sstevel@tonic-gate "ramdisk_end", (void *)&ramdisk_end); 24770Sstevel@tonic-gate 24780Sstevel@tonic-gate rd_mem_prop.phys = ramdisk_start; 24790Sstevel@tonic-gate rd_mem_prop.size = ramdisk_end - ramdisk_start + 1; 24800Sstevel@tonic-gate 24810Sstevel@tonic-gate (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE, xdip, 24820Sstevel@tonic-gate RD_EXISTING_PROP_NAME, (uchar_t *)&rd_mem_prop, 24830Sstevel@tonic-gate sizeof (rd_mem_prop)); 24840Sstevel@tonic-gate err = ndi_devi_bind_driver(xdip, 0); 24850Sstevel@tonic-gate ASSERT(err == 0); 24860Sstevel@tonic-gate 24870Sstevel@tonic-gate /* isa node */ 24880Sstevel@tonic-gate ndi_devi_alloc_sleep(ddi_root_node(), "isa", 2489789Sahrens (pnode_t)DEVI_SID_NODEID, &isa_dip); 24900Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, isa_dip, 24910Sstevel@tonic-gate "device_type", "isa"); 24920Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, isa_dip, 24930Sstevel@tonic-gate "bus-type", "isa"); 24940Sstevel@tonic-gate (void) ndi_devi_bind_driver(isa_dip, 0); 24950Sstevel@tonic-gate 24960Sstevel@tonic-gate /* 24970Sstevel@tonic-gate * Read in the properties from the boot. 24980Sstevel@tonic-gate */ 24990Sstevel@tonic-gate get_boot_properties(); 25000Sstevel@tonic-gate 25010Sstevel@tonic-gate /* do bus dependent probes. */ 25020Sstevel@tonic-gate impl_bus_initialprobe(); 25030Sstevel@tonic-gate 25040Sstevel@tonic-gate /* not framebuffer should be enumerated, if present */ 25050Sstevel@tonic-gate get_vga_properties(); 25060Sstevel@tonic-gate } 25070Sstevel@tonic-gate 25080Sstevel@tonic-gate dev_t 25090Sstevel@tonic-gate getrootdev(void) 25100Sstevel@tonic-gate { 25110Sstevel@tonic-gate /* 25120Sstevel@tonic-gate * Precedence given to rootdev if set in /etc/system 25130Sstevel@tonic-gate */ 25140Sstevel@tonic-gate if (root_is_svm) { 25150Sstevel@tonic-gate return (ddi_pathname_to_dev_t(svm_bootpath)); 25160Sstevel@tonic-gate } 25170Sstevel@tonic-gate 25180Sstevel@tonic-gate /* 25190Sstevel@tonic-gate * Usually rootfs.bo_name is initialized by the 25200Sstevel@tonic-gate * the bootpath property from bootenv.rc, but 25210Sstevel@tonic-gate * defaults to "/ramdisk:a" otherwise. 25220Sstevel@tonic-gate */ 25230Sstevel@tonic-gate return (ddi_pathname_to_dev_t(rootfs.bo_name)); 25240Sstevel@tonic-gate } 25250Sstevel@tonic-gate 25260Sstevel@tonic-gate static struct bus_probe { 25270Sstevel@tonic-gate struct bus_probe *next; 25280Sstevel@tonic-gate void (*probe)(int); 25290Sstevel@tonic-gate } *bus_probes; 25300Sstevel@tonic-gate 25310Sstevel@tonic-gate void 25320Sstevel@tonic-gate impl_bus_add_probe(void (*func)(int)) 25330Sstevel@tonic-gate { 25340Sstevel@tonic-gate struct bus_probe *probe; 25350Sstevel@tonic-gate 25360Sstevel@tonic-gate probe = kmem_alloc(sizeof (*probe), KM_SLEEP); 25370Sstevel@tonic-gate probe->next = bus_probes; 25380Sstevel@tonic-gate probe->probe = func; 25390Sstevel@tonic-gate bus_probes = probe; 25400Sstevel@tonic-gate } 25410Sstevel@tonic-gate 25420Sstevel@tonic-gate /*ARGSUSED*/ 25430Sstevel@tonic-gate void 25440Sstevel@tonic-gate impl_bus_delete_probe(void (*func)(int)) 25450Sstevel@tonic-gate { 25460Sstevel@tonic-gate struct bus_probe *prev = NULL; 25470Sstevel@tonic-gate struct bus_probe *probe = bus_probes; 25480Sstevel@tonic-gate 25490Sstevel@tonic-gate while (probe) { 25500Sstevel@tonic-gate if (probe->probe == func) 25510Sstevel@tonic-gate break; 25520Sstevel@tonic-gate prev = probe; 25530Sstevel@tonic-gate probe = probe->next; 25540Sstevel@tonic-gate } 25550Sstevel@tonic-gate 25560Sstevel@tonic-gate if (probe == NULL) 25570Sstevel@tonic-gate return; 25580Sstevel@tonic-gate 25590Sstevel@tonic-gate if (prev) 25600Sstevel@tonic-gate prev->next = probe->next; 25610Sstevel@tonic-gate else 25620Sstevel@tonic-gate bus_probes = probe->next; 25630Sstevel@tonic-gate 25640Sstevel@tonic-gate kmem_free(probe, sizeof (struct bus_probe)); 25650Sstevel@tonic-gate } 25660Sstevel@tonic-gate 25670Sstevel@tonic-gate /* 25680Sstevel@tonic-gate * impl_bus_initialprobe 25690Sstevel@tonic-gate * Modload the prom simulator, then let it probe to verify existence 25700Sstevel@tonic-gate * and type of PCI support. 25710Sstevel@tonic-gate */ 25720Sstevel@tonic-gate static void 25730Sstevel@tonic-gate impl_bus_initialprobe(void) 25740Sstevel@tonic-gate { 25750Sstevel@tonic-gate struct bus_probe *probe; 25760Sstevel@tonic-gate 25770Sstevel@tonic-gate /* load modules to install bus probes */ 25780Sstevel@tonic-gate if (modload("misc", "pci_autoconfig") < 0) { 25790Sstevel@tonic-gate cmn_err(CE_PANIC, "failed to load misc/pci_autoconfig"); 25800Sstevel@tonic-gate } 25810Sstevel@tonic-gate 25820Sstevel@tonic-gate probe = bus_probes; 25830Sstevel@tonic-gate while (probe) { 25840Sstevel@tonic-gate /* run the probe function */ 25850Sstevel@tonic-gate (*probe->probe)(0); 25860Sstevel@tonic-gate probe = probe->next; 25870Sstevel@tonic-gate } 25880Sstevel@tonic-gate } 25890Sstevel@tonic-gate 25900Sstevel@tonic-gate /* 25910Sstevel@tonic-gate * impl_bus_reprobe 25920Sstevel@tonic-gate * Reprogram devices not set up by firmware. 25930Sstevel@tonic-gate */ 25940Sstevel@tonic-gate static void 25950Sstevel@tonic-gate impl_bus_reprobe(void) 25960Sstevel@tonic-gate { 25970Sstevel@tonic-gate struct bus_probe *probe; 25980Sstevel@tonic-gate 25990Sstevel@tonic-gate probe = bus_probes; 26000Sstevel@tonic-gate while (probe) { 26010Sstevel@tonic-gate /* run the probe function */ 26020Sstevel@tonic-gate (*probe->probe)(1); 26030Sstevel@tonic-gate probe = probe->next; 26040Sstevel@tonic-gate } 26050Sstevel@tonic-gate } 26061865Sdilpreet 26071865Sdilpreet 26081865Sdilpreet /* 26091865Sdilpreet * The following functions ready a cautious request to go up to the nexus 26101865Sdilpreet * driver. It is up to the nexus driver to decide how to process the request. 26111865Sdilpreet * It may choose to call i_ddi_do_caut_get/put in this file, or do it 26121865Sdilpreet * differently. 26131865Sdilpreet */ 26141865Sdilpreet 26151865Sdilpreet static void 26161865Sdilpreet i_ddi_caut_getput_ctlops(ddi_acc_impl_t *hp, uint64_t host_addr, 26171865Sdilpreet uint64_t dev_addr, size_t size, size_t repcount, uint_t flags, 26181865Sdilpreet ddi_ctl_enum_t cmd) 26191865Sdilpreet { 26201865Sdilpreet peekpoke_ctlops_t cautacc_ctlops_arg; 26211865Sdilpreet 26221865Sdilpreet cautacc_ctlops_arg.size = size; 26231865Sdilpreet cautacc_ctlops_arg.dev_addr = dev_addr; 26241865Sdilpreet cautacc_ctlops_arg.host_addr = host_addr; 26251865Sdilpreet cautacc_ctlops_arg.handle = (ddi_acc_handle_t)hp; 26261865Sdilpreet cautacc_ctlops_arg.repcount = repcount; 26271865Sdilpreet cautacc_ctlops_arg.flags = flags; 26281865Sdilpreet 26291865Sdilpreet (void) ddi_ctlops(hp->ahi_common.ah_dip, hp->ahi_common.ah_dip, cmd, 26301865Sdilpreet &cautacc_ctlops_arg, NULL); 26311865Sdilpreet } 26321865Sdilpreet 26331865Sdilpreet uint8_t 26341865Sdilpreet i_ddi_caut_get8(ddi_acc_impl_t *hp, uint8_t *addr) 26351865Sdilpreet { 26361865Sdilpreet uint8_t value; 26371865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 26381865Sdilpreet sizeof (uint8_t), 1, 0, DDI_CTLOPS_PEEK); 26391865Sdilpreet 26401865Sdilpreet return (value); 26411865Sdilpreet } 26421865Sdilpreet 26431865Sdilpreet uint16_t 26441865Sdilpreet i_ddi_caut_get16(ddi_acc_impl_t *hp, uint16_t *addr) 26451865Sdilpreet { 26461865Sdilpreet uint16_t value; 26471865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 26481865Sdilpreet sizeof (uint16_t), 1, 0, DDI_CTLOPS_PEEK); 26491865Sdilpreet 26501865Sdilpreet return (value); 26511865Sdilpreet } 26521865Sdilpreet 26531865Sdilpreet uint32_t 26541865Sdilpreet i_ddi_caut_get32(ddi_acc_impl_t *hp, uint32_t *addr) 26551865Sdilpreet { 26561865Sdilpreet uint32_t value; 26571865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 26581865Sdilpreet sizeof (uint32_t), 1, 0, DDI_CTLOPS_PEEK); 26591865Sdilpreet 26601865Sdilpreet return (value); 26611865Sdilpreet } 26621865Sdilpreet 26631865Sdilpreet uint64_t 26641865Sdilpreet i_ddi_caut_get64(ddi_acc_impl_t *hp, uint64_t *addr) 26651865Sdilpreet { 26661865Sdilpreet uint64_t value; 26671865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 26681865Sdilpreet sizeof (uint64_t), 1, 0, DDI_CTLOPS_PEEK); 26691865Sdilpreet 26701865Sdilpreet return (value); 26711865Sdilpreet } 26721865Sdilpreet 26731865Sdilpreet void 26741865Sdilpreet i_ddi_caut_put8(ddi_acc_impl_t *hp, uint8_t *addr, uint8_t value) 26751865Sdilpreet { 26761865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 26771865Sdilpreet sizeof (uint8_t), 1, 0, DDI_CTLOPS_POKE); 26781865Sdilpreet } 26791865Sdilpreet 26801865Sdilpreet void 26811865Sdilpreet i_ddi_caut_put16(ddi_acc_impl_t *hp, uint16_t *addr, uint16_t value) 26821865Sdilpreet { 26831865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 26841865Sdilpreet sizeof (uint16_t), 1, 0, DDI_CTLOPS_POKE); 26851865Sdilpreet } 26861865Sdilpreet 26871865Sdilpreet void 26881865Sdilpreet i_ddi_caut_put32(ddi_acc_impl_t *hp, uint32_t *addr, uint32_t value) 26891865Sdilpreet { 26901865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 26911865Sdilpreet sizeof (uint32_t), 1, 0, DDI_CTLOPS_POKE); 26921865Sdilpreet } 26931865Sdilpreet 26941865Sdilpreet void 26951865Sdilpreet i_ddi_caut_put64(ddi_acc_impl_t *hp, uint64_t *addr, uint64_t value) 26961865Sdilpreet { 26971865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 26981865Sdilpreet sizeof (uint64_t), 1, 0, DDI_CTLOPS_POKE); 26991865Sdilpreet } 27001865Sdilpreet 27011865Sdilpreet void 27021865Sdilpreet i_ddi_caut_rep_get8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr, 27031865Sdilpreet size_t repcount, uint_t flags) 27041865Sdilpreet { 27051865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 27061865Sdilpreet sizeof (uint8_t), repcount, flags, DDI_CTLOPS_PEEK); 27071865Sdilpreet } 27081865Sdilpreet 27091865Sdilpreet void 27101865Sdilpreet i_ddi_caut_rep_get16(ddi_acc_impl_t *hp, uint16_t *host_addr, 27111865Sdilpreet uint16_t *dev_addr, size_t repcount, uint_t flags) 27121865Sdilpreet { 27131865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 27141865Sdilpreet sizeof (uint16_t), repcount, flags, DDI_CTLOPS_PEEK); 27151865Sdilpreet } 27161865Sdilpreet 27171865Sdilpreet void 27181865Sdilpreet i_ddi_caut_rep_get32(ddi_acc_impl_t *hp, uint32_t *host_addr, 27191865Sdilpreet uint32_t *dev_addr, size_t repcount, uint_t flags) 27201865Sdilpreet { 27211865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 27221865Sdilpreet sizeof (uint32_t), repcount, flags, DDI_CTLOPS_PEEK); 27231865Sdilpreet } 27241865Sdilpreet 27251865Sdilpreet void 27261865Sdilpreet i_ddi_caut_rep_get64(ddi_acc_impl_t *hp, uint64_t *host_addr, 27271865Sdilpreet uint64_t *dev_addr, size_t repcount, uint_t flags) 27281865Sdilpreet { 27291865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 27301865Sdilpreet sizeof (uint64_t), repcount, flags, DDI_CTLOPS_PEEK); 27311865Sdilpreet } 27321865Sdilpreet 27331865Sdilpreet void 27341865Sdilpreet i_ddi_caut_rep_put8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr, 27351865Sdilpreet size_t repcount, uint_t flags) 27361865Sdilpreet { 27371865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 27381865Sdilpreet sizeof (uint8_t), repcount, flags, DDI_CTLOPS_POKE); 27391865Sdilpreet } 27401865Sdilpreet 27411865Sdilpreet void 27421865Sdilpreet i_ddi_caut_rep_put16(ddi_acc_impl_t *hp, uint16_t *host_addr, 27431865Sdilpreet uint16_t *dev_addr, size_t repcount, uint_t flags) 27441865Sdilpreet { 27451865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 27461865Sdilpreet sizeof (uint16_t), repcount, flags, DDI_CTLOPS_POKE); 27471865Sdilpreet } 27481865Sdilpreet 27491865Sdilpreet void 27501865Sdilpreet i_ddi_caut_rep_put32(ddi_acc_impl_t *hp, uint32_t *host_addr, 27511865Sdilpreet uint32_t *dev_addr, size_t repcount, uint_t flags) 27521865Sdilpreet { 27531865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 27541865Sdilpreet sizeof (uint32_t), repcount, flags, DDI_CTLOPS_POKE); 27551865Sdilpreet } 27561865Sdilpreet 27571865Sdilpreet void 27581865Sdilpreet i_ddi_caut_rep_put64(ddi_acc_impl_t *hp, uint64_t *host_addr, 27591865Sdilpreet uint64_t *dev_addr, size_t repcount, uint_t flags) 27601865Sdilpreet { 27611865Sdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 27621865Sdilpreet sizeof (uint64_t), repcount, flags, DDI_CTLOPS_POKE); 27631865Sdilpreet } 2764