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 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 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> 590Sstevel@tonic-gate #include <sys/ramdisk.h> 600Sstevel@tonic-gate #include <sys/sunndi.h> 610Sstevel@tonic-gate #include <sys/vmem.h> 620Sstevel@tonic-gate #include <sys/pci_impl.h> 630Sstevel@tonic-gate 640Sstevel@tonic-gate /* 650Sstevel@tonic-gate * DDI Boot Configuration 660Sstevel@tonic-gate */ 670Sstevel@tonic-gate 680Sstevel@tonic-gate /* 690Sstevel@tonic-gate * No platform drivers on this platform 700Sstevel@tonic-gate */ 710Sstevel@tonic-gate char *platform_module_list[] = { 720Sstevel@tonic-gate (char *)0 730Sstevel@tonic-gate }; 740Sstevel@tonic-gate 750Sstevel@tonic-gate /* pci bus resource maps */ 760Sstevel@tonic-gate struct pci_bus_resource *pci_bus_res; 770Sstevel@tonic-gate 780Sstevel@tonic-gate extern int root_is_svm; 790Sstevel@tonic-gate uint64_t ramdisk_start, ramdisk_end; 800Sstevel@tonic-gate 810Sstevel@tonic-gate /* 820Sstevel@tonic-gate * Forward declarations 830Sstevel@tonic-gate */ 840Sstevel@tonic-gate static int getlongprop_buf(); 850Sstevel@tonic-gate static void get_boot_properties(void); 860Sstevel@tonic-gate static void impl_bus_initialprobe(void); 870Sstevel@tonic-gate static void impl_bus_reprobe(void); 880Sstevel@tonic-gate 890Sstevel@tonic-gate static int poke_mem(peekpoke_ctlops_t *in_args); 900Sstevel@tonic-gate static int peek_mem(peekpoke_ctlops_t *in_args); 910Sstevel@tonic-gate 920Sstevel@tonic-gate #define CTGENTRIES 15 930Sstevel@tonic-gate 940Sstevel@tonic-gate static struct ctgas { 950Sstevel@tonic-gate struct ctgas *ctg_next; 960Sstevel@tonic-gate int ctg_index; 970Sstevel@tonic-gate void *ctg_addr[CTGENTRIES]; 980Sstevel@tonic-gate size_t ctg_size[CTGENTRIES]; 990Sstevel@tonic-gate } ctglist; 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate static kmutex_t ctgmutex; 1020Sstevel@tonic-gate #define CTGLOCK() mutex_enter(&ctgmutex) 1030Sstevel@tonic-gate #define CTGUNLOCK() mutex_exit(&ctgmutex) 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* 1060Sstevel@tonic-gate * Minimum pfn value of page_t's put on the free list. This is to simplify 1070Sstevel@tonic-gate * support of ddi dma memory requests which specify small, non-zero addr_lo 1080Sstevel@tonic-gate * values. 1090Sstevel@tonic-gate * 1100Sstevel@tonic-gate * The default value of 2, which corresponds to the only known non-zero addr_lo 1110Sstevel@tonic-gate * value used, means a single page will be sacrificed (pfn typically starts 1120Sstevel@tonic-gate * at 1). ddiphysmin can be set to 0 to disable. It cannot be set above 0x100 1130Sstevel@tonic-gate * otherwise mp startup panics. 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate pfn_t ddiphysmin = 2; 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate static void 1180Sstevel@tonic-gate check_driver_disable(void) 1190Sstevel@tonic-gate { 1200Sstevel@tonic-gate int proplen = 128; 1210Sstevel@tonic-gate char *prop_name; 1220Sstevel@tonic-gate char *drv_name, *propval; 1230Sstevel@tonic-gate major_t major; 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate prop_name = kmem_alloc(proplen, KM_SLEEP); 1260Sstevel@tonic-gate for (major = 0; major < devcnt; major++) { 1270Sstevel@tonic-gate drv_name = ddi_major_to_name(major); 1280Sstevel@tonic-gate if (drv_name == NULL) 1290Sstevel@tonic-gate continue; 1300Sstevel@tonic-gate (void) snprintf(prop_name, proplen, "disable-%s", drv_name); 1310Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 1320Sstevel@tonic-gate DDI_PROP_DONTPASS, prop_name, &propval) == DDI_SUCCESS) { 1330Sstevel@tonic-gate if (strcmp(propval, "true") == 0) { 1340Sstevel@tonic-gate devnamesp[major].dn_flags |= DN_DRIVER_REMOVED; 1350Sstevel@tonic-gate cmn_err(CE_NOTE, "driver %s disabled", 1360Sstevel@tonic-gate drv_name); 1370Sstevel@tonic-gate } 1380Sstevel@tonic-gate ddi_prop_free(propval); 1390Sstevel@tonic-gate } 1400Sstevel@tonic-gate } 1410Sstevel@tonic-gate kmem_free(prop_name, proplen); 1420Sstevel@tonic-gate } 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate 1450Sstevel@tonic-gate /* 1460Sstevel@tonic-gate * Configure the hardware on the system. 1470Sstevel@tonic-gate * Called before the rootfs is mounted 1480Sstevel@tonic-gate */ 1490Sstevel@tonic-gate void 1500Sstevel@tonic-gate configure(void) 1510Sstevel@tonic-gate { 1520Sstevel@tonic-gate extern void i_ddi_init_root(); 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate #if defined(__i386) 1550Sstevel@tonic-gate extern int fpu_pentium_fdivbug; 1560Sstevel@tonic-gate #endif /* __i386 */ 1570Sstevel@tonic-gate extern int fpu_ignored; 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate /* 1600Sstevel@tonic-gate * Determine if an FPU is attached 1610Sstevel@tonic-gate */ 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate fpu_probe(); 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate #if defined(__i386) 1660Sstevel@tonic-gate if (fpu_pentium_fdivbug) { 1670Sstevel@tonic-gate printf("\ 1680Sstevel@tonic-gate FP hardware exhibits Pentium floating point divide problem\n"); 1690Sstevel@tonic-gate } 1700Sstevel@tonic-gate #endif /* __i386 */ 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate if (fpu_ignored) { 1730Sstevel@tonic-gate printf("FP hardware will not be used\n"); 1740Sstevel@tonic-gate } else if (!fpu_exists) { 1750Sstevel@tonic-gate printf("No FPU in configuration\n"); 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * Initialize devices on the machine. 1800Sstevel@tonic-gate * Uses configuration tree built by the PROMs to determine what 1810Sstevel@tonic-gate * is present, and builds a tree of prototype dev_info nodes 1820Sstevel@tonic-gate * corresponding to the hardware which identified itself. 1830Sstevel@tonic-gate */ 1840Sstevel@tonic-gate #if !defined(SAS) && !defined(MPSAS) 1850Sstevel@tonic-gate /* 1860Sstevel@tonic-gate * Check for disabled drivers and initialize root node. 1870Sstevel@tonic-gate */ 1880Sstevel@tonic-gate check_driver_disable(); 1890Sstevel@tonic-gate i_ddi_init_root(); 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * attach the isa nexus to get ACPI resource usage 1930Sstevel@tonic-gate * isa is "kind of" a pseudo node 1940Sstevel@tonic-gate */ 1950Sstevel@tonic-gate (void) i_ddi_attach_pseudo_node("isa"); 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate /* reprogram devices not set up by firmware (BIOS) */ 1980Sstevel@tonic-gate impl_bus_reprobe(); 1990Sstevel@tonic-gate #endif /* !SAS && !MPSAS */ 2000Sstevel@tonic-gate } 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate /* 2030Sstevel@tonic-gate * The "status" property indicates the operational status of a device. 2040Sstevel@tonic-gate * If this property is present, the value is a string indicating the 2050Sstevel@tonic-gate * status of the device as follows: 2060Sstevel@tonic-gate * 2070Sstevel@tonic-gate * "okay" operational. 2080Sstevel@tonic-gate * "disabled" not operational, but might become operational. 2090Sstevel@tonic-gate * "fail" not operational because a fault has been detected, 2100Sstevel@tonic-gate * and it is unlikely that the device will become 2110Sstevel@tonic-gate * operational without repair. no additional details 2120Sstevel@tonic-gate * are available. 2130Sstevel@tonic-gate * "fail-xxx" not operational because a fault has been detected, 2140Sstevel@tonic-gate * and it is unlikely that the device will become 2150Sstevel@tonic-gate * operational without repair. "xxx" is additional 2160Sstevel@tonic-gate * human-readable information about the particular 2170Sstevel@tonic-gate * fault condition that was detected. 2180Sstevel@tonic-gate * 2190Sstevel@tonic-gate * The absence of this property means that the operational status is 2200Sstevel@tonic-gate * unknown or okay. 2210Sstevel@tonic-gate * 2220Sstevel@tonic-gate * This routine checks the status property of the specified device node 2230Sstevel@tonic-gate * and returns 0 if the operational status indicates failure, and 1 otherwise. 2240Sstevel@tonic-gate * 2250Sstevel@tonic-gate * The property may exist on plug-in cards the existed before IEEE 1275-1994. 2260Sstevel@tonic-gate * And, in that case, the property may not even be a string. So we carefully 2270Sstevel@tonic-gate * check for the value "fail", in the beginning of the string, noting 2280Sstevel@tonic-gate * the property length. 2290Sstevel@tonic-gate */ 2300Sstevel@tonic-gate int 2310Sstevel@tonic-gate status_okay(int id, char *buf, int buflen) 2320Sstevel@tonic-gate { 2330Sstevel@tonic-gate char status_buf[OBP_MAXPROPNAME]; 2340Sstevel@tonic-gate char *bufp = buf; 2350Sstevel@tonic-gate int len = buflen; 2360Sstevel@tonic-gate int proplen; 2370Sstevel@tonic-gate static const char *status = "status"; 2380Sstevel@tonic-gate static const char *fail = "fail"; 2390Sstevel@tonic-gate int fail_len = (int)strlen(fail); 2400Sstevel@tonic-gate 2410Sstevel@tonic-gate /* 2420Sstevel@tonic-gate * Get the proplen ... if it's smaller than "fail", 2430Sstevel@tonic-gate * or doesn't exist ... then we don't care, since 2440Sstevel@tonic-gate * the value can't begin with the char string "fail". 2450Sstevel@tonic-gate * 2460Sstevel@tonic-gate * NB: proplen, if it's a string, includes the NULL in the 2470Sstevel@tonic-gate * the size of the property, and fail_len does not. 2480Sstevel@tonic-gate */ 2490Sstevel@tonic-gate proplen = prom_getproplen((dnode_t)id, (caddr_t)status); 2500Sstevel@tonic-gate if (proplen <= fail_len) /* nonexistant or uninteresting len */ 2510Sstevel@tonic-gate return (1); 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate /* 2540Sstevel@tonic-gate * if a buffer was provided, use it 2550Sstevel@tonic-gate */ 2560Sstevel@tonic-gate if ((buf == (char *)NULL) || (buflen <= 0)) { 2570Sstevel@tonic-gate bufp = status_buf; 2580Sstevel@tonic-gate len = sizeof (status_buf); 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate *bufp = (char)0; 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate /* 2630Sstevel@tonic-gate * Get the property into the buffer, to the extent of the buffer, 2640Sstevel@tonic-gate * and in case the buffer is smaller than the property size, 2650Sstevel@tonic-gate * NULL terminate the buffer. (This handles the case where 2660Sstevel@tonic-gate * a buffer was passed in and the caller wants to print the 2670Sstevel@tonic-gate * value, but the buffer was too small). 2680Sstevel@tonic-gate */ 2690Sstevel@tonic-gate (void) prom_bounded_getprop((dnode_t)id, (caddr_t)status, 2700Sstevel@tonic-gate (caddr_t)bufp, len); 2710Sstevel@tonic-gate *(bufp + len - 1) = (char)0; 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate /* 2740Sstevel@tonic-gate * If the value begins with the char string "fail", 2750Sstevel@tonic-gate * then it means the node is failed. We don't care 2760Sstevel@tonic-gate * about any other values. We assume the node is ok 2770Sstevel@tonic-gate * although it might be 'disabled'. 2780Sstevel@tonic-gate */ 2790Sstevel@tonic-gate if (strncmp(bufp, fail, fail_len) == 0) 2800Sstevel@tonic-gate return (0); 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate return (1); 2830Sstevel@tonic-gate } 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate /* 2860Sstevel@tonic-gate * Check the status of the device node passed as an argument. 2870Sstevel@tonic-gate * 2880Sstevel@tonic-gate * if ((status is OKAY) || (status is DISABLED)) 2890Sstevel@tonic-gate * return DDI_SUCCESS 2900Sstevel@tonic-gate * else 2910Sstevel@tonic-gate * print a warning and return DDI_FAILURE 2920Sstevel@tonic-gate */ 2930Sstevel@tonic-gate /*ARGSUSED1*/ 2940Sstevel@tonic-gate int 2950Sstevel@tonic-gate check_status(int id, char *name, dev_info_t *parent) 2960Sstevel@tonic-gate { 2970Sstevel@tonic-gate char status_buf[64]; 2980Sstevel@tonic-gate char devtype_buf[OBP_MAXPROPNAME]; 2990Sstevel@tonic-gate int retval = DDI_FAILURE; 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate /* 3020Sstevel@tonic-gate * is the status okay? 3030Sstevel@tonic-gate */ 3040Sstevel@tonic-gate if (status_okay(id, status_buf, sizeof (status_buf))) 3050Sstevel@tonic-gate return (DDI_SUCCESS); 3060Sstevel@tonic-gate 3070Sstevel@tonic-gate /* 3080Sstevel@tonic-gate * a status property indicating bad memory will be associated 3090Sstevel@tonic-gate * with a node which has a "device_type" property with a value of 3100Sstevel@tonic-gate * "memory-controller". in this situation, return DDI_SUCCESS 3110Sstevel@tonic-gate */ 3120Sstevel@tonic-gate if (getlongprop_buf(id, OBP_DEVICETYPE, devtype_buf, 3130Sstevel@tonic-gate sizeof (devtype_buf)) > 0) { 3140Sstevel@tonic-gate if (strcmp(devtype_buf, "memory-controller") == 0) 3150Sstevel@tonic-gate retval = DDI_SUCCESS; 3160Sstevel@tonic-gate } 3170Sstevel@tonic-gate 3180Sstevel@tonic-gate /* 3190Sstevel@tonic-gate * print the status property information 3200Sstevel@tonic-gate */ 3210Sstevel@tonic-gate cmn_err(CE_WARN, "status '%s' for '%s'", status_buf, name); 3220Sstevel@tonic-gate return (retval); 3230Sstevel@tonic-gate } 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate /*ARGSUSED*/ 3260Sstevel@tonic-gate uint_t 3270Sstevel@tonic-gate softlevel1(caddr_t arg1, caddr_t arg2) 3280Sstevel@tonic-gate { 3290Sstevel@tonic-gate softint(); 3300Sstevel@tonic-gate return (1); 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate /* 3340Sstevel@tonic-gate * Allow for implementation specific correction of PROM property values. 3350Sstevel@tonic-gate */ 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate /*ARGSUSED*/ 3380Sstevel@tonic-gate void 3390Sstevel@tonic-gate impl_fix_props(dev_info_t *dip, dev_info_t *ch_dip, char *name, int len, 3400Sstevel@tonic-gate caddr_t buffer) 3410Sstevel@tonic-gate { 3420Sstevel@tonic-gate /* 3430Sstevel@tonic-gate * There are no adjustments needed in this implementation. 3440Sstevel@tonic-gate */ 3450Sstevel@tonic-gate } 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate static int 3480Sstevel@tonic-gate getlongprop_buf(int id, char *name, char *buf, int maxlen) 3490Sstevel@tonic-gate { 3500Sstevel@tonic-gate int size; 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate size = prom_getproplen((dnode_t)id, name); 3530Sstevel@tonic-gate if (size <= 0 || (size > maxlen - 1)) 3540Sstevel@tonic-gate return (-1); 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate if (-1 == prom_getprop((dnode_t)id, name, buf)) 3570Sstevel@tonic-gate return (-1); 3580Sstevel@tonic-gate 3590Sstevel@tonic-gate if (strcmp("name", name) == 0) { 3600Sstevel@tonic-gate if (buf[size - 1] != '\0') { 3610Sstevel@tonic-gate buf[size] = '\0'; 3620Sstevel@tonic-gate size += 1; 3630Sstevel@tonic-gate } 3640Sstevel@tonic-gate } 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate return (size); 3670Sstevel@tonic-gate } 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate static int 3700Sstevel@tonic-gate get_prop_int_array(dev_info_t *di, char *pname, int **pval, uint_t *plen) 3710Sstevel@tonic-gate { 3720Sstevel@tonic-gate int ret; 3730Sstevel@tonic-gate 3740Sstevel@tonic-gate if ((ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, di, 3750Sstevel@tonic-gate DDI_PROP_DONTPASS, pname, pval, plen)) 3760Sstevel@tonic-gate == DDI_PROP_SUCCESS) { 3770Sstevel@tonic-gate *plen = (*plen) * (sizeof (int)); 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate return (ret); 3800Sstevel@tonic-gate } 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate /* 3840Sstevel@tonic-gate * Node Configuration 3850Sstevel@tonic-gate */ 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate struct prop_ispec { 3880Sstevel@tonic-gate uint_t pri, vec; 3890Sstevel@tonic-gate }; 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate /* 3920Sstevel@tonic-gate * Create a ddi_parent_private_data structure from the ddi properties of 3930Sstevel@tonic-gate * the dev_info node. 3940Sstevel@tonic-gate * 3950Sstevel@tonic-gate * The "reg" and either an "intr" or "interrupts" properties are required 3960Sstevel@tonic-gate * if the driver wishes to create mappings or field interrupts on behalf 3970Sstevel@tonic-gate * of the device. 3980Sstevel@tonic-gate * 3990Sstevel@tonic-gate * The "reg" property is assumed to be a list of at least one triple 4000Sstevel@tonic-gate * 4010Sstevel@tonic-gate * <bustype, address, size>*1 4020Sstevel@tonic-gate * 4030Sstevel@tonic-gate * The "intr" property is assumed to be a list of at least one duple 4040Sstevel@tonic-gate * 4050Sstevel@tonic-gate * <SPARC ipl, vector#>*1 4060Sstevel@tonic-gate * 4070Sstevel@tonic-gate * The "interrupts" property is assumed to be a list of at least one 4080Sstevel@tonic-gate * n-tuples that describes the interrupt capabilities of the bus the device 4090Sstevel@tonic-gate * is connected to. For SBus, this looks like 4100Sstevel@tonic-gate * 4110Sstevel@tonic-gate * <SBus-level>*1 4120Sstevel@tonic-gate * 4130Sstevel@tonic-gate * (This property obsoletes the 'intr' property). 4140Sstevel@tonic-gate * 4150Sstevel@tonic-gate * The "ranges" property is optional. 4160Sstevel@tonic-gate */ 4170Sstevel@tonic-gate void 4180Sstevel@tonic-gate make_ddi_ppd(dev_info_t *child, struct ddi_parent_private_data **ppd) 4190Sstevel@tonic-gate { 4200Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 4210Sstevel@tonic-gate int n; 4220Sstevel@tonic-gate int *reg_prop, *rng_prop, *intr_prop, *irupts_prop; 4230Sstevel@tonic-gate uint_t reg_len, rng_len, intr_len, irupts_len; 4240Sstevel@tonic-gate 4250Sstevel@tonic-gate *ppd = pdptr = kmem_zalloc(sizeof (*pdptr), KM_SLEEP); 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate /* 4280Sstevel@tonic-gate * Handle the 'reg' property. 4290Sstevel@tonic-gate */ 4300Sstevel@tonic-gate if ((get_prop_int_array(child, "reg", ®_prop, ®_len) == 4310Sstevel@tonic-gate DDI_PROP_SUCCESS) && (reg_len != 0)) { 4320Sstevel@tonic-gate pdptr->par_nreg = reg_len / (int)sizeof (struct regspec); 4330Sstevel@tonic-gate pdptr->par_reg = (struct regspec *)reg_prop; 4340Sstevel@tonic-gate } 4350Sstevel@tonic-gate 4360Sstevel@tonic-gate /* 4370Sstevel@tonic-gate * See if I have a range (adding one where needed - this 4380Sstevel@tonic-gate * means to add one for sbus node in sun4c, when romvec > 0, 4390Sstevel@tonic-gate * if no range is already defined in the PROM node. 4400Sstevel@tonic-gate * (Currently no sun4c PROMS define range properties, 4410Sstevel@tonic-gate * but they should and may in the future.) For the SBus 4420Sstevel@tonic-gate * node, the range is defined by the SBus reg property. 4430Sstevel@tonic-gate */ 4440Sstevel@tonic-gate if (get_prop_int_array(child, "ranges", &rng_prop, &rng_len) 4450Sstevel@tonic-gate == DDI_PROP_SUCCESS) { 4460Sstevel@tonic-gate pdptr->par_nrng = rng_len / (int)(sizeof (struct rangespec)); 4470Sstevel@tonic-gate pdptr->par_rng = (struct rangespec *)rng_prop; 4480Sstevel@tonic-gate } 4490Sstevel@tonic-gate 4500Sstevel@tonic-gate /* 4510Sstevel@tonic-gate * Handle the 'intr' and 'interrupts' properties 4520Sstevel@tonic-gate */ 4530Sstevel@tonic-gate 4540Sstevel@tonic-gate /* 4550Sstevel@tonic-gate * For backwards compatibility 4560Sstevel@tonic-gate * we first look for the 'intr' property for the device. 4570Sstevel@tonic-gate */ 4580Sstevel@tonic-gate if (get_prop_int_array(child, "intr", &intr_prop, &intr_len) 4590Sstevel@tonic-gate != DDI_PROP_SUCCESS) { 4600Sstevel@tonic-gate intr_len = 0; 4610Sstevel@tonic-gate } 4620Sstevel@tonic-gate 4630Sstevel@tonic-gate /* 4640Sstevel@tonic-gate * If we're to support bus adapters and future platforms cleanly, 4650Sstevel@tonic-gate * we need to support the generalized 'interrupts' property. 4660Sstevel@tonic-gate */ 4670Sstevel@tonic-gate if (get_prop_int_array(child, "interrupts", &irupts_prop, 4680Sstevel@tonic-gate &irupts_len) != DDI_PROP_SUCCESS) { 4690Sstevel@tonic-gate irupts_len = 0; 4700Sstevel@tonic-gate } else if (intr_len != 0) { 4710Sstevel@tonic-gate /* 4720Sstevel@tonic-gate * If both 'intr' and 'interrupts' are defined, 4730Sstevel@tonic-gate * then 'interrupts' wins and we toss the 'intr' away. 4740Sstevel@tonic-gate */ 4750Sstevel@tonic-gate ddi_prop_free((void *)intr_prop); 4760Sstevel@tonic-gate intr_len = 0; 4770Sstevel@tonic-gate } 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate if (intr_len != 0) { 4800Sstevel@tonic-gate 4810Sstevel@tonic-gate /* 4820Sstevel@tonic-gate * Translate the 'intr' property into an array 4830Sstevel@tonic-gate * an array of struct intrspec's. There's not really 4840Sstevel@tonic-gate * very much to do here except copy what's out there. 4850Sstevel@tonic-gate */ 4860Sstevel@tonic-gate 4870Sstevel@tonic-gate struct intrspec *new; 4880Sstevel@tonic-gate struct prop_ispec *l; 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate n = pdptr->par_nintr = 4910Sstevel@tonic-gate intr_len / sizeof (struct prop_ispec); 4920Sstevel@tonic-gate l = (struct prop_ispec *)intr_prop; 4930Sstevel@tonic-gate pdptr->par_intr = 4940Sstevel@tonic-gate new = kmem_zalloc(n * sizeof (struct intrspec), KM_SLEEP); 4950Sstevel@tonic-gate while (n--) { 4960Sstevel@tonic-gate new->intrspec_pri = l->pri; 4970Sstevel@tonic-gate new->intrspec_vec = l->vec; 4980Sstevel@tonic-gate new++; 4990Sstevel@tonic-gate l++; 5000Sstevel@tonic-gate } 5010Sstevel@tonic-gate ddi_prop_free((void *)intr_prop); 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate } else if ((n = irupts_len) != 0) { 5040Sstevel@tonic-gate size_t size; 5050Sstevel@tonic-gate int *out; 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate /* 5080Sstevel@tonic-gate * Translate the 'interrupts' property into an array 5090Sstevel@tonic-gate * of intrspecs for the rest of the DDI framework to 5100Sstevel@tonic-gate * toy with. Only our ancestors really know how to 5110Sstevel@tonic-gate * do this, so ask 'em. We massage the 'interrupts' 5120Sstevel@tonic-gate * property so that it is pre-pended by a count of 5130Sstevel@tonic-gate * the number of integers in the argument. 5140Sstevel@tonic-gate */ 5150Sstevel@tonic-gate size = sizeof (int) + n; 5160Sstevel@tonic-gate out = kmem_alloc(size, KM_SLEEP); 5170Sstevel@tonic-gate *out = n / sizeof (int); 5180Sstevel@tonic-gate bcopy(irupts_prop, out + 1, (size_t)n); 5190Sstevel@tonic-gate ddi_prop_free((void *)irupts_prop); 5200Sstevel@tonic-gate if (ddi_ctlops(child, child, DDI_CTLOPS_XLATE_INTRS, 5210Sstevel@tonic-gate out, pdptr) != DDI_SUCCESS) { 5220Sstevel@tonic-gate cmn_err(CE_CONT, 5230Sstevel@tonic-gate "Unable to translate 'interrupts' for %s%d\n", 5240Sstevel@tonic-gate DEVI(child)->devi_binding_name, 5250Sstevel@tonic-gate DEVI(child)->devi_instance); 5260Sstevel@tonic-gate } 5270Sstevel@tonic-gate kmem_free(out, size); 5280Sstevel@tonic-gate } 5290Sstevel@tonic-gate } 5300Sstevel@tonic-gate 5310Sstevel@tonic-gate /* 5320Sstevel@tonic-gate * Name a child 5330Sstevel@tonic-gate */ 5340Sstevel@tonic-gate static int 5350Sstevel@tonic-gate impl_sunbus_name_child(dev_info_t *child, char *name, int namelen) 5360Sstevel@tonic-gate { 5370Sstevel@tonic-gate /* 5380Sstevel@tonic-gate * Fill in parent-private data and this function returns to us 5390Sstevel@tonic-gate * an indication if it used "registers" to fill in the data. 5400Sstevel@tonic-gate */ 5410Sstevel@tonic-gate if (ddi_get_parent_data(child) == NULL) { 5420Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 5430Sstevel@tonic-gate make_ddi_ppd(child, &pdptr); 5440Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 5450Sstevel@tonic-gate } 5460Sstevel@tonic-gate 5470Sstevel@tonic-gate name[0] = '\0'; 5480Sstevel@tonic-gate if (sparc_pd_getnreg(child) > 0) { 5490Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 5500Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype, 5510Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_addr); 5520Sstevel@tonic-gate } 5530Sstevel@tonic-gate 5540Sstevel@tonic-gate return (DDI_SUCCESS); 5550Sstevel@tonic-gate } 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate /* 5580Sstevel@tonic-gate * Called from the bus_ctl op of sunbus (sbus, obio, etc) nexus drivers 5590Sstevel@tonic-gate * to implement the DDI_CTLOPS_INITCHILD operation. That is, it names 5600Sstevel@tonic-gate * the children of sun busses based on the reg spec. 5610Sstevel@tonic-gate * 5620Sstevel@tonic-gate * Handles the following properties (in make_ddi_ppd): 5630Sstevel@tonic-gate * Property value 5640Sstevel@tonic-gate * Name type 5650Sstevel@tonic-gate * reg register spec 5660Sstevel@tonic-gate * intr old-form interrupt spec 5670Sstevel@tonic-gate * interrupts new (bus-oriented) interrupt spec 5680Sstevel@tonic-gate * ranges range spec 5690Sstevel@tonic-gate */ 5700Sstevel@tonic-gate int 5710Sstevel@tonic-gate impl_ddi_sunbus_initchild(dev_info_t *child) 5720Sstevel@tonic-gate { 5730Sstevel@tonic-gate char name[MAXNAMELEN]; 5740Sstevel@tonic-gate void impl_ddi_sunbus_removechild(dev_info_t *); 5750Sstevel@tonic-gate 5760Sstevel@tonic-gate /* 5770Sstevel@tonic-gate * Name the child, also makes parent private data 5780Sstevel@tonic-gate */ 5790Sstevel@tonic-gate (void) impl_sunbus_name_child(child, name, MAXNAMELEN); 5800Sstevel@tonic-gate ddi_set_name_addr(child, name); 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate /* 5830Sstevel@tonic-gate * Attempt to merge a .conf node; if successful, remove the 5840Sstevel@tonic-gate * .conf node. 5850Sstevel@tonic-gate */ 5860Sstevel@tonic-gate if ((ndi_dev_is_persistent_node(child) == 0) && 5870Sstevel@tonic-gate (ndi_merge_node(child, impl_sunbus_name_child) == DDI_SUCCESS)) { 5880Sstevel@tonic-gate /* 5890Sstevel@tonic-gate * Return failure to remove node 5900Sstevel@tonic-gate */ 5910Sstevel@tonic-gate impl_ddi_sunbus_removechild(child); 5920Sstevel@tonic-gate return (DDI_FAILURE); 5930Sstevel@tonic-gate } 5940Sstevel@tonic-gate return (DDI_SUCCESS); 5950Sstevel@tonic-gate } 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate void 5980Sstevel@tonic-gate impl_free_ddi_ppd(dev_info_t *dip) 5990Sstevel@tonic-gate { 6000Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 6010Sstevel@tonic-gate size_t n; 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate if ((pdptr = ddi_get_parent_data(dip)) == NULL) 6040Sstevel@tonic-gate return; 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate if ((n = (size_t)pdptr->par_nintr) != 0) 6070Sstevel@tonic-gate /* 6080Sstevel@tonic-gate * Note that kmem_free is used here (instead of 6090Sstevel@tonic-gate * ddi_prop_free) because the contents of the 6100Sstevel@tonic-gate * property were placed into a separate buffer and 6110Sstevel@tonic-gate * mucked with a bit before being stored in par_intr. 6120Sstevel@tonic-gate * The actual return value from the prop lookup 6130Sstevel@tonic-gate * was freed with ddi_prop_free previously. 6140Sstevel@tonic-gate */ 6150Sstevel@tonic-gate kmem_free(pdptr->par_intr, n * sizeof (struct intrspec)); 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate if ((n = (size_t)pdptr->par_nrng) != 0) 6180Sstevel@tonic-gate ddi_prop_free((void *)pdptr->par_rng); 6190Sstevel@tonic-gate 6200Sstevel@tonic-gate if ((n = pdptr->par_nreg) != 0) 6210Sstevel@tonic-gate ddi_prop_free((void *)pdptr->par_reg); 6220Sstevel@tonic-gate 6230Sstevel@tonic-gate kmem_free(pdptr, sizeof (*pdptr)); 6240Sstevel@tonic-gate ddi_set_parent_data(dip, NULL); 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate void 6280Sstevel@tonic-gate impl_ddi_sunbus_removechild(dev_info_t *dip) 6290Sstevel@tonic-gate { 6300Sstevel@tonic-gate impl_free_ddi_ppd(dip); 6310Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 6320Sstevel@tonic-gate /* 6330Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form 6340Sstevel@tonic-gate */ 6350Sstevel@tonic-gate impl_rem_dev_props(dip); 6360Sstevel@tonic-gate } 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate /* 6390Sstevel@tonic-gate * DDI Interrupt 6400Sstevel@tonic-gate */ 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate /* 6430Sstevel@tonic-gate * turn this on to force isa, eisa, and mca device to ignore the new 6440Sstevel@tonic-gate * hardware nodes in the device tree (normally turned on only for 6450Sstevel@tonic-gate * drivers that need it by setting the property "ignore-hardware-nodes" 6460Sstevel@tonic-gate * in their driver.conf file). 6470Sstevel@tonic-gate * 6480Sstevel@tonic-gate * 7/31/96 -- Turned off globally. Leaving variable in for the moment 6490Sstevel@tonic-gate * as safety valve. 6500Sstevel@tonic-gate */ 6510Sstevel@tonic-gate int ignore_hardware_nodes = 0; 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate /* 6540Sstevel@tonic-gate * Local data 6550Sstevel@tonic-gate */ 6560Sstevel@tonic-gate static struct impl_bus_promops *impl_busp; 6570Sstevel@tonic-gate 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate /* 6600Sstevel@tonic-gate * New DDI interrupt framework 6610Sstevel@tonic-gate */ 6620Sstevel@tonic-gate 6630Sstevel@tonic-gate /* 6640Sstevel@tonic-gate * i_ddi_handle_intr_ops: 6650Sstevel@tonic-gate */ 6660Sstevel@tonic-gate int 6670Sstevel@tonic-gate i_ddi_handle_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op, 6680Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void * result) 6690Sstevel@tonic-gate { 6700Sstevel@tonic-gate return (i_ddi_intr_ops(dip, rdip, op, hdlp, result)); 6710Sstevel@tonic-gate } 6720Sstevel@tonic-gate 6730Sstevel@tonic-gate /* 6740Sstevel@tonic-gate * i_ddi_intr_ops: 6750Sstevel@tonic-gate * 6760Sstevel@tonic-gate * This is the interrupt operator function wrapper for the bus function 6770Sstevel@tonic-gate * bus_intr_op. 6780Sstevel@tonic-gate */ 6790Sstevel@tonic-gate int 6800Sstevel@tonic-gate i_ddi_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op, 6810Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void * result) 6820Sstevel@tonic-gate { 6830Sstevel@tonic-gate dev_info_t *pdip = (dev_info_t *)DEVI(dip)->devi_parent; 6840Sstevel@tonic-gate int ret = DDI_FAILURE; 6850Sstevel@tonic-gate 6860Sstevel@tonic-gate /* request parent to process this interrupt op */ 6870Sstevel@tonic-gate if (NEXUS_HAS_INTR_OP(pdip)) 6880Sstevel@tonic-gate ret = (*(DEVI(pdip)->devi_ops->devo_bus_ops->bus_intr_op))( 6890Sstevel@tonic-gate pdip, rdip, op, hdlp, result); 6900Sstevel@tonic-gate else 6910Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to process interrupt " 6920Sstevel@tonic-gate "for %s%d due to down-rev nexus driver %s%d", 6930Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip), 6940Sstevel@tonic-gate ddi_get_name(pdip), ddi_get_instance(pdip)); 6950Sstevel@tonic-gate return (ret); 6960Sstevel@tonic-gate } 6970Sstevel@tonic-gate 6980Sstevel@tonic-gate /* 6990Sstevel@tonic-gate * i_ddi_add_softint - allocate and add a soft interrupt to the system 7000Sstevel@tonic-gate */ 7010Sstevel@tonic-gate int 7020Sstevel@tonic-gate i_ddi_add_softint(ddi_softint_hdl_impl_t *hdlp) 7030Sstevel@tonic-gate { 7040Sstevel@tonic-gate int ret; 7050Sstevel@tonic-gate 7060Sstevel@tonic-gate /* add soft interrupt handler */ 7070Sstevel@tonic-gate ret = add_avsoftintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func, 7080Sstevel@tonic-gate DEVI(hdlp->ih_dip)->devi_name, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 7090Sstevel@tonic-gate return (ret ? DDI_SUCCESS : DDI_FAILURE); 7100Sstevel@tonic-gate } 7110Sstevel@tonic-gate 7120Sstevel@tonic-gate 7130Sstevel@tonic-gate void 7140Sstevel@tonic-gate i_ddi_remove_softint(ddi_softint_hdl_impl_t *hdlp) 7150Sstevel@tonic-gate { 7160Sstevel@tonic-gate (void) rem_avsoftintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func); 7170Sstevel@tonic-gate } 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate 7200Sstevel@tonic-gate extern void (*setsoftint)(int); 7210Sstevel@tonic-gate 7220Sstevel@tonic-gate int 723*278Sgovinda i_ddi_trigger_softint(ddi_softint_hdl_impl_t *hdlp, void *arg2) 7240Sstevel@tonic-gate { 725*278Sgovinda int ret = DDI_SUCCESS; 726*278Sgovinda 727*278Sgovinda if (hdlp->ih_pending) { 728*278Sgovinda ret = DDI_EPENDING; 729*278Sgovinda } else { 7300Sstevel@tonic-gate update_avsoftintr_args((void *)hdlp, 731*278Sgovinda hdlp->ih_pri, arg2); 7320Sstevel@tonic-gate hdlp->ih_pending = 1; 7330Sstevel@tonic-gate } 734*278Sgovinda 7350Sstevel@tonic-gate (*setsoftint)(hdlp->ih_pri); 736*278Sgovinda return (ret); 7370Sstevel@tonic-gate } 7380Sstevel@tonic-gate 7390Sstevel@tonic-gate /* 7400Sstevel@tonic-gate * i_ddi_set_softint_pri: 7410Sstevel@tonic-gate * 7420Sstevel@tonic-gate * The way this works is that it first tries to add a softint vector 7430Sstevel@tonic-gate * at the new priority in hdlp. If that succeeds; then it removes the 7440Sstevel@tonic-gate * existing softint vector at the old priority. 7450Sstevel@tonic-gate */ 7460Sstevel@tonic-gate int 7470Sstevel@tonic-gate i_ddi_set_softint_pri(ddi_softint_hdl_impl_t *hdlp, uint_t old_pri) 7480Sstevel@tonic-gate { 7490Sstevel@tonic-gate /* 7500Sstevel@tonic-gate * If a softint is pending at the old priority then fail the request. 7510Sstevel@tonic-gate * OR 7520Sstevel@tonic-gate * If we failed to add a softint vector with the new priority; then 7530Sstevel@tonic-gate * fail the request with a DDI_FAILURE 7540Sstevel@tonic-gate */ 7550Sstevel@tonic-gate if (hdlp->ih_pending || i_ddi_add_softint(hdlp) != DDI_SUCCESS) 7560Sstevel@tonic-gate return (DDI_FAILURE); 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate /* Now, remove the softint at the old priority */ 7590Sstevel@tonic-gate (void) rem_avsoftintr((void *)hdlp, old_pri, hdlp->ih_cb_func); 7600Sstevel@tonic-gate return (DDI_SUCCESS); 7610Sstevel@tonic-gate } 7620Sstevel@tonic-gate 7630Sstevel@tonic-gate /* 7640Sstevel@tonic-gate * DDI Memory/DMA 7650Sstevel@tonic-gate */ 7660Sstevel@tonic-gate 7670Sstevel@tonic-gate /* 7680Sstevel@tonic-gate * Support for allocating DMAable memory to implement 7690Sstevel@tonic-gate * ddi_dma_mem_alloc(9F) interface. 7700Sstevel@tonic-gate */ 7710Sstevel@tonic-gate 7720Sstevel@tonic-gate #define KA_ALIGN_SHIFT 7 7730Sstevel@tonic-gate #define KA_ALIGN (1 << KA_ALIGN_SHIFT) 7740Sstevel@tonic-gate #define KA_NCACHE (PAGESHIFT + 1 - KA_ALIGN_SHIFT) 7750Sstevel@tonic-gate 7760Sstevel@tonic-gate /* 7770Sstevel@tonic-gate * Dummy DMA attribute template for kmem_io[].kmem_io_attr. We only 7780Sstevel@tonic-gate * care about addr_lo, addr_hi, and align. addr_hi will be dynamically set. 7790Sstevel@tonic-gate */ 7800Sstevel@tonic-gate 7810Sstevel@tonic-gate static ddi_dma_attr_t kmem_io_attr = { 7820Sstevel@tonic-gate DMA_ATTR_V0, 7830Sstevel@tonic-gate 0x0000000000000000ULL, /* dma_attr_addr_lo */ 7840Sstevel@tonic-gate 0x0000000000000000ULL, /* dma_attr_addr_hi */ 7850Sstevel@tonic-gate 0x00ffffff, 7860Sstevel@tonic-gate 0x1000, /* dma_attr_align */ 7870Sstevel@tonic-gate 1, 1, 0xffffffffULL, 0xffffffffULL, 0x1, 1, 0 7880Sstevel@tonic-gate }; 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate /* kmem io memory ranges and indices */ 7910Sstevel@tonic-gate enum { 7920Sstevel@tonic-gate IO_4P, IO_64G, IO_4G, IO_2G, IO_1G, IO_512M, 7930Sstevel@tonic-gate IO_256M, IO_128M, IO_64M, IO_32M, IO_16M, MAX_MEM_RANGES 7940Sstevel@tonic-gate }; 7950Sstevel@tonic-gate 7960Sstevel@tonic-gate static struct { 7970Sstevel@tonic-gate vmem_t *kmem_io_arena; 7980Sstevel@tonic-gate kmem_cache_t *kmem_io_cache[KA_NCACHE]; 7990Sstevel@tonic-gate ddi_dma_attr_t kmem_io_attr; 8000Sstevel@tonic-gate } kmem_io[MAX_MEM_RANGES]; 8010Sstevel@tonic-gate 8020Sstevel@tonic-gate static int kmem_io_idx; /* index of first populated kmem_io[] */ 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate static page_t * 8050Sstevel@tonic-gate page_create_io_wrapper(void *addr, size_t len, int vmflag, void *arg) 8060Sstevel@tonic-gate { 8070Sstevel@tonic-gate extern page_t *page_create_io(vnode_t *, u_offset_t, uint_t, 8080Sstevel@tonic-gate uint_t, struct as *, caddr_t, ddi_dma_attr_t *); 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate return (page_create_io(&kvp, (u_offset_t)(uintptr_t)addr, len, 8110Sstevel@tonic-gate PG_EXCL | ((vmflag & VM_NOSLEEP) ? 0 : PG_WAIT), &kas, addr, arg)); 8120Sstevel@tonic-gate } 8130Sstevel@tonic-gate 8140Sstevel@tonic-gate static void * 8150Sstevel@tonic-gate segkmem_alloc_io_4P(vmem_t *vmp, size_t size, int vmflag) 8160Sstevel@tonic-gate { 8170Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8180Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_4P].kmem_io_attr)); 8190Sstevel@tonic-gate } 8200Sstevel@tonic-gate 8210Sstevel@tonic-gate static void * 8220Sstevel@tonic-gate segkmem_alloc_io_64G(vmem_t *vmp, size_t size, int vmflag) 8230Sstevel@tonic-gate { 8240Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8250Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_64G].kmem_io_attr)); 8260Sstevel@tonic-gate } 8270Sstevel@tonic-gate 8280Sstevel@tonic-gate static void * 8290Sstevel@tonic-gate segkmem_alloc_io_4G(vmem_t *vmp, size_t size, int vmflag) 8300Sstevel@tonic-gate { 8310Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8320Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_4G].kmem_io_attr)); 8330Sstevel@tonic-gate } 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate static void * 8360Sstevel@tonic-gate segkmem_alloc_io_2G(vmem_t *vmp, size_t size, int vmflag) 8370Sstevel@tonic-gate { 8380Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8390Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_2G].kmem_io_attr)); 8400Sstevel@tonic-gate } 8410Sstevel@tonic-gate 8420Sstevel@tonic-gate static void * 8430Sstevel@tonic-gate segkmem_alloc_io_1G(vmem_t *vmp, size_t size, int vmflag) 8440Sstevel@tonic-gate { 8450Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8460Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_1G].kmem_io_attr)); 8470Sstevel@tonic-gate } 8480Sstevel@tonic-gate 8490Sstevel@tonic-gate static void * 8500Sstevel@tonic-gate segkmem_alloc_io_512M(vmem_t *vmp, size_t size, int vmflag) 8510Sstevel@tonic-gate { 8520Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8530Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_512M].kmem_io_attr)); 8540Sstevel@tonic-gate } 8550Sstevel@tonic-gate 8560Sstevel@tonic-gate static void * 8570Sstevel@tonic-gate segkmem_alloc_io_256M(vmem_t *vmp, size_t size, int vmflag) 8580Sstevel@tonic-gate { 8590Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8600Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_256M].kmem_io_attr)); 8610Sstevel@tonic-gate } 8620Sstevel@tonic-gate 8630Sstevel@tonic-gate static void * 8640Sstevel@tonic-gate segkmem_alloc_io_128M(vmem_t *vmp, size_t size, int vmflag) 8650Sstevel@tonic-gate { 8660Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8670Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_128M].kmem_io_attr)); 8680Sstevel@tonic-gate } 8690Sstevel@tonic-gate 8700Sstevel@tonic-gate static void * 8710Sstevel@tonic-gate segkmem_alloc_io_64M(vmem_t *vmp, size_t size, int vmflag) 8720Sstevel@tonic-gate { 8730Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8740Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_64M].kmem_io_attr)); 8750Sstevel@tonic-gate } 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate static void * 8780Sstevel@tonic-gate segkmem_alloc_io_32M(vmem_t *vmp, size_t size, int vmflag) 8790Sstevel@tonic-gate { 8800Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8810Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_32M].kmem_io_attr)); 8820Sstevel@tonic-gate } 8830Sstevel@tonic-gate 8840Sstevel@tonic-gate static void * 8850Sstevel@tonic-gate segkmem_alloc_io_16M(vmem_t *vmp, size_t size, int vmflag) 8860Sstevel@tonic-gate { 8870Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 8880Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_16M].kmem_io_attr)); 8890Sstevel@tonic-gate } 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate struct { 8920Sstevel@tonic-gate uint64_t io_limit; 8930Sstevel@tonic-gate char *io_name; 8940Sstevel@tonic-gate void *(*io_alloc)(vmem_t *, size_t, int); 8950Sstevel@tonic-gate int io_initial; /* kmem_io_init during startup */ 8960Sstevel@tonic-gate } io_arena_params[MAX_MEM_RANGES] = { 8970Sstevel@tonic-gate {0x000fffffffffffffULL, "kmem_io_4P", segkmem_alloc_io_4P, 1}, 8980Sstevel@tonic-gate {0x0000000fffffffffULL, "kmem_io_64G", segkmem_alloc_io_64G, 0}, 8990Sstevel@tonic-gate {0x00000000ffffffffULL, "kmem_io_4G", segkmem_alloc_io_4G, 1}, 9000Sstevel@tonic-gate {0x000000007fffffffULL, "kmem_io_2G", segkmem_alloc_io_2G, 1}, 9010Sstevel@tonic-gate {0x000000003fffffffULL, "kmem_io_1G", segkmem_alloc_io_1G, 0}, 9020Sstevel@tonic-gate {0x000000001fffffffULL, "kmem_io_512M", segkmem_alloc_io_512M, 0}, 9030Sstevel@tonic-gate {0x000000000fffffffULL, "kmem_io_256M", segkmem_alloc_io_256M, 0}, 9040Sstevel@tonic-gate {0x0000000007ffffffULL, "kmem_io_128M", segkmem_alloc_io_128M, 0}, 9050Sstevel@tonic-gate {0x0000000003ffffffULL, "kmem_io_64M", segkmem_alloc_io_64M, 0}, 9060Sstevel@tonic-gate {0x0000000001ffffffULL, "kmem_io_32M", segkmem_alloc_io_32M, 0}, 9070Sstevel@tonic-gate {0x0000000000ffffffULL, "kmem_io_16M", segkmem_alloc_io_16M, 1} 9080Sstevel@tonic-gate }; 9090Sstevel@tonic-gate 9100Sstevel@tonic-gate void 9110Sstevel@tonic-gate kmem_io_init(int a) 9120Sstevel@tonic-gate { 9130Sstevel@tonic-gate int c; 9140Sstevel@tonic-gate char name[40]; 9150Sstevel@tonic-gate 9160Sstevel@tonic-gate kmem_io[a].kmem_io_arena = vmem_create(io_arena_params[a].io_name, 9170Sstevel@tonic-gate NULL, 0, PAGESIZE, io_arena_params[a].io_alloc, 9180Sstevel@tonic-gate segkmem_free, heap_arena, 0, VM_SLEEP); 9190Sstevel@tonic-gate for (c = 0; c < KA_NCACHE; c++) { 9200Sstevel@tonic-gate size_t size = KA_ALIGN << c; 9210Sstevel@tonic-gate (void) sprintf(name, "%s_%lu", 9220Sstevel@tonic-gate io_arena_params[a].io_name, size); 9230Sstevel@tonic-gate kmem_io[a].kmem_io_cache[c] = kmem_cache_create(name, 9240Sstevel@tonic-gate size, size, NULL, NULL, NULL, NULL, 9250Sstevel@tonic-gate kmem_io[a].kmem_io_arena, 0); 9260Sstevel@tonic-gate } 9270Sstevel@tonic-gate } 9280Sstevel@tonic-gate 9290Sstevel@tonic-gate /* 9300Sstevel@tonic-gate * Return the index of the highest memory range for addr. 9310Sstevel@tonic-gate */ 9320Sstevel@tonic-gate static int 9330Sstevel@tonic-gate kmem_io_index(uint64_t addr) 9340Sstevel@tonic-gate { 9350Sstevel@tonic-gate int n; 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate for (n = kmem_io_idx; n < MAX_MEM_RANGES; n++) { 9380Sstevel@tonic-gate if (kmem_io[n].kmem_io_attr.dma_attr_addr_hi <= addr) { 9390Sstevel@tonic-gate if (kmem_io[n].kmem_io_arena == NULL) 9400Sstevel@tonic-gate kmem_io_init(n); 9410Sstevel@tonic-gate return (n); 9420Sstevel@tonic-gate } 9430Sstevel@tonic-gate } 9440Sstevel@tonic-gate panic("kmem_io_index: invalid addr - must be at least 16m"); 9450Sstevel@tonic-gate 9460Sstevel@tonic-gate /*NOTREACHED*/ 9470Sstevel@tonic-gate } 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate /* 9500Sstevel@tonic-gate * Return the index of the next kmem_io populated memory range 9510Sstevel@tonic-gate * after curindex. 9520Sstevel@tonic-gate */ 9530Sstevel@tonic-gate static int 9540Sstevel@tonic-gate kmem_io_index_next(int curindex) 9550Sstevel@tonic-gate { 9560Sstevel@tonic-gate int n; 9570Sstevel@tonic-gate 9580Sstevel@tonic-gate for (n = curindex + 1; n < MAX_MEM_RANGES; n++) { 9590Sstevel@tonic-gate if (kmem_io[n].kmem_io_arena) 9600Sstevel@tonic-gate return (n); 9610Sstevel@tonic-gate } 9620Sstevel@tonic-gate return (-1); 9630Sstevel@tonic-gate } 9640Sstevel@tonic-gate 9650Sstevel@tonic-gate void 9660Sstevel@tonic-gate ka_init(void) 9670Sstevel@tonic-gate { 9680Sstevel@tonic-gate int a; 9690Sstevel@tonic-gate extern pfn_t physmax; 9700Sstevel@tonic-gate uint64_t maxphysaddr = mmu_ptob((uint64_t)physmax + 1) - 1; 9710Sstevel@tonic-gate 9720Sstevel@tonic-gate ASSERT(maxphysaddr <= io_arena_params[0].io_limit); 9730Sstevel@tonic-gate 9740Sstevel@tonic-gate for (a = 0; a < MAX_MEM_RANGES; a++) { 9750Sstevel@tonic-gate if (maxphysaddr >= io_arena_params[a + 1].io_limit) { 9760Sstevel@tonic-gate if (maxphysaddr > io_arena_params[a + 1].io_limit) 9770Sstevel@tonic-gate io_arena_params[a].io_limit = maxphysaddr; 9780Sstevel@tonic-gate else 9790Sstevel@tonic-gate a++; 9800Sstevel@tonic-gate break; 9810Sstevel@tonic-gate } 9820Sstevel@tonic-gate } 9830Sstevel@tonic-gate kmem_io_idx = a; 9840Sstevel@tonic-gate 9850Sstevel@tonic-gate for (; a < MAX_MEM_RANGES; a++) { 9860Sstevel@tonic-gate kmem_io[a].kmem_io_attr = kmem_io_attr; 9870Sstevel@tonic-gate kmem_io[a].kmem_io_attr.dma_attr_addr_hi = 9880Sstevel@tonic-gate io_arena_params[a].io_limit; 9890Sstevel@tonic-gate /* 9900Sstevel@tonic-gate * initialize kmem_io[] arena/cache corresponding to 9910Sstevel@tonic-gate * maxphysaddr and to the "common" io memory ranges that 9920Sstevel@tonic-gate * have io_initial set to a non-zero value. 9930Sstevel@tonic-gate */ 9940Sstevel@tonic-gate if (io_arena_params[a].io_initial || a == kmem_io_idx) 9950Sstevel@tonic-gate kmem_io_init(a); 9960Sstevel@tonic-gate } 9970Sstevel@tonic-gate } 9980Sstevel@tonic-gate 9990Sstevel@tonic-gate /* 10000Sstevel@tonic-gate * put contig address/size 10010Sstevel@tonic-gate */ 10020Sstevel@tonic-gate static void * 10030Sstevel@tonic-gate putctgas(void *addr, size_t size) 10040Sstevel@tonic-gate { 10050Sstevel@tonic-gate struct ctgas *ctgp = &ctglist; 10060Sstevel@tonic-gate int i; 10070Sstevel@tonic-gate 10080Sstevel@tonic-gate CTGLOCK(); 10090Sstevel@tonic-gate do { 10100Sstevel@tonic-gate if ((i = ctgp->ctg_index) < CTGENTRIES) { 10110Sstevel@tonic-gate ctgp->ctg_addr[i] = addr; 10120Sstevel@tonic-gate ctgp->ctg_size[i] = size; 10130Sstevel@tonic-gate ctgp->ctg_index++; 10140Sstevel@tonic-gate break; 10150Sstevel@tonic-gate } 10160Sstevel@tonic-gate if (!ctgp->ctg_next) 10170Sstevel@tonic-gate ctgp->ctg_next = kmem_zalloc(sizeof (struct ctgas), 10180Sstevel@tonic-gate KM_NOSLEEP); 10190Sstevel@tonic-gate ctgp = ctgp->ctg_next; 10200Sstevel@tonic-gate } while (ctgp); 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate CTGUNLOCK(); 10230Sstevel@tonic-gate return (ctgp); 10240Sstevel@tonic-gate } 10250Sstevel@tonic-gate 10260Sstevel@tonic-gate /* 10270Sstevel@tonic-gate * get contig size by addr 10280Sstevel@tonic-gate */ 10290Sstevel@tonic-gate static size_t 10300Sstevel@tonic-gate getctgsz(void *addr) 10310Sstevel@tonic-gate { 10320Sstevel@tonic-gate struct ctgas *ctgp = &ctglist; 10330Sstevel@tonic-gate int i, j; 10340Sstevel@tonic-gate size_t sz; 10350Sstevel@tonic-gate 10360Sstevel@tonic-gate ASSERT(addr); 10370Sstevel@tonic-gate CTGLOCK(); 10380Sstevel@tonic-gate 10390Sstevel@tonic-gate while (ctgp) { 10400Sstevel@tonic-gate for (i = 0; i < ctgp->ctg_index; i++) { 10410Sstevel@tonic-gate if (addr != ctgp->ctg_addr[i]) 10420Sstevel@tonic-gate continue; 10430Sstevel@tonic-gate 10440Sstevel@tonic-gate sz = ctgp->ctg_size[i]; 10450Sstevel@tonic-gate j = --ctgp->ctg_index; 10460Sstevel@tonic-gate if (i != j) { 10470Sstevel@tonic-gate ctgp->ctg_size[i] = ctgp->ctg_size[j]; 10480Sstevel@tonic-gate ctgp->ctg_addr[i] = ctgp->ctg_addr[j]; 10490Sstevel@tonic-gate } 10500Sstevel@tonic-gate CTGUNLOCK(); 10510Sstevel@tonic-gate return (sz); 10520Sstevel@tonic-gate } 10530Sstevel@tonic-gate ctgp = ctgp->ctg_next; 10540Sstevel@tonic-gate } 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate CTGUNLOCK(); 10570Sstevel@tonic-gate return (0); 10580Sstevel@tonic-gate } 10590Sstevel@tonic-gate 10600Sstevel@tonic-gate /* 10610Sstevel@tonic-gate * contig_alloc: 10620Sstevel@tonic-gate * 10630Sstevel@tonic-gate * allocates contiguous memory to satisfy the 'size' and dma attributes 10640Sstevel@tonic-gate * specified in 'attr'. 10650Sstevel@tonic-gate * 10660Sstevel@tonic-gate * Not all of memory need to be physically contiguous if the 10670Sstevel@tonic-gate * scatter-gather list length is greater than 1. 10680Sstevel@tonic-gate */ 10690Sstevel@tonic-gate 10700Sstevel@tonic-gate /*ARGSUSED*/ 10710Sstevel@tonic-gate void * 10720Sstevel@tonic-gate contig_alloc(size_t size, ddi_dma_attr_t *attr, uintptr_t align, int cansleep) 10730Sstevel@tonic-gate { 10740Sstevel@tonic-gate pgcnt_t pgcnt = btopr(size); 10750Sstevel@tonic-gate size_t asize = pgcnt * PAGESIZE; 10760Sstevel@tonic-gate page_t *ppl; 10770Sstevel@tonic-gate int pflag; 10780Sstevel@tonic-gate void *addr; 10790Sstevel@tonic-gate 10800Sstevel@tonic-gate extern page_t *page_create_io(vnode_t *, u_offset_t, uint_t, 10810Sstevel@tonic-gate uint_t, struct as *, caddr_t, ddi_dma_attr_t *); 10820Sstevel@tonic-gate 10830Sstevel@tonic-gate /* segkmem_xalloc */ 10840Sstevel@tonic-gate 10850Sstevel@tonic-gate if (align <= PAGESIZE) 10860Sstevel@tonic-gate addr = vmem_alloc(heap_arena, asize, 10870Sstevel@tonic-gate (cansleep) ? VM_SLEEP : VM_NOSLEEP); 10880Sstevel@tonic-gate else 10890Sstevel@tonic-gate addr = vmem_xalloc(heap_arena, asize, align, 0, 0, NULL, NULL, 10900Sstevel@tonic-gate (cansleep) ? VM_SLEEP : VM_NOSLEEP); 10910Sstevel@tonic-gate if (addr) { 10920Sstevel@tonic-gate ASSERT(!((uintptr_t)addr & (align - 1))); 10930Sstevel@tonic-gate 10940Sstevel@tonic-gate if (page_resv(pgcnt, 10950Sstevel@tonic-gate (cansleep) ? KM_SLEEP : KM_NOSLEEP) == 0) { 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate vmem_free(heap_arena, addr, asize); 10980Sstevel@tonic-gate return (NULL); 10990Sstevel@tonic-gate } 11000Sstevel@tonic-gate pflag = PG_EXCL; 11010Sstevel@tonic-gate 11020Sstevel@tonic-gate if (cansleep) 11030Sstevel@tonic-gate pflag |= PG_WAIT; 11040Sstevel@tonic-gate 11050Sstevel@tonic-gate /* 4k req gets from freelists rather than pfn search */ 11060Sstevel@tonic-gate if (pgcnt > 1 || align > PAGESIZE) 11070Sstevel@tonic-gate pflag |= PG_PHYSCONTIG; 11080Sstevel@tonic-gate 11090Sstevel@tonic-gate ppl = page_create_io(&kvp, (u_offset_t)(uintptr_t)addr, 11100Sstevel@tonic-gate asize, pflag, &kas, (caddr_t)addr, attr); 11110Sstevel@tonic-gate 11120Sstevel@tonic-gate if (!ppl) { 11130Sstevel@tonic-gate vmem_free(heap_arena, addr, asize); 11140Sstevel@tonic-gate page_unresv(pgcnt); 11150Sstevel@tonic-gate return (NULL); 11160Sstevel@tonic-gate } 11170Sstevel@tonic-gate 11180Sstevel@tonic-gate while (ppl != NULL) { 11190Sstevel@tonic-gate page_t *pp = ppl; 11200Sstevel@tonic-gate page_sub(&ppl, pp); 11210Sstevel@tonic-gate ASSERT(page_iolock_assert(pp)); 11220Sstevel@tonic-gate page_io_unlock(pp); 11230Sstevel@tonic-gate page_downgrade(pp); 11240Sstevel@tonic-gate hat_memload(kas.a_hat, (caddr_t)(uintptr_t)pp->p_offset, 11250Sstevel@tonic-gate pp, (PROT_ALL & ~PROT_USER) | 11260Sstevel@tonic-gate HAT_NOSYNC, HAT_LOAD_LOCK); 11270Sstevel@tonic-gate } 11280Sstevel@tonic-gate } 11290Sstevel@tonic-gate return (addr); 11300Sstevel@tonic-gate } 11310Sstevel@tonic-gate 11320Sstevel@tonic-gate static void 11330Sstevel@tonic-gate contig_free(void *addr, size_t size) 11340Sstevel@tonic-gate { 11350Sstevel@tonic-gate pgcnt_t pgcnt = btopr(size); 11360Sstevel@tonic-gate size_t asize = pgcnt * PAGESIZE; 11370Sstevel@tonic-gate caddr_t a, ea; 11380Sstevel@tonic-gate page_t *pp; 11390Sstevel@tonic-gate 11400Sstevel@tonic-gate hat_unload(kas.a_hat, addr, asize, HAT_UNLOAD_UNLOCK); 11410Sstevel@tonic-gate 11420Sstevel@tonic-gate for (a = addr, ea = a + asize; a < ea; a += PAGESIZE) { 11430Sstevel@tonic-gate pp = page_find(&kvp, 11440Sstevel@tonic-gate (u_offset_t)(uintptr_t)a); 11450Sstevel@tonic-gate if (!pp) 11460Sstevel@tonic-gate panic("contig_free: contig pp not found"); 11470Sstevel@tonic-gate 11480Sstevel@tonic-gate if (!page_tryupgrade(pp)) { 11490Sstevel@tonic-gate page_unlock(pp); 11500Sstevel@tonic-gate pp = page_lookup(&kvp, 11510Sstevel@tonic-gate (u_offset_t)(uintptr_t)a, SE_EXCL); 11520Sstevel@tonic-gate if (pp == NULL) 11530Sstevel@tonic-gate panic("contig_free: page freed"); 11540Sstevel@tonic-gate } 11550Sstevel@tonic-gate page_destroy(pp, 0); 11560Sstevel@tonic-gate } 11570Sstevel@tonic-gate 11580Sstevel@tonic-gate page_unresv(pgcnt); 11590Sstevel@tonic-gate vmem_free(heap_arena, addr, asize); 11600Sstevel@tonic-gate } 11610Sstevel@tonic-gate 11620Sstevel@tonic-gate /* 11630Sstevel@tonic-gate * Allocate from the system, aligned on a specific boundary. 11640Sstevel@tonic-gate * The alignment, if non-zero, must be a power of 2. 11650Sstevel@tonic-gate */ 11660Sstevel@tonic-gate static void * 11670Sstevel@tonic-gate kalloca(size_t size, size_t align, int cansleep, int physcontig, 11680Sstevel@tonic-gate ddi_dma_attr_t *attr) 11690Sstevel@tonic-gate { 11700Sstevel@tonic-gate size_t *addr, *raddr, rsize; 11710Sstevel@tonic-gate size_t hdrsize = 4 * sizeof (size_t); /* must be power of 2 */ 11720Sstevel@tonic-gate int a, i, c; 11730Sstevel@tonic-gate vmem_t *vmp; 11740Sstevel@tonic-gate kmem_cache_t *cp = NULL; 11750Sstevel@tonic-gate 11760Sstevel@tonic-gate align = MAX(align, hdrsize); 11770Sstevel@tonic-gate ASSERT((align & (align - 1)) == 0); 11780Sstevel@tonic-gate 11790Sstevel@tonic-gate /* 11800Sstevel@tonic-gate * All of our allocators guarantee 16-byte alignment, so we don't 11810Sstevel@tonic-gate * need to reserve additional space for the header. 11820Sstevel@tonic-gate * To simplify picking the correct kmem_io_cache, we round up to 11830Sstevel@tonic-gate * a multiple of KA_ALIGN. 11840Sstevel@tonic-gate */ 11850Sstevel@tonic-gate rsize = P2ROUNDUP_TYPED(size + align, KA_ALIGN, size_t); 11860Sstevel@tonic-gate 11870Sstevel@tonic-gate if (physcontig && rsize > PAGESIZE) { 11880Sstevel@tonic-gate if (addr = contig_alloc(size, attr, align, cansleep)) { 11890Sstevel@tonic-gate if (!putctgas(addr, size)) 11900Sstevel@tonic-gate contig_free(addr, size); 11910Sstevel@tonic-gate else 11920Sstevel@tonic-gate return (addr); 11930Sstevel@tonic-gate } 11940Sstevel@tonic-gate return (NULL); 11950Sstevel@tonic-gate } 11960Sstevel@tonic-gate 11970Sstevel@tonic-gate ASSERT(attr->dma_attr_addr_lo <= mmu_ptob((uint64_t)ddiphysmin)); 11980Sstevel@tonic-gate 11990Sstevel@tonic-gate a = kmem_io_index(attr->dma_attr_addr_hi); 12000Sstevel@tonic-gate 12010Sstevel@tonic-gate if (rsize > PAGESIZE) { 12020Sstevel@tonic-gate vmp = kmem_io[a].kmem_io_arena; 12030Sstevel@tonic-gate raddr = vmem_alloc(vmp, rsize, 12040Sstevel@tonic-gate (cansleep) ? VM_SLEEP : VM_NOSLEEP); 12050Sstevel@tonic-gate } else { 12060Sstevel@tonic-gate c = highbit((rsize >> KA_ALIGN_SHIFT) - 1); 12070Sstevel@tonic-gate cp = kmem_io[a].kmem_io_cache[c]; 12080Sstevel@tonic-gate raddr = kmem_cache_alloc(cp, (cansleep) ? KM_SLEEP : 12090Sstevel@tonic-gate KM_NOSLEEP); 12100Sstevel@tonic-gate } 12110Sstevel@tonic-gate 12120Sstevel@tonic-gate if (raddr == NULL) { 12130Sstevel@tonic-gate int na; 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate ASSERT(cansleep == 0); 12160Sstevel@tonic-gate if (rsize > PAGESIZE) 12170Sstevel@tonic-gate return (NULL); 12180Sstevel@tonic-gate /* 12190Sstevel@tonic-gate * System does not have memory in the requested range. 12200Sstevel@tonic-gate * Try smaller kmem io ranges and larger cache sizes 12210Sstevel@tonic-gate * to see if there might be memory available in 12220Sstevel@tonic-gate * these other caches. 12230Sstevel@tonic-gate */ 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate for (na = kmem_io_index_next(a); na >= 0; 12260Sstevel@tonic-gate na = kmem_io_index_next(na)) { 12270Sstevel@tonic-gate ASSERT(kmem_io[na].kmem_io_arena); 12280Sstevel@tonic-gate cp = kmem_io[na].kmem_io_cache[c]; 12290Sstevel@tonic-gate raddr = kmem_cache_alloc(cp, KM_NOSLEEP); 12300Sstevel@tonic-gate if (raddr) 12310Sstevel@tonic-gate goto kallocdone; 12320Sstevel@tonic-gate } 12330Sstevel@tonic-gate /* now try the larger kmem io cache sizes */ 12340Sstevel@tonic-gate for (na = a; na >= 0; na = kmem_io_index_next(na)) { 12350Sstevel@tonic-gate for (i = c + 1; i < KA_NCACHE; i++) { 12360Sstevel@tonic-gate cp = kmem_io[na].kmem_io_cache[i]; 12370Sstevel@tonic-gate raddr = kmem_cache_alloc(cp, KM_NOSLEEP); 12380Sstevel@tonic-gate if (raddr) 12390Sstevel@tonic-gate goto kallocdone; 12400Sstevel@tonic-gate } 12410Sstevel@tonic-gate } 12420Sstevel@tonic-gate return (NULL); 12430Sstevel@tonic-gate } 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate kallocdone: 12460Sstevel@tonic-gate ASSERT(!P2CROSS((uintptr_t)raddr, (uintptr_t)raddr + rsize - 1, 12470Sstevel@tonic-gate PAGESIZE) || rsize > PAGESIZE); 12480Sstevel@tonic-gate 12490Sstevel@tonic-gate addr = (size_t *)P2ROUNDUP((uintptr_t)raddr + hdrsize, align); 12500Sstevel@tonic-gate ASSERT((uintptr_t)addr + size - (uintptr_t)raddr <= rsize); 12510Sstevel@tonic-gate 12520Sstevel@tonic-gate addr[-4] = (size_t)cp; 12530Sstevel@tonic-gate addr[-3] = (size_t)vmp; 12540Sstevel@tonic-gate addr[-2] = (size_t)raddr; 12550Sstevel@tonic-gate addr[-1] = rsize; 12560Sstevel@tonic-gate 12570Sstevel@tonic-gate return (addr); 12580Sstevel@tonic-gate } 12590Sstevel@tonic-gate 12600Sstevel@tonic-gate static void 12610Sstevel@tonic-gate kfreea(void *addr) 12620Sstevel@tonic-gate { 12630Sstevel@tonic-gate size_t size; 12640Sstevel@tonic-gate 12650Sstevel@tonic-gate if (!((uintptr_t)addr & PAGEOFFSET) && (size = getctgsz(addr))) { 12660Sstevel@tonic-gate contig_free(addr, size); 12670Sstevel@tonic-gate } else { 12680Sstevel@tonic-gate size_t *saddr = addr; 12690Sstevel@tonic-gate if (saddr[-4] == 0) 12700Sstevel@tonic-gate vmem_free((vmem_t *)saddr[-3], (void *)saddr[-2], 12710Sstevel@tonic-gate saddr[-1]); 12720Sstevel@tonic-gate else 12730Sstevel@tonic-gate kmem_cache_free((kmem_cache_t *)saddr[-4], 12740Sstevel@tonic-gate (void *)saddr[-2]); 12750Sstevel@tonic-gate } 12760Sstevel@tonic-gate } 12770Sstevel@tonic-gate 12780Sstevel@tonic-gate /* 12790Sstevel@tonic-gate * This should actually be called i_ddi_dma_mem_alloc. There should 12800Sstevel@tonic-gate * also be an i_ddi_pio_mem_alloc. i_ddi_dma_mem_alloc should call 12810Sstevel@tonic-gate * through the device tree with the DDI_CTLOPS_DMA_ALIGN ctl ops to 12820Sstevel@tonic-gate * get alignment requirements for DMA memory. i_ddi_pio_mem_alloc 12830Sstevel@tonic-gate * should use DDI_CTLOPS_PIO_ALIGN. Since we only have i_ddi_mem_alloc 12840Sstevel@tonic-gate * so far which is used for both, DMA and PIO, we have to use the DMA 12850Sstevel@tonic-gate * ctl ops to make everybody happy. 12860Sstevel@tonic-gate */ 12870Sstevel@tonic-gate /*ARGSUSED*/ 12880Sstevel@tonic-gate int 12890Sstevel@tonic-gate i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attr, 12900Sstevel@tonic-gate size_t length, int cansleep, int streaming, 12910Sstevel@tonic-gate ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, 12920Sstevel@tonic-gate size_t *real_length, ddi_acc_hdl_t *ap) 12930Sstevel@tonic-gate { 12940Sstevel@tonic-gate caddr_t a; 12950Sstevel@tonic-gate int iomin; 12960Sstevel@tonic-gate ddi_acc_impl_t *iap; 12970Sstevel@tonic-gate int physcontig = 0; 12980Sstevel@tonic-gate pgcnt_t npages; 12990Sstevel@tonic-gate pgcnt_t minctg; 13000Sstevel@tonic-gate 13010Sstevel@tonic-gate /* 13020Sstevel@tonic-gate * Check legality of arguments 13030Sstevel@tonic-gate */ 13040Sstevel@tonic-gate if (length == 0 || kaddrp == NULL || attr == NULL) { 13050Sstevel@tonic-gate return (DDI_FAILURE); 13060Sstevel@tonic-gate } 13070Sstevel@tonic-gate if (attr->dma_attr_minxfer == 0 || attr->dma_attr_align == 0 || 13080Sstevel@tonic-gate (attr->dma_attr_align & (attr->dma_attr_align - 1)) || 13090Sstevel@tonic-gate (attr->dma_attr_minxfer & (attr->dma_attr_minxfer - 1))) { 13100Sstevel@tonic-gate return (DDI_FAILURE); 13110Sstevel@tonic-gate } 13120Sstevel@tonic-gate 13130Sstevel@tonic-gate /* 13140Sstevel@tonic-gate * figure out most restrictive alignment requirement 13150Sstevel@tonic-gate */ 13160Sstevel@tonic-gate iomin = attr->dma_attr_minxfer; 13170Sstevel@tonic-gate iomin = maxbit(iomin, attr->dma_attr_align); 13180Sstevel@tonic-gate if (iomin == 0) 13190Sstevel@tonic-gate return (DDI_FAILURE); 13200Sstevel@tonic-gate 13210Sstevel@tonic-gate ASSERT((iomin & (iomin - 1)) == 0); 13220Sstevel@tonic-gate 13230Sstevel@tonic-gate 13240Sstevel@tonic-gate /* 13250Sstevel@tonic-gate * Determine if we need to satisfy the request for physically 13260Sstevel@tonic-gate * contiguous memory or alignments larger than pagesize. 13270Sstevel@tonic-gate */ 13280Sstevel@tonic-gate npages = btopr(length + attr->dma_attr_align); 13290Sstevel@tonic-gate minctg = howmany(npages, attr->dma_attr_sgllen); 13300Sstevel@tonic-gate 13310Sstevel@tonic-gate if (minctg > 1) { 13320Sstevel@tonic-gate uint64_t pfnseg = attr->dma_attr_seg >> PAGESHIFT; 13330Sstevel@tonic-gate /* 13340Sstevel@tonic-gate * verify that the minimum contig requirement for the 13350Sstevel@tonic-gate * actual length does not cross segment boundary. 13360Sstevel@tonic-gate */ 13370Sstevel@tonic-gate length = P2ROUNDUP_TYPED(length, attr->dma_attr_minxfer, 13380Sstevel@tonic-gate size_t); 13390Sstevel@tonic-gate npages = btopr(length); 13400Sstevel@tonic-gate minctg = howmany(npages, attr->dma_attr_sgllen); 13410Sstevel@tonic-gate if (minctg > pfnseg + 1) 13420Sstevel@tonic-gate return (DDI_FAILURE); 13430Sstevel@tonic-gate physcontig = 1; 13440Sstevel@tonic-gate } else { 13450Sstevel@tonic-gate length = P2ROUNDUP_TYPED(length, iomin, size_t); 13460Sstevel@tonic-gate } 13470Sstevel@tonic-gate 13480Sstevel@tonic-gate /* 13490Sstevel@tonic-gate * Allocate the requested amount from the system. 13500Sstevel@tonic-gate */ 13510Sstevel@tonic-gate a = kalloca(length, iomin, cansleep, physcontig, attr); 13520Sstevel@tonic-gate 13530Sstevel@tonic-gate if ((*kaddrp = a) == NULL) 13540Sstevel@tonic-gate return (DDI_FAILURE); 13550Sstevel@tonic-gate 13560Sstevel@tonic-gate if (real_length) { 13570Sstevel@tonic-gate *real_length = length; 13580Sstevel@tonic-gate } 13590Sstevel@tonic-gate if (ap) { 13600Sstevel@tonic-gate /* 13610Sstevel@tonic-gate * initialize access handle 13620Sstevel@tonic-gate */ 13630Sstevel@tonic-gate iap = (ddi_acc_impl_t *)ap->ah_platform_private; 13640Sstevel@tonic-gate iap->ahi_acc_attr |= DDI_ACCATTR_CPU_VADDR; 13650Sstevel@tonic-gate impl_acc_hdl_init(ap); 13660Sstevel@tonic-gate } 13670Sstevel@tonic-gate return (DDI_SUCCESS); 13680Sstevel@tonic-gate } 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate /* 13710Sstevel@tonic-gate * covert old DMA limits structure to DMA attribute structure 13720Sstevel@tonic-gate * and continue 13730Sstevel@tonic-gate */ 13740Sstevel@tonic-gate int 13750Sstevel@tonic-gate i_ddi_mem_alloc_lim(dev_info_t *dip, ddi_dma_lim_t *limits, 13760Sstevel@tonic-gate size_t length, int cansleep, int streaming, 13770Sstevel@tonic-gate ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, 13780Sstevel@tonic-gate uint_t *real_length, ddi_acc_hdl_t *ap) 13790Sstevel@tonic-gate { 13800Sstevel@tonic-gate ddi_dma_attr_t dma_attr, *attrp; 13810Sstevel@tonic-gate size_t rlen; 13820Sstevel@tonic-gate int ret; 13830Sstevel@tonic-gate 13840Sstevel@tonic-gate if (limits == NULL) { 13850Sstevel@tonic-gate return (DDI_FAILURE); 13860Sstevel@tonic-gate } 13870Sstevel@tonic-gate 13880Sstevel@tonic-gate /* 13890Sstevel@tonic-gate * set up DMA attribute structure to pass to i_ddi_mem_alloc() 13900Sstevel@tonic-gate */ 13910Sstevel@tonic-gate attrp = &dma_attr; 13920Sstevel@tonic-gate attrp->dma_attr_version = DMA_ATTR_V0; 13930Sstevel@tonic-gate attrp->dma_attr_addr_lo = (uint64_t)limits->dlim_addr_lo; 13940Sstevel@tonic-gate attrp->dma_attr_addr_hi = (uint64_t)limits->dlim_addr_hi; 13950Sstevel@tonic-gate attrp->dma_attr_count_max = (uint64_t)limits->dlim_ctreg_max; 13960Sstevel@tonic-gate attrp->dma_attr_align = 1; 13970Sstevel@tonic-gate attrp->dma_attr_burstsizes = (uint_t)limits->dlim_burstsizes; 13980Sstevel@tonic-gate attrp->dma_attr_minxfer = (uint32_t)limits->dlim_minxfer; 13990Sstevel@tonic-gate attrp->dma_attr_maxxfer = (uint64_t)limits->dlim_reqsize; 14000Sstevel@tonic-gate attrp->dma_attr_seg = (uint64_t)limits->dlim_adreg_max; 14010Sstevel@tonic-gate attrp->dma_attr_sgllen = limits->dlim_sgllen; 14020Sstevel@tonic-gate attrp->dma_attr_granular = (uint32_t)limits->dlim_granular; 14030Sstevel@tonic-gate attrp->dma_attr_flags = 0; 14040Sstevel@tonic-gate 14050Sstevel@tonic-gate ret = i_ddi_mem_alloc(dip, attrp, length, cansleep, streaming, 14060Sstevel@tonic-gate accattrp, kaddrp, &rlen, ap); 14070Sstevel@tonic-gate if (ret == DDI_SUCCESS) { 14080Sstevel@tonic-gate if (real_length) 14090Sstevel@tonic-gate *real_length = (uint_t)rlen; 14100Sstevel@tonic-gate } 14110Sstevel@tonic-gate return (ret); 14120Sstevel@tonic-gate } 14130Sstevel@tonic-gate 14140Sstevel@tonic-gate /* ARGSUSED */ 14150Sstevel@tonic-gate void 14160Sstevel@tonic-gate i_ddi_mem_free(caddr_t kaddr, int stream) 14170Sstevel@tonic-gate { 14180Sstevel@tonic-gate kfreea(kaddr); 14190Sstevel@tonic-gate } 14200Sstevel@tonic-gate 14210Sstevel@tonic-gate /* 14220Sstevel@tonic-gate * Access Barriers 14230Sstevel@tonic-gate * 14240Sstevel@tonic-gate */ 14250Sstevel@tonic-gate /*ARGSUSED*/ 14260Sstevel@tonic-gate int 14270Sstevel@tonic-gate i_ddi_ontrap(ddi_acc_handle_t hp) 14280Sstevel@tonic-gate { 14290Sstevel@tonic-gate return (DDI_FAILURE); 14300Sstevel@tonic-gate } 14310Sstevel@tonic-gate 14320Sstevel@tonic-gate /*ARGSUSED*/ 14330Sstevel@tonic-gate void 14340Sstevel@tonic-gate i_ddi_notrap(ddi_acc_handle_t hp) 14350Sstevel@tonic-gate { 14360Sstevel@tonic-gate } 14370Sstevel@tonic-gate 14380Sstevel@tonic-gate 14390Sstevel@tonic-gate /* 14400Sstevel@tonic-gate * Misc Functions 14410Sstevel@tonic-gate */ 14420Sstevel@tonic-gate 14430Sstevel@tonic-gate /* 14440Sstevel@tonic-gate * Implementation instance override functions 14450Sstevel@tonic-gate * 14460Sstevel@tonic-gate * No override on i86pc 14470Sstevel@tonic-gate */ 14480Sstevel@tonic-gate /*ARGSUSED*/ 14490Sstevel@tonic-gate uint_t 14500Sstevel@tonic-gate impl_assign_instance(dev_info_t *dip) 14510Sstevel@tonic-gate { 14520Sstevel@tonic-gate return ((uint_t)-1); 14530Sstevel@tonic-gate } 14540Sstevel@tonic-gate 14550Sstevel@tonic-gate /*ARGSUSED*/ 14560Sstevel@tonic-gate int 14570Sstevel@tonic-gate impl_keep_instance(dev_info_t *dip) 14580Sstevel@tonic-gate { 14590Sstevel@tonic-gate return (DDI_FAILURE); 14600Sstevel@tonic-gate } 14610Sstevel@tonic-gate 14620Sstevel@tonic-gate /*ARGSUSED*/ 14630Sstevel@tonic-gate int 14640Sstevel@tonic-gate impl_free_instance(dev_info_t *dip) 14650Sstevel@tonic-gate { 14660Sstevel@tonic-gate return (DDI_FAILURE); 14670Sstevel@tonic-gate } 14680Sstevel@tonic-gate 14690Sstevel@tonic-gate /*ARGSUSED*/ 14700Sstevel@tonic-gate int 14710Sstevel@tonic-gate impl_check_cpu(dev_info_t *devi) 14720Sstevel@tonic-gate { 14730Sstevel@tonic-gate return (DDI_SUCCESS); 14740Sstevel@tonic-gate } 14750Sstevel@tonic-gate 14760Sstevel@tonic-gate /* 14770Sstevel@tonic-gate * Referenced in common/cpr_driver.c: Power off machine. 14780Sstevel@tonic-gate * Don't know how to power off i86pc. 14790Sstevel@tonic-gate */ 14800Sstevel@tonic-gate void 14810Sstevel@tonic-gate arch_power_down() 14820Sstevel@tonic-gate {} 14830Sstevel@tonic-gate 14840Sstevel@tonic-gate /* 14850Sstevel@tonic-gate * Copy name to property_name, since name 14860Sstevel@tonic-gate * is in the low address range below kernelbase. 14870Sstevel@tonic-gate */ 14880Sstevel@tonic-gate static void 14890Sstevel@tonic-gate copy_boot_str(const char *boot_str, char *kern_str, int len) 14900Sstevel@tonic-gate { 14910Sstevel@tonic-gate int i = 0; 14920Sstevel@tonic-gate 14930Sstevel@tonic-gate while (i < len - 1 && boot_str[i] != '\0') { 14940Sstevel@tonic-gate kern_str[i] = boot_str[i]; 14950Sstevel@tonic-gate i++; 14960Sstevel@tonic-gate } 14970Sstevel@tonic-gate 14980Sstevel@tonic-gate kern_str[i] = 0; /* null terminate */ 14990Sstevel@tonic-gate if (boot_str[i] != '\0') 15000Sstevel@tonic-gate cmn_err(CE_WARN, 15010Sstevel@tonic-gate "boot property string is truncated to %s", kern_str); 15020Sstevel@tonic-gate } 15030Sstevel@tonic-gate 15040Sstevel@tonic-gate static void 15050Sstevel@tonic-gate get_boot_properties(void) 15060Sstevel@tonic-gate { 15070Sstevel@tonic-gate extern char hw_provider[]; 15080Sstevel@tonic-gate dev_info_t *devi; 15090Sstevel@tonic-gate char *name; 15100Sstevel@tonic-gate int length; 15110Sstevel@tonic-gate char property_name[50], property_val[50]; 15120Sstevel@tonic-gate void *bop_staging_area; 15130Sstevel@tonic-gate 15140Sstevel@tonic-gate bop_staging_area = kmem_zalloc(MMU_PAGESIZE, KM_NOSLEEP); 15150Sstevel@tonic-gate 15160Sstevel@tonic-gate /* 15170Sstevel@tonic-gate * Import "root" properties from the boot. 15180Sstevel@tonic-gate * 15190Sstevel@tonic-gate * We do this by invoking BOP_NEXTPROP until the list 15200Sstevel@tonic-gate * is completely copied in. 15210Sstevel@tonic-gate */ 15220Sstevel@tonic-gate 15230Sstevel@tonic-gate devi = ddi_root_node(); 15240Sstevel@tonic-gate for (name = BOP_NEXTPROP(bootops, ""); /* get first */ 15250Sstevel@tonic-gate name; /* NULL => DONE */ 15260Sstevel@tonic-gate name = BOP_NEXTPROP(bootops, name)) { /* get next */ 15270Sstevel@tonic-gate 15280Sstevel@tonic-gate /* copy string to memory above kernelbase */ 15290Sstevel@tonic-gate copy_boot_str(name, property_name, 50); 15300Sstevel@tonic-gate 15310Sstevel@tonic-gate /* 15320Sstevel@tonic-gate * Skip vga properties. They will be picked up later 15330Sstevel@tonic-gate * by get_vga_properties. 15340Sstevel@tonic-gate */ 15350Sstevel@tonic-gate if (strcmp(property_name, "display-edif-block") == 0 || 15360Sstevel@tonic-gate strcmp(property_name, "display-edif-id") == 0) { 15370Sstevel@tonic-gate continue; 15380Sstevel@tonic-gate } 15390Sstevel@tonic-gate 15400Sstevel@tonic-gate length = BOP_GETPROPLEN(bootops, property_name); 15410Sstevel@tonic-gate if (length == 0) 15420Sstevel@tonic-gate continue; 15430Sstevel@tonic-gate if (length > MMU_PAGESIZE) { 15440Sstevel@tonic-gate cmn_err(CE_NOTE, 15450Sstevel@tonic-gate "boot property %s longer than 0x%x, ignored\n", 15460Sstevel@tonic-gate property_name, MMU_PAGESIZE); 15470Sstevel@tonic-gate continue; 15480Sstevel@tonic-gate } 15490Sstevel@tonic-gate BOP_GETPROP(bootops, property_name, bop_staging_area); 15500Sstevel@tonic-gate 15510Sstevel@tonic-gate /* 15520Sstevel@tonic-gate * special properties: 15530Sstevel@tonic-gate * si-machine, si-hw-provider 15540Sstevel@tonic-gate * goes to kernel data structures. 15550Sstevel@tonic-gate * bios-boot-device and stdout 15560Sstevel@tonic-gate * goes to hardware property list so it may show up 15570Sstevel@tonic-gate * in the prtconf -vp output. This is needed by 15580Sstevel@tonic-gate * Install/Upgrade. Once we fix install upgrade, 15590Sstevel@tonic-gate * this can be taken out. 15600Sstevel@tonic-gate */ 15610Sstevel@tonic-gate if (strcmp(name, "si-machine") == 0) { 15620Sstevel@tonic-gate (void) strncpy(utsname.machine, bop_staging_area, 15630Sstevel@tonic-gate SYS_NMLN); 15640Sstevel@tonic-gate utsname.machine[SYS_NMLN - 1] = (char)NULL; 15650Sstevel@tonic-gate } else if (strcmp(name, "si-hw-provider") == 0) { 15660Sstevel@tonic-gate (void) strncpy(hw_provider, bop_staging_area, SYS_NMLN); 15670Sstevel@tonic-gate hw_provider[SYS_NMLN - 1] = (char)NULL; 15680Sstevel@tonic-gate } else if (strcmp(name, "bios-boot-device") == 0) { 15690Sstevel@tonic-gate copy_boot_str(bop_staging_area, property_val, 50); 15700Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, devi, 15710Sstevel@tonic-gate property_name, property_val); 15720Sstevel@tonic-gate } else if (strcmp(name, "stdout") == 0) { 15730Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, 15740Sstevel@tonic-gate property_name, *((int *)bop_staging_area)); 15750Sstevel@tonic-gate } else { 15760Sstevel@tonic-gate /* Property type unknown, use old prop interface */ 15770Sstevel@tonic-gate (void) e_ddi_prop_create(DDI_DEV_T_NONE, devi, 15780Sstevel@tonic-gate DDI_PROP_CANSLEEP, property_name, bop_staging_area, 15790Sstevel@tonic-gate length); 15800Sstevel@tonic-gate } 15810Sstevel@tonic-gate } 15820Sstevel@tonic-gate 15830Sstevel@tonic-gate kmem_free(bop_staging_area, MMU_PAGESIZE); 15840Sstevel@tonic-gate } 15850Sstevel@tonic-gate 15860Sstevel@tonic-gate static void 15870Sstevel@tonic-gate get_vga_properties(void) 15880Sstevel@tonic-gate { 15890Sstevel@tonic-gate dev_info_t *devi; 15900Sstevel@tonic-gate major_t major; 15910Sstevel@tonic-gate char *name; 15920Sstevel@tonic-gate int length; 15930Sstevel@tonic-gate char property_val[50]; 15940Sstevel@tonic-gate void *bop_staging_area; 15950Sstevel@tonic-gate 15960Sstevel@tonic-gate major = ddi_name_to_major("vgatext"); 15970Sstevel@tonic-gate if (major == (major_t)-1) 15980Sstevel@tonic-gate return; 15990Sstevel@tonic-gate devi = devnamesp[major].dn_head; 16000Sstevel@tonic-gate if (devi == NULL) 16010Sstevel@tonic-gate return; 16020Sstevel@tonic-gate 16030Sstevel@tonic-gate bop_staging_area = kmem_zalloc(MMU_PAGESIZE, KM_SLEEP); 16040Sstevel@tonic-gate 16050Sstevel@tonic-gate /* 16060Sstevel@tonic-gate * Import "vga" properties from the boot. 16070Sstevel@tonic-gate */ 16080Sstevel@tonic-gate name = "display-edif-block"; 16090Sstevel@tonic-gate length = BOP_GETPROPLEN(bootops, name); 16100Sstevel@tonic-gate if (length > 0 && length < MMU_PAGESIZE) { 16110Sstevel@tonic-gate BOP_GETPROP(bootops, name, bop_staging_area); 16120Sstevel@tonic-gate (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE, 16130Sstevel@tonic-gate devi, name, bop_staging_area, length); 16140Sstevel@tonic-gate } 16150Sstevel@tonic-gate 16160Sstevel@tonic-gate /* 16170Sstevel@tonic-gate * kdmconfig is also looking for display-type and 16180Sstevel@tonic-gate * video-adapter-type. We default to color and svga. 16190Sstevel@tonic-gate * 16200Sstevel@tonic-gate * Could it be "monochrome", "vga"? 16210Sstevel@tonic-gate * Nah, you've got to come to the 21st century... 16220Sstevel@tonic-gate * And you can set monitor type manually in kdmconfig 16230Sstevel@tonic-gate * if you are really an old junky. 16240Sstevel@tonic-gate */ 16250Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 16260Sstevel@tonic-gate devi, "display-type", "color"); 16270Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 16280Sstevel@tonic-gate devi, "video-adapter-type", "svga"); 16290Sstevel@tonic-gate 16300Sstevel@tonic-gate name = "display-edif-id"; 16310Sstevel@tonic-gate length = BOP_GETPROPLEN(bootops, name); 16320Sstevel@tonic-gate if (length > 0 && length < MMU_PAGESIZE) { 16330Sstevel@tonic-gate BOP_GETPROP(bootops, name, bop_staging_area); 16340Sstevel@tonic-gate copy_boot_str(bop_staging_area, property_val, length); 16350Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 16360Sstevel@tonic-gate devi, name, property_val); 16370Sstevel@tonic-gate } 16380Sstevel@tonic-gate 16390Sstevel@tonic-gate kmem_free(bop_staging_area, MMU_PAGESIZE); 16400Sstevel@tonic-gate } 16410Sstevel@tonic-gate 16420Sstevel@tonic-gate 16430Sstevel@tonic-gate /* 16440Sstevel@tonic-gate * This is temporary, but absolutely necessary. If we are being 16450Sstevel@tonic-gate * booted with a device tree created by the DevConf project's bootconf 16460Sstevel@tonic-gate * program, then we have device information nodes that reflect 16470Sstevel@tonic-gate * reality. At this point in time in the Solaris release schedule, the 16480Sstevel@tonic-gate * kernel drivers aren't prepared for reality. They still depend on their 16490Sstevel@tonic-gate * own ad-hoc interpretations of the properties created when their .conf 16500Sstevel@tonic-gate * files were interpreted. These drivers use an "ignore-hardware-nodes" 16510Sstevel@tonic-gate * property to prevent them from using the nodes passed up from the bootconf 16520Sstevel@tonic-gate * device tree. 16530Sstevel@tonic-gate * 16540Sstevel@tonic-gate * Trying to assemble root file system drivers as we are booting from 16550Sstevel@tonic-gate * devconf will fail if the kernel driver is basing its name_addr's on the 16560Sstevel@tonic-gate * psuedo-node device info while the bootpath passed up from bootconf is using 16570Sstevel@tonic-gate * reality-based name_addrs. We help the boot along in this case by 16580Sstevel@tonic-gate * looking at the pre-bootconf bootpath and determining if we would have 16590Sstevel@tonic-gate * successfully matched if that had been the bootpath we had chosen. 16600Sstevel@tonic-gate * 16610Sstevel@tonic-gate * Note that we only even perform this extra check if we've booted 16620Sstevel@tonic-gate * using bootconf's 1275 compliant bootpath, this is the boot device, and 16630Sstevel@tonic-gate * we're trying to match the name_addr specified in the 1275 bootpath. 16640Sstevel@tonic-gate */ 16650Sstevel@tonic-gate 16660Sstevel@tonic-gate #define MAXCOMPONENTLEN 32 16670Sstevel@tonic-gate 16680Sstevel@tonic-gate int 16690Sstevel@tonic-gate x86_old_bootpath_name_addr_match(dev_info_t *cdip, char *caddr, char *naddr) 16700Sstevel@tonic-gate { 16710Sstevel@tonic-gate /* 16720Sstevel@tonic-gate * There are multiple criteria to be met before we can even 16730Sstevel@tonic-gate * consider allowing a name_addr match here. 16740Sstevel@tonic-gate * 16750Sstevel@tonic-gate * 1) We must have been booted such that the bootconf program 16760Sstevel@tonic-gate * created device tree nodes and properties. This can be 16770Sstevel@tonic-gate * determined by examining the 'bootpath' property. This 16780Sstevel@tonic-gate * property will be a non-null string iff bootconf was 16790Sstevel@tonic-gate * involved in the boot. 16800Sstevel@tonic-gate * 16810Sstevel@tonic-gate * 2) The module that we want to match must be the boot device. 16820Sstevel@tonic-gate * 16830Sstevel@tonic-gate * 3) The instance of the module we are thinking of letting be 16840Sstevel@tonic-gate * our match must be ignoring hardware nodes. 16850Sstevel@tonic-gate * 16860Sstevel@tonic-gate * 4) The name_addr we want to match must be the name_addr 16870Sstevel@tonic-gate * specified in the 1275 bootpath. 16880Sstevel@tonic-gate */ 16890Sstevel@tonic-gate static char bootdev_module[MAXCOMPONENTLEN]; 16900Sstevel@tonic-gate static char bootdev_oldmod[MAXCOMPONENTLEN]; 16910Sstevel@tonic-gate static char bootdev_newaddr[MAXCOMPONENTLEN]; 16920Sstevel@tonic-gate static char bootdev_oldaddr[MAXCOMPONENTLEN]; 16930Sstevel@tonic-gate static int quickexit; 16940Sstevel@tonic-gate 16950Sstevel@tonic-gate char *daddr; 16960Sstevel@tonic-gate int dlen; 16970Sstevel@tonic-gate 16980Sstevel@tonic-gate char *lkupname; 16990Sstevel@tonic-gate int rv = DDI_FAILURE; 17000Sstevel@tonic-gate 17010Sstevel@tonic-gate if ((ddi_getlongprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 17020Sstevel@tonic-gate "devconf-addr", (caddr_t)&daddr, &dlen) == DDI_PROP_SUCCESS) && 17030Sstevel@tonic-gate (ddi_getprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 17040Sstevel@tonic-gate "ignore-hardware-nodes", -1) != -1)) { 17050Sstevel@tonic-gate if (strcmp(daddr, caddr) == 0) { 17060Sstevel@tonic-gate return (DDI_SUCCESS); 17070Sstevel@tonic-gate } 17080Sstevel@tonic-gate } 17090Sstevel@tonic-gate 17100Sstevel@tonic-gate if (quickexit) 17110Sstevel@tonic-gate return (rv); 17120Sstevel@tonic-gate 17130Sstevel@tonic-gate if (bootdev_module[0] == '\0') { 17140Sstevel@tonic-gate char *addrp, *eoaddrp; 17150Sstevel@tonic-gate char *busp, *modp, *atp; 17160Sstevel@tonic-gate char *bp1275, *bp; 17170Sstevel@tonic-gate int bp1275len, bplen; 17180Sstevel@tonic-gate 17190Sstevel@tonic-gate bp1275 = bp = addrp = eoaddrp = busp = modp = atp = NULL; 17200Sstevel@tonic-gate 17210Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, 17220Sstevel@tonic-gate ddi_root_node(), 0, "bootpath", 17230Sstevel@tonic-gate (caddr_t)&bp1275, &bp1275len) != DDI_PROP_SUCCESS || 17240Sstevel@tonic-gate bp1275len <= 1) { 17250Sstevel@tonic-gate /* 17260Sstevel@tonic-gate * We didn't boot from bootconf so we never need to 17270Sstevel@tonic-gate * do any special matches. 17280Sstevel@tonic-gate */ 17290Sstevel@tonic-gate quickexit = 1; 17300Sstevel@tonic-gate if (bp1275) 17310Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 17320Sstevel@tonic-gate return (rv); 17330Sstevel@tonic-gate } 17340Sstevel@tonic-gate 17350Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, 17360Sstevel@tonic-gate ddi_root_node(), 0, "boot-path", 17370Sstevel@tonic-gate (caddr_t)&bp, &bplen) != DDI_PROP_SUCCESS || bplen <= 1) { 17380Sstevel@tonic-gate /* 17390Sstevel@tonic-gate * No fallback position for matching. This is 17400Sstevel@tonic-gate * certainly unexpected, but we'll handle it 17410Sstevel@tonic-gate * just in case. 17420Sstevel@tonic-gate */ 17430Sstevel@tonic-gate quickexit = 1; 17440Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 17450Sstevel@tonic-gate if (bp) 17460Sstevel@tonic-gate kmem_free(bp, bplen); 17470Sstevel@tonic-gate return (rv); 17480Sstevel@tonic-gate } 17490Sstevel@tonic-gate 17500Sstevel@tonic-gate /* 17510Sstevel@tonic-gate * Determine boot device module and 1275 name_addr 17520Sstevel@tonic-gate * 17530Sstevel@tonic-gate * bootpath assumed to be of the form /bus/module@name_addr 17540Sstevel@tonic-gate */ 17550Sstevel@tonic-gate if (busp = strchr(bp1275, '/')) { 17560Sstevel@tonic-gate if (modp = strchr(busp + 1, '/')) { 17570Sstevel@tonic-gate if (atp = strchr(modp + 1, '@')) { 17580Sstevel@tonic-gate *atp = '\0'; 17590Sstevel@tonic-gate addrp = atp + 1; 17600Sstevel@tonic-gate if (eoaddrp = strchr(addrp, '/')) 17610Sstevel@tonic-gate *eoaddrp = '\0'; 17620Sstevel@tonic-gate } 17630Sstevel@tonic-gate } 17640Sstevel@tonic-gate } 17650Sstevel@tonic-gate 17660Sstevel@tonic-gate if (modp && addrp) { 17670Sstevel@tonic-gate (void) strncpy(bootdev_module, modp + 1, 17680Sstevel@tonic-gate MAXCOMPONENTLEN); 17690Sstevel@tonic-gate bootdev_module[MAXCOMPONENTLEN - 1] = '\0'; 17700Sstevel@tonic-gate 17710Sstevel@tonic-gate (void) strncpy(bootdev_newaddr, addrp, MAXCOMPONENTLEN); 17720Sstevel@tonic-gate bootdev_newaddr[MAXCOMPONENTLEN - 1] = '\0'; 17730Sstevel@tonic-gate } else { 17740Sstevel@tonic-gate quickexit = 1; 17750Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 17760Sstevel@tonic-gate kmem_free(bp, bplen); 17770Sstevel@tonic-gate return (rv); 17780Sstevel@tonic-gate } 17790Sstevel@tonic-gate 17800Sstevel@tonic-gate /* 17810Sstevel@tonic-gate * Determine fallback name_addr 17820Sstevel@tonic-gate * 17830Sstevel@tonic-gate * 10/3/96 - Also save fallback module name because it 17840Sstevel@tonic-gate * might actually be different than the current module 17850Sstevel@tonic-gate * name. E.G., ISA pnp drivers have new names. 17860Sstevel@tonic-gate * 17870Sstevel@tonic-gate * bootpath assumed to be of the form /bus/module@name_addr 17880Sstevel@tonic-gate */ 17890Sstevel@tonic-gate addrp = NULL; 17900Sstevel@tonic-gate if (busp = strchr(bp, '/')) { 17910Sstevel@tonic-gate if (modp = strchr(busp + 1, '/')) { 17920Sstevel@tonic-gate if (atp = strchr(modp + 1, '@')) { 17930Sstevel@tonic-gate *atp = '\0'; 17940Sstevel@tonic-gate addrp = atp + 1; 17950Sstevel@tonic-gate if (eoaddrp = strchr(addrp, '/')) 17960Sstevel@tonic-gate *eoaddrp = '\0'; 17970Sstevel@tonic-gate } 17980Sstevel@tonic-gate } 17990Sstevel@tonic-gate } 18000Sstevel@tonic-gate 18010Sstevel@tonic-gate if (modp && addrp) { 18020Sstevel@tonic-gate (void) strncpy(bootdev_oldmod, modp + 1, 18030Sstevel@tonic-gate MAXCOMPONENTLEN); 18040Sstevel@tonic-gate bootdev_module[MAXCOMPONENTLEN - 1] = '\0'; 18050Sstevel@tonic-gate 18060Sstevel@tonic-gate (void) strncpy(bootdev_oldaddr, addrp, MAXCOMPONENTLEN); 18070Sstevel@tonic-gate bootdev_oldaddr[MAXCOMPONENTLEN - 1] = '\0'; 18080Sstevel@tonic-gate } 18090Sstevel@tonic-gate 18100Sstevel@tonic-gate /* Free up the bootpath storage now that we're done with it. */ 18110Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 18120Sstevel@tonic-gate kmem_free(bp, bplen); 18130Sstevel@tonic-gate 18140Sstevel@tonic-gate if (bootdev_oldaddr[0] == '\0') { 18150Sstevel@tonic-gate quickexit = 1; 18160Sstevel@tonic-gate return (rv); 18170Sstevel@tonic-gate } 18180Sstevel@tonic-gate } 18190Sstevel@tonic-gate 18200Sstevel@tonic-gate if (((lkupname = ddi_get_name(cdip)) != NULL) && 18210Sstevel@tonic-gate (strcmp(bootdev_module, lkupname) == 0 || 18220Sstevel@tonic-gate strcmp(bootdev_oldmod, lkupname) == 0) && 18230Sstevel@tonic-gate ((ddi_getprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 18240Sstevel@tonic-gate "ignore-hardware-nodes", -1) != -1) || 18250Sstevel@tonic-gate ignore_hardware_nodes) && 18260Sstevel@tonic-gate strcmp(bootdev_newaddr, caddr) == 0 && 18270Sstevel@tonic-gate strcmp(bootdev_oldaddr, naddr) == 0) { 18280Sstevel@tonic-gate rv = DDI_SUCCESS; 18290Sstevel@tonic-gate } 18300Sstevel@tonic-gate 18310Sstevel@tonic-gate return (rv); 18320Sstevel@tonic-gate } 18330Sstevel@tonic-gate 18340Sstevel@tonic-gate /* 18350Sstevel@tonic-gate * Perform a copy from a memory mapped device (whose devinfo pointer is devi) 18360Sstevel@tonic-gate * separately mapped at devaddr in the kernel to a kernel buffer at kaddr. 18370Sstevel@tonic-gate */ 18380Sstevel@tonic-gate /*ARGSUSED*/ 18390Sstevel@tonic-gate int 18400Sstevel@tonic-gate e_ddi_copyfromdev(dev_info_t *devi, 18410Sstevel@tonic-gate off_t off, const void *devaddr, void *kaddr, size_t len) 18420Sstevel@tonic-gate { 18430Sstevel@tonic-gate bcopy(devaddr, kaddr, len); 18440Sstevel@tonic-gate return (0); 18450Sstevel@tonic-gate } 18460Sstevel@tonic-gate 18470Sstevel@tonic-gate /* 18480Sstevel@tonic-gate * Perform a copy to a memory mapped device (whose devinfo pointer is devi) 18490Sstevel@tonic-gate * separately mapped at devaddr in the kernel from a kernel buffer at kaddr. 18500Sstevel@tonic-gate */ 18510Sstevel@tonic-gate /*ARGSUSED*/ 18520Sstevel@tonic-gate int 18530Sstevel@tonic-gate e_ddi_copytodev(dev_info_t *devi, 18540Sstevel@tonic-gate off_t off, const void *kaddr, void *devaddr, size_t len) 18550Sstevel@tonic-gate { 18560Sstevel@tonic-gate bcopy(kaddr, devaddr, len); 18570Sstevel@tonic-gate return (0); 18580Sstevel@tonic-gate } 18590Sstevel@tonic-gate 18600Sstevel@tonic-gate 18610Sstevel@tonic-gate static int 18620Sstevel@tonic-gate poke_mem(peekpoke_ctlops_t *in_args) 18630Sstevel@tonic-gate { 18640Sstevel@tonic-gate int err = DDI_SUCCESS; 18650Sstevel@tonic-gate on_trap_data_t otd; 18660Sstevel@tonic-gate 18670Sstevel@tonic-gate /* Set up protected environment. */ 18680Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 18690Sstevel@tonic-gate switch (in_args->size) { 18700Sstevel@tonic-gate case sizeof (uint8_t): 18710Sstevel@tonic-gate *(uint8_t *)(in_args->dev_addr) = 18720Sstevel@tonic-gate *(uint8_t *)in_args->host_addr; 18730Sstevel@tonic-gate break; 18740Sstevel@tonic-gate 18750Sstevel@tonic-gate case sizeof (uint16_t): 18760Sstevel@tonic-gate *(uint16_t *)(in_args->dev_addr) = 18770Sstevel@tonic-gate *(uint16_t *)in_args->host_addr; 18780Sstevel@tonic-gate break; 18790Sstevel@tonic-gate 18800Sstevel@tonic-gate case sizeof (uint32_t): 18810Sstevel@tonic-gate *(uint32_t *)(in_args->dev_addr) = 18820Sstevel@tonic-gate *(uint32_t *)in_args->host_addr; 18830Sstevel@tonic-gate break; 18840Sstevel@tonic-gate 18850Sstevel@tonic-gate case sizeof (uint64_t): 18860Sstevel@tonic-gate *(uint64_t *)(in_args->dev_addr) = 18870Sstevel@tonic-gate *(uint64_t *)in_args->host_addr; 18880Sstevel@tonic-gate break; 18890Sstevel@tonic-gate 18900Sstevel@tonic-gate default: 18910Sstevel@tonic-gate err = DDI_FAILURE; 18920Sstevel@tonic-gate break; 18930Sstevel@tonic-gate } 18940Sstevel@tonic-gate } else 18950Sstevel@tonic-gate err = DDI_FAILURE; 18960Sstevel@tonic-gate 18970Sstevel@tonic-gate /* Take down protected environment. */ 18980Sstevel@tonic-gate no_trap(); 18990Sstevel@tonic-gate 19000Sstevel@tonic-gate return (err); 19010Sstevel@tonic-gate } 19020Sstevel@tonic-gate 19030Sstevel@tonic-gate 19040Sstevel@tonic-gate static int 19050Sstevel@tonic-gate peek_mem(peekpoke_ctlops_t *in_args) 19060Sstevel@tonic-gate { 19070Sstevel@tonic-gate int err = DDI_SUCCESS; 19080Sstevel@tonic-gate on_trap_data_t otd; 19090Sstevel@tonic-gate 19100Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 19110Sstevel@tonic-gate switch (in_args->size) { 19120Sstevel@tonic-gate case sizeof (uint8_t): 19130Sstevel@tonic-gate *(uint8_t *)in_args->host_addr = 19140Sstevel@tonic-gate *(uint8_t *)in_args->dev_addr; 19150Sstevel@tonic-gate break; 19160Sstevel@tonic-gate 19170Sstevel@tonic-gate case sizeof (uint16_t): 19180Sstevel@tonic-gate *(uint16_t *)in_args->host_addr = 19190Sstevel@tonic-gate *(uint16_t *)in_args->dev_addr; 19200Sstevel@tonic-gate break; 19210Sstevel@tonic-gate 19220Sstevel@tonic-gate case sizeof (uint32_t): 19230Sstevel@tonic-gate *(uint32_t *)in_args->host_addr = 19240Sstevel@tonic-gate *(uint32_t *)in_args->dev_addr; 19250Sstevel@tonic-gate break; 19260Sstevel@tonic-gate 19270Sstevel@tonic-gate case sizeof (uint64_t): 19280Sstevel@tonic-gate *(uint64_t *)in_args->host_addr = 19290Sstevel@tonic-gate *(uint64_t *)in_args->dev_addr; 19300Sstevel@tonic-gate break; 19310Sstevel@tonic-gate 19320Sstevel@tonic-gate default: 19330Sstevel@tonic-gate err = DDI_FAILURE; 19340Sstevel@tonic-gate break; 19350Sstevel@tonic-gate } 19360Sstevel@tonic-gate } else 19370Sstevel@tonic-gate err = DDI_FAILURE; 19380Sstevel@tonic-gate 19390Sstevel@tonic-gate no_trap(); 19400Sstevel@tonic-gate return (err); 19410Sstevel@tonic-gate } 19420Sstevel@tonic-gate 19430Sstevel@tonic-gate 19440Sstevel@tonic-gate /* 19450Sstevel@tonic-gate * This is called only to process peek/poke when the DIP is NULL. 19460Sstevel@tonic-gate * Assume that this is for memory, as nexi take care of device safe accesses. 19470Sstevel@tonic-gate */ 19480Sstevel@tonic-gate int 19490Sstevel@tonic-gate peekpoke_mem(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args) 19500Sstevel@tonic-gate { 19510Sstevel@tonic-gate return (cmd == DDI_CTLOPS_PEEK ? peek_mem(in_args) : poke_mem(in_args)); 19520Sstevel@tonic-gate } 19530Sstevel@tonic-gate 19540Sstevel@tonic-gate void 19550Sstevel@tonic-gate impl_setup_ddi(void) 19560Sstevel@tonic-gate { 19570Sstevel@tonic-gate dev_info_t *xdip, *isa_dip; 19580Sstevel@tonic-gate rd_existing_t rd_mem_prop; 19590Sstevel@tonic-gate int err; 19600Sstevel@tonic-gate 19610Sstevel@tonic-gate ndi_devi_alloc_sleep(ddi_root_node(), "ramdisk", 19620Sstevel@tonic-gate (dnode_t)DEVI_SID_NODEID, &xdip); 19630Sstevel@tonic-gate 19640Sstevel@tonic-gate (void) BOP_GETPROP(bootops, 19650Sstevel@tonic-gate "ramdisk_start", (void *)&ramdisk_start); 19660Sstevel@tonic-gate (void) BOP_GETPROP(bootops, 19670Sstevel@tonic-gate "ramdisk_end", (void *)&ramdisk_end); 19680Sstevel@tonic-gate 19690Sstevel@tonic-gate rd_mem_prop.phys = ramdisk_start; 19700Sstevel@tonic-gate rd_mem_prop.size = ramdisk_end - ramdisk_start + 1; 19710Sstevel@tonic-gate 19720Sstevel@tonic-gate (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE, xdip, 19730Sstevel@tonic-gate RD_EXISTING_PROP_NAME, (uchar_t *)&rd_mem_prop, 19740Sstevel@tonic-gate sizeof (rd_mem_prop)); 19750Sstevel@tonic-gate err = ndi_devi_bind_driver(xdip, 0); 19760Sstevel@tonic-gate ASSERT(err == 0); 19770Sstevel@tonic-gate 19780Sstevel@tonic-gate /* isa node */ 19790Sstevel@tonic-gate ndi_devi_alloc_sleep(ddi_root_node(), "isa", 19800Sstevel@tonic-gate (dnode_t)DEVI_SID_NODEID, &isa_dip); 19810Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, isa_dip, 19820Sstevel@tonic-gate "device_type", "isa"); 19830Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, isa_dip, 19840Sstevel@tonic-gate "bus-type", "isa"); 19850Sstevel@tonic-gate (void) ndi_devi_bind_driver(isa_dip, 0); 19860Sstevel@tonic-gate 19870Sstevel@tonic-gate /* 19880Sstevel@tonic-gate * Read in the properties from the boot. 19890Sstevel@tonic-gate */ 19900Sstevel@tonic-gate get_boot_properties(); 19910Sstevel@tonic-gate 19920Sstevel@tonic-gate /* do bus dependent probes. */ 19930Sstevel@tonic-gate impl_bus_initialprobe(); 19940Sstevel@tonic-gate 19950Sstevel@tonic-gate /* not framebuffer should be enumerated, if present */ 19960Sstevel@tonic-gate get_vga_properties(); 19970Sstevel@tonic-gate } 19980Sstevel@tonic-gate 19990Sstevel@tonic-gate dev_t 20000Sstevel@tonic-gate getrootdev(void) 20010Sstevel@tonic-gate { 20020Sstevel@tonic-gate /* 20030Sstevel@tonic-gate * Precedence given to rootdev if set in /etc/system 20040Sstevel@tonic-gate */ 20050Sstevel@tonic-gate if (root_is_svm) { 20060Sstevel@tonic-gate return (ddi_pathname_to_dev_t(svm_bootpath)); 20070Sstevel@tonic-gate } 20080Sstevel@tonic-gate 20090Sstevel@tonic-gate /* 20100Sstevel@tonic-gate * Usually rootfs.bo_name is initialized by the 20110Sstevel@tonic-gate * the bootpath property from bootenv.rc, but 20120Sstevel@tonic-gate * defaults to "/ramdisk:a" otherwise. 20130Sstevel@tonic-gate */ 20140Sstevel@tonic-gate return (ddi_pathname_to_dev_t(rootfs.bo_name)); 20150Sstevel@tonic-gate } 20160Sstevel@tonic-gate 20170Sstevel@tonic-gate static struct bus_probe { 20180Sstevel@tonic-gate struct bus_probe *next; 20190Sstevel@tonic-gate void (*probe)(int); 20200Sstevel@tonic-gate } *bus_probes; 20210Sstevel@tonic-gate 20220Sstevel@tonic-gate void 20230Sstevel@tonic-gate impl_bus_add_probe(void (*func)(int)) 20240Sstevel@tonic-gate { 20250Sstevel@tonic-gate struct bus_probe *probe; 20260Sstevel@tonic-gate 20270Sstevel@tonic-gate probe = kmem_alloc(sizeof (*probe), KM_SLEEP); 20280Sstevel@tonic-gate probe->next = bus_probes; 20290Sstevel@tonic-gate probe->probe = func; 20300Sstevel@tonic-gate bus_probes = probe; 20310Sstevel@tonic-gate } 20320Sstevel@tonic-gate 20330Sstevel@tonic-gate /*ARGSUSED*/ 20340Sstevel@tonic-gate void 20350Sstevel@tonic-gate impl_bus_delete_probe(void (*func)(int)) 20360Sstevel@tonic-gate { 20370Sstevel@tonic-gate struct bus_probe *prev = NULL; 20380Sstevel@tonic-gate struct bus_probe *probe = bus_probes; 20390Sstevel@tonic-gate 20400Sstevel@tonic-gate while (probe) { 20410Sstevel@tonic-gate if (probe->probe == func) 20420Sstevel@tonic-gate break; 20430Sstevel@tonic-gate prev = probe; 20440Sstevel@tonic-gate probe = probe->next; 20450Sstevel@tonic-gate } 20460Sstevel@tonic-gate 20470Sstevel@tonic-gate if (probe == NULL) 20480Sstevel@tonic-gate return; 20490Sstevel@tonic-gate 20500Sstevel@tonic-gate if (prev) 20510Sstevel@tonic-gate prev->next = probe->next; 20520Sstevel@tonic-gate else 20530Sstevel@tonic-gate bus_probes = probe->next; 20540Sstevel@tonic-gate 20550Sstevel@tonic-gate kmem_free(probe, sizeof (struct bus_probe)); 20560Sstevel@tonic-gate } 20570Sstevel@tonic-gate 20580Sstevel@tonic-gate /* 20590Sstevel@tonic-gate * impl_bus_initialprobe 20600Sstevel@tonic-gate * Modload the prom simulator, then let it probe to verify existence 20610Sstevel@tonic-gate * and type of PCI support. 20620Sstevel@tonic-gate */ 20630Sstevel@tonic-gate static void 20640Sstevel@tonic-gate impl_bus_initialprobe(void) 20650Sstevel@tonic-gate { 20660Sstevel@tonic-gate struct bus_probe *probe; 20670Sstevel@tonic-gate 20680Sstevel@tonic-gate /* load modules to install bus probes */ 20690Sstevel@tonic-gate if (modload("misc", "pci_autoconfig") < 0) { 20700Sstevel@tonic-gate cmn_err(CE_PANIC, "failed to load misc/pci_autoconfig"); 20710Sstevel@tonic-gate } 20720Sstevel@tonic-gate 20730Sstevel@tonic-gate probe = bus_probes; 20740Sstevel@tonic-gate while (probe) { 20750Sstevel@tonic-gate /* run the probe function */ 20760Sstevel@tonic-gate (*probe->probe)(0); 20770Sstevel@tonic-gate probe = probe->next; 20780Sstevel@tonic-gate } 20790Sstevel@tonic-gate } 20800Sstevel@tonic-gate 20810Sstevel@tonic-gate /* 20820Sstevel@tonic-gate * impl_bus_reprobe 20830Sstevel@tonic-gate * Reprogram devices not set up by firmware. 20840Sstevel@tonic-gate */ 20850Sstevel@tonic-gate static void 20860Sstevel@tonic-gate impl_bus_reprobe(void) 20870Sstevel@tonic-gate { 20880Sstevel@tonic-gate struct bus_probe *probe; 20890Sstevel@tonic-gate 20900Sstevel@tonic-gate probe = bus_probes; 20910Sstevel@tonic-gate while (probe) { 20920Sstevel@tonic-gate /* run the probe function */ 20930Sstevel@tonic-gate (*probe->probe)(1); 20940Sstevel@tonic-gate probe = probe->next; 20950Sstevel@tonic-gate } 20960Sstevel@tonic-gate } 2097