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 5*1865Sdilpreet * Common Development and Distribution License (the "License"). 6*1865Sdilpreet * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*1865Sdilpreet * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /* 290Sstevel@tonic-gate * sun4 specific DDI implementation 300Sstevel@tonic-gate */ 310Sstevel@tonic-gate #include <sys/cpuvar.h> 320Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 330Sstevel@tonic-gate #include <sys/machsystm.h> 340Sstevel@tonic-gate #include <sys/sunndi.h> 350Sstevel@tonic-gate #include <sys/sysmacros.h> 360Sstevel@tonic-gate #include <sys/ontrap.h> 370Sstevel@tonic-gate #include <vm/seg_kmem.h> 380Sstevel@tonic-gate #include <sys/membar.h> 390Sstevel@tonic-gate #include <sys/dditypes.h> 400Sstevel@tonic-gate #include <sys/ndifm.h> 410Sstevel@tonic-gate #include <sys/fm/io/ddi.h> 420Sstevel@tonic-gate #include <sys/ivintr.h> 430Sstevel@tonic-gate #include <sys/bootconf.h> 440Sstevel@tonic-gate #include <sys/conf.h> 450Sstevel@tonic-gate #include <sys/ethernet.h> 460Sstevel@tonic-gate #include <sys/idprom.h> 470Sstevel@tonic-gate #include <sys/promif.h> 480Sstevel@tonic-gate #include <sys/prom_plat.h> 490Sstevel@tonic-gate #include <sys/systeminfo.h> 500Sstevel@tonic-gate #include <sys/fpu/fpusystm.h> 510Sstevel@tonic-gate #include <sys/vm.h> 520Sstevel@tonic-gate #include <sys/fs/dv_node.h> 530Sstevel@tonic-gate #include <sys/fs/snode.h> 540Sstevel@tonic-gate #include <sys/ddi_isa.h> 550Sstevel@tonic-gate 560Sstevel@tonic-gate dev_info_t *get_intr_parent(dev_info_t *, dev_info_t *, 57693Sgovinda ddi_intr_handle_impl_t *); 580Sstevel@tonic-gate #pragma weak get_intr_parent 590Sstevel@tonic-gate 600Sstevel@tonic-gate int process_intr_ops(dev_info_t *, dev_info_t *, ddi_intr_op_t, 610Sstevel@tonic-gate ddi_intr_handle_impl_t *, void *); 620Sstevel@tonic-gate #pragma weak process_intr_ops 630Sstevel@tonic-gate 640Sstevel@tonic-gate void cells_1275_copy(prop_1275_cell_t *, prop_1275_cell_t *, int32_t); 650Sstevel@tonic-gate prop_1275_cell_t *cells_1275_cmp(prop_1275_cell_t *, prop_1275_cell_t *, 660Sstevel@tonic-gate int32_t len); 670Sstevel@tonic-gate #pragma weak cells_1275_copy 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * Wrapper for ddi_prop_lookup_int_array(). 710Sstevel@tonic-gate * This is handy because it returns the prop length in 720Sstevel@tonic-gate * bytes which is what most of the callers require. 730Sstevel@tonic-gate */ 740Sstevel@tonic-gate 750Sstevel@tonic-gate static int 760Sstevel@tonic-gate get_prop_int_array(dev_info_t *di, char *pname, int **pval, uint_t *plen) 770Sstevel@tonic-gate { 780Sstevel@tonic-gate int ret; 790Sstevel@tonic-gate 800Sstevel@tonic-gate if ((ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, di, 810Sstevel@tonic-gate DDI_PROP_DONTPASS, pname, pval, plen)) == DDI_PROP_SUCCESS) { 820Sstevel@tonic-gate *plen = (*plen) * (uint_t)sizeof (int); 830Sstevel@tonic-gate } 840Sstevel@tonic-gate return (ret); 850Sstevel@tonic-gate } 860Sstevel@tonic-gate 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * SECTION: DDI Node Configuration 890Sstevel@tonic-gate */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * init_regspec_64: 930Sstevel@tonic-gate * 940Sstevel@tonic-gate * If the parent #size-cells is 2, convert the upa-style or 950Sstevel@tonic-gate * safari-style reg property from 2-size cells to 1 size cell 960Sstevel@tonic-gate * format, ignoring the size_hi, which must be zero for devices. 970Sstevel@tonic-gate * (It won't be zero in the memory list properties in the memory 980Sstevel@tonic-gate * nodes, but that doesn't matter here.) 990Sstevel@tonic-gate */ 1000Sstevel@tonic-gate struct ddi_parent_private_data * 1010Sstevel@tonic-gate init_regspec_64(dev_info_t *dip) 1020Sstevel@tonic-gate { 1030Sstevel@tonic-gate struct ddi_parent_private_data *pd; 1040Sstevel@tonic-gate dev_info_t *parent; 1050Sstevel@tonic-gate int size_cells; 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate /* 1080Sstevel@tonic-gate * If there are no "reg"s in the child node, return. 1090Sstevel@tonic-gate */ 1100Sstevel@tonic-gate pd = ddi_get_parent_data(dip); 1110Sstevel@tonic-gate if ((pd == NULL) || (pd->par_nreg == 0)) { 1120Sstevel@tonic-gate return (pd); 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate parent = ddi_get_parent(dip); 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate size_cells = ddi_prop_get_int(DDI_DEV_T_ANY, parent, 1170Sstevel@tonic-gate DDI_PROP_DONTPASS, "#size-cells", 1); 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate if (size_cells != 1) { 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate int n, j; 1220Sstevel@tonic-gate struct regspec *irp; 1230Sstevel@tonic-gate struct reg_64 { 1240Sstevel@tonic-gate uint_t addr_hi, addr_lo, size_hi, size_lo; 1250Sstevel@tonic-gate }; 1260Sstevel@tonic-gate struct reg_64 *r64_rp; 1270Sstevel@tonic-gate struct regspec *rp; 1280Sstevel@tonic-gate uint_t len = 0; 1290Sstevel@tonic-gate int *reg_prop; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate ASSERT(size_cells == 2); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate /* 1340Sstevel@tonic-gate * We already looked the property up once before if 1350Sstevel@tonic-gate * pd is non-NULL. 1360Sstevel@tonic-gate */ 1370Sstevel@tonic-gate (void) ddi_prop_lookup_int_array(DDI_DEV_T_ANY, dip, 1380Sstevel@tonic-gate DDI_PROP_DONTPASS, OBP_REG, ®_prop, &len); 1390Sstevel@tonic-gate ASSERT(len != 0); 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate n = sizeof (struct reg_64) / sizeof (int); 1420Sstevel@tonic-gate n = len / n; 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate /* 1450Sstevel@tonic-gate * We're allocating a buffer the size of the PROM's property, 1460Sstevel@tonic-gate * but we're only using a smaller portion when we assign it 1470Sstevel@tonic-gate * to a regspec. We do this so that in the 1480Sstevel@tonic-gate * impl_ddi_sunbus_removechild function, we will 1490Sstevel@tonic-gate * always free the right amount of memory. 1500Sstevel@tonic-gate */ 1510Sstevel@tonic-gate irp = rp = (struct regspec *)reg_prop; 1520Sstevel@tonic-gate r64_rp = (struct reg_64 *)pd->par_reg; 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate for (j = 0; j < n; ++j, ++rp, ++r64_rp) { 1550Sstevel@tonic-gate ASSERT(r64_rp->size_hi == 0); 1560Sstevel@tonic-gate rp->regspec_bustype = r64_rp->addr_hi; 1570Sstevel@tonic-gate rp->regspec_addr = r64_rp->addr_lo; 1580Sstevel@tonic-gate rp->regspec_size = r64_rp->size_lo; 1590Sstevel@tonic-gate } 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate ddi_prop_free((void *)pd->par_reg); 1620Sstevel@tonic-gate pd->par_nreg = n; 1630Sstevel@tonic-gate pd->par_reg = irp; 1640Sstevel@tonic-gate } 1650Sstevel@tonic-gate return (pd); 1660Sstevel@tonic-gate } 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate /* 1690Sstevel@tonic-gate * Create a ddi_parent_private_data structure from the ddi properties of 1700Sstevel@tonic-gate * the dev_info node. 1710Sstevel@tonic-gate * 1720Sstevel@tonic-gate * The "reg" is required if the driver wishes to create mappings on behalf 1730Sstevel@tonic-gate * of the device. The "reg" property is assumed to be a list of at least 1740Sstevel@tonic-gate * one triplet 1750Sstevel@tonic-gate * 1760Sstevel@tonic-gate * <bustype, address, size>*1 1770Sstevel@tonic-gate * 1780Sstevel@tonic-gate * The "interrupt" property is no longer part of parent private data on 1790Sstevel@tonic-gate * sun4u. The interrupt parent is may not be the device tree parent. 1800Sstevel@tonic-gate * 1810Sstevel@tonic-gate * The "ranges" property describes the mapping of child addresses to parent 1820Sstevel@tonic-gate * addresses. 1830Sstevel@tonic-gate * 1840Sstevel@tonic-gate * N.B. struct rangespec is defined for the following default values: 1850Sstevel@tonic-gate * parent child 1860Sstevel@tonic-gate * #address-cells 2 2 1870Sstevel@tonic-gate * #size-cells 1 1 1880Sstevel@tonic-gate * This function doesn't deal with non-default cells and will not create 1890Sstevel@tonic-gate * ranges in such cases. 1900Sstevel@tonic-gate */ 1910Sstevel@tonic-gate void 1920Sstevel@tonic-gate make_ddi_ppd(dev_info_t *child, struct ddi_parent_private_data **ppd) 1930Sstevel@tonic-gate { 1940Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 1950Sstevel@tonic-gate int *reg_prop, *rng_prop; 1960Sstevel@tonic-gate uint_t reg_len = 0, rng_len = 0; 1970Sstevel@tonic-gate dev_info_t *parent; 1980Sstevel@tonic-gate int parent_addr_cells, parent_size_cells; 1990Sstevel@tonic-gate int child_addr_cells, child_size_cells; 2000Sstevel@tonic-gate 2010Sstevel@tonic-gate *ppd = pdptr = kmem_zalloc(sizeof (*pdptr), KM_SLEEP); 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate /* 2040Sstevel@tonic-gate * root node has no parent private data, so *ppd should 2050Sstevel@tonic-gate * be initialized for naming to work properly. 2060Sstevel@tonic-gate */ 2070Sstevel@tonic-gate if ((parent = ddi_get_parent(child)) == NULL) 2080Sstevel@tonic-gate return; 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate /* 2110Sstevel@tonic-gate * Set reg field of parent data from "reg" property 2120Sstevel@tonic-gate */ 2130Sstevel@tonic-gate if ((get_prop_int_array(child, OBP_REG, ®_prop, ®_len) 2140Sstevel@tonic-gate == DDI_PROP_SUCCESS) && (reg_len != 0)) { 2150Sstevel@tonic-gate pdptr->par_nreg = (int)(reg_len / sizeof (struct regspec)); 2160Sstevel@tonic-gate pdptr->par_reg = (struct regspec *)reg_prop; 2170Sstevel@tonic-gate } 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate /* 2200Sstevel@tonic-gate * "ranges" property ... 2210Sstevel@tonic-gate * 2220Sstevel@tonic-gate * This function does not handle cases where #address-cells != 2 2230Sstevel@tonic-gate * and * min(parent, child) #size-cells != 1 (see bugid 4211124). 2240Sstevel@tonic-gate * 2250Sstevel@tonic-gate * Nexus drivers with such exceptions (e.g. pci ranges) 2260Sstevel@tonic-gate * should either create a separate function for handling 2270Sstevel@tonic-gate * ranges or not use parent private data to store ranges. 2280Sstevel@tonic-gate */ 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate /* root node has no ranges */ 2310Sstevel@tonic-gate if ((parent = ddi_get_parent(child)) == NULL) 2320Sstevel@tonic-gate return; 2330Sstevel@tonic-gate 2340Sstevel@tonic-gate child_addr_cells = ddi_prop_get_int(DDI_DEV_T_ANY, child, 2350Sstevel@tonic-gate DDI_PROP_DONTPASS, "#address-cells", 2); 2360Sstevel@tonic-gate child_size_cells = ddi_prop_get_int(DDI_DEV_T_ANY, child, 2370Sstevel@tonic-gate DDI_PROP_DONTPASS, "#size-cells", 1); 2380Sstevel@tonic-gate parent_addr_cells = ddi_prop_get_int(DDI_DEV_T_ANY, parent, 2390Sstevel@tonic-gate DDI_PROP_DONTPASS, "#address-cells", 2); 2400Sstevel@tonic-gate parent_size_cells = ddi_prop_get_int(DDI_DEV_T_ANY, parent, 2410Sstevel@tonic-gate DDI_PROP_DONTPASS, "#size-cells", 1); 2420Sstevel@tonic-gate if (child_addr_cells != 2 || parent_addr_cells != 2 || 2430Sstevel@tonic-gate (child_size_cells != 1 && parent_size_cells != 1)) { 2440Sstevel@tonic-gate NDI_CONFIG_DEBUG((CE_NOTE, "!ranges not made in parent data; " 2450Sstevel@tonic-gate "#address-cells or #size-cells have non-default value")); 2460Sstevel@tonic-gate return; 2470Sstevel@tonic-gate } 2480Sstevel@tonic-gate 2490Sstevel@tonic-gate if (get_prop_int_array(child, OBP_RANGES, &rng_prop, &rng_len) 2500Sstevel@tonic-gate == DDI_PROP_SUCCESS) { 2510Sstevel@tonic-gate pdptr->par_nrng = rng_len / (int)(sizeof (struct rangespec)); 2520Sstevel@tonic-gate pdptr->par_rng = (struct rangespec *)rng_prop; 2530Sstevel@tonic-gate } 2540Sstevel@tonic-gate } 2550Sstevel@tonic-gate 2560Sstevel@tonic-gate /* 2570Sstevel@tonic-gate * Free ddi_parent_private_data structure 2580Sstevel@tonic-gate */ 2590Sstevel@tonic-gate void 2600Sstevel@tonic-gate impl_free_ddi_ppd(dev_info_t *dip) 2610Sstevel@tonic-gate { 2620Sstevel@tonic-gate struct ddi_parent_private_data *pdptr = ddi_get_parent_data(dip); 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate if (pdptr == NULL) 2650Sstevel@tonic-gate return; 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate if (pdptr->par_nrng != 0) 2680Sstevel@tonic-gate ddi_prop_free((void *)pdptr->par_rng); 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate if (pdptr->par_nreg != 0) 2710Sstevel@tonic-gate ddi_prop_free((void *)pdptr->par_reg); 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate kmem_free(pdptr, sizeof (*pdptr)); 2740Sstevel@tonic-gate ddi_set_parent_data(dip, NULL); 2750Sstevel@tonic-gate } 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate /* 2780Sstevel@tonic-gate * Name a child of sun busses based on the reg spec. 2790Sstevel@tonic-gate * Handles the following properties: 2800Sstevel@tonic-gate * 2810Sstevel@tonic-gate * Property value 2820Sstevel@tonic-gate * Name type 2830Sstevel@tonic-gate * 2840Sstevel@tonic-gate * reg register spec 2850Sstevel@tonic-gate * interrupts new (bus-oriented) interrupt spec 2860Sstevel@tonic-gate * ranges range spec 2870Sstevel@tonic-gate * 2880Sstevel@tonic-gate * This may be called multiple times, independent of 2890Sstevel@tonic-gate * initchild calls. 2900Sstevel@tonic-gate */ 2910Sstevel@tonic-gate static int 2920Sstevel@tonic-gate impl_sunbus_name_child(dev_info_t *child, char *name, int namelen) 2930Sstevel@tonic-gate { 2940Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 2950Sstevel@tonic-gate struct regspec *rp; 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate /* 2980Sstevel@tonic-gate * Fill in parent-private data and this function returns to us 2990Sstevel@tonic-gate * an indication if it used "registers" to fill in the data. 3000Sstevel@tonic-gate */ 3010Sstevel@tonic-gate if (ddi_get_parent_data(child) == NULL) { 3020Sstevel@tonic-gate make_ddi_ppd(child, &pdptr); 3030Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 3040Sstevel@tonic-gate } 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate /* 3070Sstevel@tonic-gate * No reg property, return null string as address 3080Sstevel@tonic-gate * (e.g. root node) 3090Sstevel@tonic-gate */ 3100Sstevel@tonic-gate name[0] = '\0'; 3110Sstevel@tonic-gate if (sparc_pd_getnreg(child) == 0) { 3120Sstevel@tonic-gate return (DDI_SUCCESS); 3130Sstevel@tonic-gate } 3140Sstevel@tonic-gate 3150Sstevel@tonic-gate rp = sparc_pd_getreg(child, 0); 3160Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 3170Sstevel@tonic-gate rp->regspec_bustype, rp->regspec_addr); 3180Sstevel@tonic-gate return (DDI_SUCCESS); 3190Sstevel@tonic-gate } 3200Sstevel@tonic-gate 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate /* 3230Sstevel@tonic-gate * Called from the bus_ctl op of some drivers. 3240Sstevel@tonic-gate * to implement the DDI_CTLOPS_INITCHILD operation. 3250Sstevel@tonic-gate * 3260Sstevel@tonic-gate * NEW drivers should NOT use this function, but should declare 3270Sstevel@tonic-gate * there own initchild/uninitchild handlers. (This function assumes 3280Sstevel@tonic-gate * the layout of the parent private data and the format of "reg", 3290Sstevel@tonic-gate * "ranges", "interrupts" properties and that #address-cells and 3300Sstevel@tonic-gate * #size-cells of the parent bus are defined to be default values.) 3310Sstevel@tonic-gate */ 3320Sstevel@tonic-gate int 3330Sstevel@tonic-gate impl_ddi_sunbus_initchild(dev_info_t *child) 3340Sstevel@tonic-gate { 3350Sstevel@tonic-gate char name[MAXNAMELEN]; 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate (void) impl_sunbus_name_child(child, name, MAXNAMELEN); 3380Sstevel@tonic-gate ddi_set_name_addr(child, name); 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate /* 3410Sstevel@tonic-gate * Try to merge .conf node. If successful, return failure to 3420Sstevel@tonic-gate * remove this child. 3430Sstevel@tonic-gate */ 3440Sstevel@tonic-gate if ((ndi_dev_is_persistent_node(child) == 0) && 3450Sstevel@tonic-gate (ndi_merge_node(child, impl_sunbus_name_child) == DDI_SUCCESS)) { 3460Sstevel@tonic-gate impl_ddi_sunbus_removechild(child); 3470Sstevel@tonic-gate return (DDI_FAILURE); 3480Sstevel@tonic-gate } 3490Sstevel@tonic-gate return (DDI_SUCCESS); 3500Sstevel@tonic-gate } 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate /* 3530Sstevel@tonic-gate * A better name for this function would be impl_ddi_sunbus_uninitchild() 3540Sstevel@tonic-gate * It does not remove the child, it uninitializes it, reclaiming the 3550Sstevel@tonic-gate * resources taken by impl_ddi_sunbus_initchild. 3560Sstevel@tonic-gate */ 3570Sstevel@tonic-gate void 3580Sstevel@tonic-gate impl_ddi_sunbus_removechild(dev_info_t *dip) 3590Sstevel@tonic-gate { 3600Sstevel@tonic-gate impl_free_ddi_ppd(dip); 3610Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 3620Sstevel@tonic-gate /* 3630Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form 3640Sstevel@tonic-gate */ 3650Sstevel@tonic-gate impl_rem_dev_props(dip); 3660Sstevel@tonic-gate } 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate /* 3690Sstevel@tonic-gate * SECTION: DDI Interrupt 3700Sstevel@tonic-gate */ 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate void 3730Sstevel@tonic-gate cells_1275_copy(prop_1275_cell_t *from, prop_1275_cell_t *to, int32_t len) 3740Sstevel@tonic-gate { 3750Sstevel@tonic-gate int i; 3760Sstevel@tonic-gate for (i = 0; i < len; i++) 3770Sstevel@tonic-gate *to = *from; 3780Sstevel@tonic-gate } 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate prop_1275_cell_t * 3810Sstevel@tonic-gate cells_1275_cmp(prop_1275_cell_t *cell1, prop_1275_cell_t *cell2, int32_t len) 3820Sstevel@tonic-gate { 3830Sstevel@tonic-gate prop_1275_cell_t *match_cell = 0; 3840Sstevel@tonic-gate int32_t i; 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate for (i = 0; i < len; i++) 3870Sstevel@tonic-gate if (cell1[i] != cell2[i]) { 3880Sstevel@tonic-gate match_cell = &cell1[i]; 3890Sstevel@tonic-gate break; 3900Sstevel@tonic-gate } 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate return (match_cell); 3930Sstevel@tonic-gate } 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate /* 396693Sgovinda * get_intr_parent() is a generic routine that process a 1275 interrupt 397693Sgovinda * map (imap) property. This function returns a dev_info_t structure 398693Sgovinda * which claims ownership of the interrupt domain. 399693Sgovinda * It also returns the new interrupt translation within this new domain. 400693Sgovinda * If an interrupt-parent or interrupt-map property are not found, 401693Sgovinda * then we fallback to using the device tree's parent. 402693Sgovinda * 403693Sgovinda * imap entry format: 404693Sgovinda * <reg>,<interrupt>,<phandle>,<translated interrupt> 405693Sgovinda * reg - The register specification in the interrupts domain 406693Sgovinda * interrupt - The interrupt specification 407693Sgovinda * phandle - PROM handle of the device that owns the xlated interrupt domain 408693Sgovinda * translated interrupt - interrupt specifier in the parents domain 409693Sgovinda * note: <reg>,<interrupt> - The reg and interrupt can be combined to create 410693Sgovinda * a unique entry called a unit interrupt specifier. 411693Sgovinda * 412693Sgovinda * Here's the processing steps: 413693Sgovinda * step1 - If the interrupt-parent property exists, create the ispec and 414693Sgovinda * return the dip of the interrupt parent. 415693Sgovinda * step2 - Extract the interrupt-map property and the interrupt-map-mask 416693Sgovinda * If these don't exist, just return the device tree parent. 417693Sgovinda * step3 - build up the unit interrupt specifier to match against the 418693Sgovinda * interrupt map property 419693Sgovinda * step4 - Scan the interrupt-map property until a match is found 420693Sgovinda * step4a - Extract the interrupt parent 421693Sgovinda * step4b - Compare the unit interrupt specifier 4220Sstevel@tonic-gate */ 423693Sgovinda dev_info_t * 424693Sgovinda get_intr_parent(dev_info_t *pdip, dev_info_t *dip, ddi_intr_handle_impl_t *hdlp) 4250Sstevel@tonic-gate { 426693Sgovinda prop_1275_cell_t *imap, *imap_mask, *scan, *reg_p, *match_req; 427693Sgovinda int32_t imap_sz, imap_cells, imap_scan_cells, imap_mask_sz, 428693Sgovinda addr_cells, intr_cells, reg_len, i, j; 429693Sgovinda int32_t match_found = 0; 430693Sgovinda dev_info_t *intr_parent_dip = NULL; 431693Sgovinda uint32_t *intr = &hdlp->ih_vector; 432693Sgovinda uint32_t nodeid; 433693Sgovinda #ifdef DEBUG 434693Sgovinda static int debug = 0; 435693Sgovinda #endif 4360Sstevel@tonic-gate 437693Sgovinda /* 438693Sgovinda * step1 439693Sgovinda * If we have an interrupt-parent property, this property represents 440693Sgovinda * the nodeid of our interrupt parent. 441693Sgovinda */ 442693Sgovinda if ((nodeid = ddi_getprop(DDI_DEV_T_ANY, dip, 0, 443693Sgovinda "interrupt-parent", -1)) != -1) { 444693Sgovinda intr_parent_dip = e_ddi_nodeid_to_dip(nodeid); 445693Sgovinda ASSERT(intr_parent_dip); 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate /* 448693Sgovinda * Attach the interrupt parent. 449693Sgovinda * 450693Sgovinda * N.B. e_ddi_nodeid_to_dip() isn't safe under DR. 451693Sgovinda * Also, interrupt parent isn't held. This needs 452693Sgovinda * to be revisited if DR-capable platforms implement 453693Sgovinda * interrupt redirection. 454693Sgovinda */ 455693Sgovinda if (i_ddi_attach_node_hierarchy(intr_parent_dip) 456693Sgovinda != DDI_SUCCESS) { 457693Sgovinda ndi_rele_devi(intr_parent_dip); 458693Sgovinda return (NULL); 459693Sgovinda } 460693Sgovinda 461693Sgovinda return (intr_parent_dip); 462693Sgovinda } 463693Sgovinda 464693Sgovinda /* 465693Sgovinda * step2 466693Sgovinda * Get interrupt map structure from PROM property 467693Sgovinda */ 468693Sgovinda if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, DDI_PROP_DONTPASS, 469693Sgovinda "interrupt-map", (caddr_t)&imap, &imap_sz) 470693Sgovinda != DDI_PROP_SUCCESS) { 471693Sgovinda /* 472693Sgovinda * If we don't have an imap property, default to using the 473693Sgovinda * device tree. 4740Sstevel@tonic-gate */ 475693Sgovinda 476693Sgovinda ndi_hold_devi(pdip); 477693Sgovinda return (pdip); 478693Sgovinda } 479693Sgovinda 480693Sgovinda /* Get the interrupt mask property */ 481693Sgovinda if (ddi_getlongprop(DDI_DEV_T_ANY, pdip, DDI_PROP_DONTPASS, 482693Sgovinda "interrupt-map-mask", (caddr_t)&imap_mask, &imap_mask_sz) 483693Sgovinda != DDI_PROP_SUCCESS) { 484693Sgovinda /* 485693Sgovinda * If we don't find this property, we have to fail the request 486693Sgovinda * because the 1275 imap property wasn't defined correctly. 487693Sgovinda */ 488693Sgovinda ASSERT(intr_parent_dip == NULL); 489693Sgovinda goto exit2; 490693Sgovinda } 491693Sgovinda 492693Sgovinda /* Get the address cell size */ 493693Sgovinda addr_cells = ddi_getprop(DDI_DEV_T_ANY, pdip, 0, 494693Sgovinda "#address-cells", 2); 495693Sgovinda 496693Sgovinda /* Get the interrupts cell size */ 497693Sgovinda intr_cells = ddi_getprop(DDI_DEV_T_ANY, pdip, 0, 498693Sgovinda "#interrupt-cells", 1); 499693Sgovinda 500693Sgovinda /* 501693Sgovinda * step3 502693Sgovinda * Now lets build up the unit interrupt specifier e.g. reg,intr 503693Sgovinda * and apply the imap mask. match_req will hold this when we're 504693Sgovinda * through. 505693Sgovinda */ 506693Sgovinda if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "reg", 507693Sgovinda (caddr_t)®_p, ®_len) != DDI_SUCCESS) { 508693Sgovinda ASSERT(intr_parent_dip == NULL); 509693Sgovinda goto exit3; 5100Sstevel@tonic-gate } 5110Sstevel@tonic-gate 512693Sgovinda match_req = kmem_alloc(CELLS_1275_TO_BYTES(addr_cells) + 513693Sgovinda CELLS_1275_TO_BYTES(intr_cells), KM_SLEEP); 514693Sgovinda 515693Sgovinda for (i = 0; i < addr_cells; i++) 516693Sgovinda match_req[i] = (reg_p[i] & imap_mask[i]); 517693Sgovinda 518693Sgovinda for (j = 0; j < intr_cells; i++, j++) 519693Sgovinda match_req[i] = (intr[j] & imap_mask[i]); 520693Sgovinda 521693Sgovinda /* Calculate the imap size in cells */ 522693Sgovinda imap_cells = BYTES_TO_1275_CELLS(imap_sz); 523693Sgovinda 524693Sgovinda #ifdef DEBUG 525693Sgovinda if (debug) 526693Sgovinda prom_printf("reg cell size 0x%x, intr cell size 0x%x, " 527693Sgovinda "match_request 0x%p, imap 0x%p\n", addr_cells, intr_cells, 528693Sgovinda match_req, imap); 529693Sgovinda #endif 530693Sgovinda 531693Sgovinda /* 532693Sgovinda * Scan the imap property looking for a match of the interrupt unit 533693Sgovinda * specifier. This loop is rather complex since the data within the 534693Sgovinda * imap property may vary in size. 535693Sgovinda */ 536693Sgovinda for (scan = imap, imap_scan_cells = i = 0; 537693Sgovinda imap_scan_cells < imap_cells; scan += i, imap_scan_cells += i) { 538693Sgovinda int new_intr_cells; 539693Sgovinda 540693Sgovinda /* Set the index to the nodeid field */ 541693Sgovinda i = addr_cells + intr_cells; 542693Sgovinda 543693Sgovinda /* 544693Sgovinda * step4a 545693Sgovinda * Translate the nodeid field to a dip 546693Sgovinda */ 547693Sgovinda ASSERT(intr_parent_dip == NULL); 548693Sgovinda intr_parent_dip = e_ddi_nodeid_to_dip((uint_t)scan[i++]); 549693Sgovinda 550693Sgovinda ASSERT(intr_parent_dip != 0); 551693Sgovinda #ifdef DEBUG 552693Sgovinda if (debug) 553693Sgovinda prom_printf("scan 0x%p\n", scan); 554693Sgovinda #endif 555693Sgovinda /* 556693Sgovinda * The tmp_dip describes the new domain, get it's interrupt 557693Sgovinda * cell size 558693Sgovinda */ 559693Sgovinda new_intr_cells = ddi_getprop(DDI_DEV_T_ANY, intr_parent_dip, 0, 560693Sgovinda "#interrupts-cells", 1); 5610Sstevel@tonic-gate 562693Sgovinda /* 563693Sgovinda * step4b 564693Sgovinda * See if we have a match on the interrupt unit specifier 565693Sgovinda */ 566693Sgovinda if (cells_1275_cmp(match_req, scan, addr_cells + intr_cells) 567693Sgovinda == 0) { 568693Sgovinda uint32_t *intr; 569693Sgovinda 570693Sgovinda match_found = 1; 571693Sgovinda 572693Sgovinda /* 573693Sgovinda * If we have an imap parent whose not in our device 574693Sgovinda * tree path, we need to hold and install that driver. 575693Sgovinda */ 576693Sgovinda if (i_ddi_attach_node_hierarchy(intr_parent_dip) 577693Sgovinda != DDI_SUCCESS) { 578693Sgovinda ndi_rele_devi(intr_parent_dip); 579693Sgovinda intr_parent_dip = (dev_info_t *)NULL; 580693Sgovinda goto exit4; 581693Sgovinda } 5820Sstevel@tonic-gate 583693Sgovinda /* 584693Sgovinda * We need to handcraft an ispec along with a bus 585693Sgovinda * interrupt value, so we can dup it into our 586693Sgovinda * standard ispec structure. 587693Sgovinda */ 588693Sgovinda /* Extract the translated interrupt information */ 589693Sgovinda intr = kmem_alloc( 590693Sgovinda CELLS_1275_TO_BYTES(new_intr_cells), KM_SLEEP); 591693Sgovinda 592693Sgovinda for (j = 0; j < new_intr_cells; j++, i++) 593693Sgovinda intr[j] = scan[i]; 594693Sgovinda 595693Sgovinda cells_1275_copy(intr, &hdlp->ih_vector, new_intr_cells); 5960Sstevel@tonic-gate 597693Sgovinda kmem_free(intr, CELLS_1275_TO_BYTES(new_intr_cells)); 598693Sgovinda 599693Sgovinda #ifdef DEBUG 600693Sgovinda if (debug) 601693Sgovinda prom_printf("dip 0x%p\n", intr_parent_dip); 602693Sgovinda #endif 603693Sgovinda break; 604693Sgovinda } else { 605693Sgovinda #ifdef DEBUG 606693Sgovinda if (debug) 607693Sgovinda prom_printf("dip 0x%p\n", intr_parent_dip); 608693Sgovinda #endif 609693Sgovinda ndi_rele_devi(intr_parent_dip); 610693Sgovinda intr_parent_dip = NULL; 611693Sgovinda i += new_intr_cells; 6120Sstevel@tonic-gate } 6130Sstevel@tonic-gate } 6140Sstevel@tonic-gate 615693Sgovinda /* 616693Sgovinda * If we haven't found our interrupt parent at this point, fallback 617693Sgovinda * to using the device tree. 618693Sgovinda */ 619693Sgovinda if (!match_found) { 620693Sgovinda ndi_hold_devi(pdip); 621693Sgovinda ASSERT(intr_parent_dip == NULL); 622693Sgovinda intr_parent_dip = pdip; 623693Sgovinda } 624693Sgovinda 625693Sgovinda ASSERT(intr_parent_dip != NULL); 626693Sgovinda 627693Sgovinda exit4: 628693Sgovinda kmem_free(reg_p, reg_len); 629693Sgovinda kmem_free(match_req, CELLS_1275_TO_BYTES(addr_cells) + 630693Sgovinda CELLS_1275_TO_BYTES(intr_cells)); 631693Sgovinda 632693Sgovinda exit3: 633693Sgovinda kmem_free(imap_mask, imap_mask_sz); 634693Sgovinda 635693Sgovinda exit2: 636693Sgovinda kmem_free(imap, imap_sz); 637693Sgovinda 638693Sgovinda return (intr_parent_dip); 6390Sstevel@tonic-gate } 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate /* 6420Sstevel@tonic-gate * process_intr_ops: 6430Sstevel@tonic-gate * 6440Sstevel@tonic-gate * Process the interrupt op via the interrupt parent. 6450Sstevel@tonic-gate */ 6460Sstevel@tonic-gate int 6470Sstevel@tonic-gate process_intr_ops(dev_info_t *pdip, dev_info_t *rdip, ddi_intr_op_t op, 6480Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 6490Sstevel@tonic-gate { 6500Sstevel@tonic-gate int ret = DDI_FAILURE; 6510Sstevel@tonic-gate 6520Sstevel@tonic-gate if (NEXUS_HAS_INTR_OP(pdip)) { 6530Sstevel@tonic-gate ret = (*(DEVI(pdip)->devi_ops->devo_bus_ops-> 6540Sstevel@tonic-gate bus_intr_op)) (pdip, rdip, op, hdlp, result); 6550Sstevel@tonic-gate } else { 6560Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to process interrupt " 6570Sstevel@tonic-gate "for %s%d due to down-rev nexus driver %s%d", 6580Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip), 6590Sstevel@tonic-gate ddi_get_name(pdip), ddi_get_instance(pdip)); 6600Sstevel@tonic-gate } 6610Sstevel@tonic-gate 6620Sstevel@tonic-gate return (ret); 6630Sstevel@tonic-gate } 6640Sstevel@tonic-gate 665693Sgovinda /*ARGSUSED*/ 666693Sgovinda uint_t 667693Sgovinda softlevel1(caddr_t arg) 668693Sgovinda { 669693Sgovinda softint(); 670693Sgovinda return (1); 671693Sgovinda } 672693Sgovinda 673693Sgovinda /* 674693Sgovinda * indirection table, to save us some large switch statements 675693Sgovinda * NOTE: This must agree with "INTLEVEL_foo" constants in 676693Sgovinda * <sys/avintr.h> 677693Sgovinda */ 678693Sgovinda struct autovec *const vectorlist[] = { 0 }; 679693Sgovinda 680693Sgovinda /* 681693Sgovinda * This value is exported here for the functions in avintr.c 682693Sgovinda */ 683693Sgovinda const uint_t maxautovec = (sizeof (vectorlist) / sizeof (vectorlist[0])); 684693Sgovinda 685693Sgovinda /* 686693Sgovinda * Check for machine specific interrupt levels which cannot be reassigned by 687693Sgovinda * settrap(), sun4u version. 688693Sgovinda * 689693Sgovinda * sun4u does not support V8 SPARC "fast trap" handlers. 690693Sgovinda */ 691693Sgovinda /*ARGSUSED*/ 692693Sgovinda int 693693Sgovinda exclude_settrap(int lvl) 694693Sgovinda { 695693Sgovinda return (1); 696693Sgovinda } 697693Sgovinda 698693Sgovinda /* 699693Sgovinda * Check for machine specific interrupt levels which cannot have interrupt 700693Sgovinda * handlers added. We allow levels 1 through 15; level 0 is nonsense. 701693Sgovinda */ 702693Sgovinda /*ARGSUSED*/ 703693Sgovinda int 704693Sgovinda exclude_level(int lvl) 705693Sgovinda { 706693Sgovinda return ((lvl < 1) || (lvl > 15)); 707693Sgovinda } 708693Sgovinda 709693Sgovinda /* 710693Sgovinda * Wrapper functions used by New DDI interrupt framework. 711693Sgovinda */ 712693Sgovinda 713693Sgovinda /* 714693Sgovinda * i_ddi_intr_ops: 715693Sgovinda */ 716693Sgovinda int 717693Sgovinda i_ddi_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op, 718693Sgovinda ddi_intr_handle_impl_t *hdlp, void *result) 719693Sgovinda { 720693Sgovinda dev_info_t *pdip = ddi_get_parent(dip); 721693Sgovinda int ret = DDI_FAILURE; 722693Sgovinda 723693Sgovinda /* 724693Sgovinda * The following check is required to address 725693Sgovinda * one of the test case of ADDI test suite. 726693Sgovinda */ 727693Sgovinda if (pdip == NULL) 728693Sgovinda return (DDI_FAILURE); 729693Sgovinda 730693Sgovinda if (hdlp->ih_type != DDI_INTR_TYPE_FIXED) 731693Sgovinda return (process_intr_ops(pdip, rdip, op, hdlp, result)); 732693Sgovinda 733693Sgovinda if (hdlp->ih_vector == 0) 734693Sgovinda hdlp->ih_vector = i_ddi_get_inum(rdip, hdlp->ih_inum); 735693Sgovinda 736693Sgovinda if (hdlp->ih_pri == 0) 737693Sgovinda hdlp->ih_pri = i_ddi_get_intr_pri(rdip, hdlp->ih_inum); 738693Sgovinda 739693Sgovinda switch (op) { 740693Sgovinda case DDI_INTROP_ADDISR: 741693Sgovinda case DDI_INTROP_REMISR: 742693Sgovinda case DDI_INTROP_ENABLE: 743693Sgovinda case DDI_INTROP_DISABLE: 744693Sgovinda case DDI_INTROP_BLOCKENABLE: 745693Sgovinda case DDI_INTROP_BLOCKDISABLE: 746693Sgovinda /* 747693Sgovinda * Try and determine our parent and possibly an interrupt 748693Sgovinda * translation. intr parent dip returned held 749693Sgovinda */ 750693Sgovinda if ((pdip = get_intr_parent(pdip, dip, hdlp)) == NULL) 751693Sgovinda goto done; 752693Sgovinda } 753693Sgovinda 754693Sgovinda ret = process_intr_ops(pdip, rdip, op, hdlp, result); 755693Sgovinda 756693Sgovinda done: 757693Sgovinda switch (op) { 758693Sgovinda case DDI_INTROP_ADDISR: 759693Sgovinda case DDI_INTROP_REMISR: 760693Sgovinda case DDI_INTROP_ENABLE: 761693Sgovinda case DDI_INTROP_DISABLE: 762693Sgovinda case DDI_INTROP_BLOCKENABLE: 763693Sgovinda case DDI_INTROP_BLOCKDISABLE: 764693Sgovinda /* Release hold acquired in get_intr_parent() */ 765693Sgovinda if (pdip) 766693Sgovinda ndi_rele_devi(pdip); 767693Sgovinda } 768693Sgovinda 769693Sgovinda hdlp->ih_vector = 0; 770693Sgovinda 771693Sgovinda return (ret); 772693Sgovinda } 773693Sgovinda 7740Sstevel@tonic-gate /* 7750Sstevel@tonic-gate * i_ddi_add_ivintr: 7760Sstevel@tonic-gate */ 7770Sstevel@tonic-gate /*ARGSUSED*/ 7780Sstevel@tonic-gate int 7790Sstevel@tonic-gate i_ddi_add_ivintr(ddi_intr_handle_impl_t *hdlp) 7800Sstevel@tonic-gate { 7810Sstevel@tonic-gate /* Sanity check the entry we're about to add */ 7820Sstevel@tonic-gate if (GET_IVINTR(hdlp->ih_vector)) { 7830Sstevel@tonic-gate cmn_err(CE_WARN, "mondo 0x%x in use", hdlp->ih_vector); 7840Sstevel@tonic-gate return (DDI_FAILURE); 7850Sstevel@tonic-gate } 7860Sstevel@tonic-gate 7870Sstevel@tonic-gate /* 7880Sstevel@tonic-gate * If the PIL was set and is valid use it, otherwise 7890Sstevel@tonic-gate * default it to 1 7900Sstevel@tonic-gate */ 7910Sstevel@tonic-gate if ((hdlp->ih_pri < 1) || (hdlp->ih_pri > PIL_MAX)) 7920Sstevel@tonic-gate hdlp->ih_pri = 1; 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate VERIFY(add_ivintr(hdlp->ih_vector, hdlp->ih_pri, 7950Sstevel@tonic-gate (intrfunc)hdlp->ih_cb_func, hdlp->ih_cb_arg1, NULL) == 0); 7960Sstevel@tonic-gate 7970Sstevel@tonic-gate return (DDI_SUCCESS); 7980Sstevel@tonic-gate } 7990Sstevel@tonic-gate 8000Sstevel@tonic-gate /* 8010Sstevel@tonic-gate * i_ddi_rem_ivintr: 8020Sstevel@tonic-gate */ 8030Sstevel@tonic-gate /*ARGSUSED*/ 8040Sstevel@tonic-gate void 8050Sstevel@tonic-gate i_ddi_rem_ivintr(ddi_intr_handle_impl_t *hdlp) 8060Sstevel@tonic-gate { 8070Sstevel@tonic-gate rem_ivintr(hdlp->ih_vector, NULL); 8080Sstevel@tonic-gate } 8090Sstevel@tonic-gate 8100Sstevel@tonic-gate /* 811693Sgovinda * i_ddi_get_inum - Get the interrupt number property from the 812693Sgovinda * specified device. Note that this function is called only for 813693Sgovinda * the FIXED interrupt type. 814693Sgovinda */ 815693Sgovinda uint32_t 816693Sgovinda i_ddi_get_inum(dev_info_t *dip, uint_t inumber) 817693Sgovinda { 818693Sgovinda int32_t intrlen, intr_cells, max_intrs; 819693Sgovinda prop_1275_cell_t *ip, intr_sz; 820693Sgovinda uint32_t intr = 0; 821693Sgovinda 822693Sgovinda if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS | 823693Sgovinda DDI_PROP_CANSLEEP, 824693Sgovinda "interrupts", (caddr_t)&ip, &intrlen) == DDI_SUCCESS) { 825693Sgovinda 826693Sgovinda intr_cells = ddi_getprop(DDI_DEV_T_ANY, dip, 0, 827693Sgovinda "#interrupt-cells", 1); 828693Sgovinda 829693Sgovinda /* adjust for number of bytes */ 830693Sgovinda intr_sz = CELLS_1275_TO_BYTES(intr_cells); 831693Sgovinda 832693Sgovinda /* Calculate the number of interrupts */ 833693Sgovinda max_intrs = intrlen / intr_sz; 834693Sgovinda 835693Sgovinda if (inumber < max_intrs) { 836693Sgovinda prop_1275_cell_t *intrp = ip; 837693Sgovinda 838693Sgovinda /* Index into interrupt property */ 839693Sgovinda intrp += (inumber * intr_cells); 840693Sgovinda 841693Sgovinda cells_1275_copy(intrp, &intr, intr_cells); 842693Sgovinda } 843693Sgovinda 844693Sgovinda kmem_free(ip, intrlen); 845693Sgovinda } 846693Sgovinda 847693Sgovinda return (intr); 848693Sgovinda } 849693Sgovinda 850693Sgovinda /* 851693Sgovinda * i_ddi_get_intr_pri - Get the interrupt-priorities property from 852693Sgovinda * the specified device. Note that this function is called only for 853693Sgovinda * the FIXED interrupt type. 854693Sgovinda */ 855693Sgovinda uint32_t 856693Sgovinda i_ddi_get_intr_pri(dev_info_t *dip, uint_t inumber) 857693Sgovinda { 858693Sgovinda uint32_t *intr_prio_p; 859693Sgovinda uint32_t pri = 0; 860693Sgovinda int32_t i; 861693Sgovinda 862693Sgovinda /* 863693Sgovinda * Use the "interrupt-priorities" property to determine the 864693Sgovinda * the pil/ipl for the interrupt handler. 865693Sgovinda */ 866693Sgovinda if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, 867693Sgovinda "interrupt-priorities", (caddr_t)&intr_prio_p, 868693Sgovinda &i) == DDI_SUCCESS) { 869693Sgovinda if (inumber < (i / sizeof (int32_t))) 870693Sgovinda pri = intr_prio_p[inumber]; 871693Sgovinda kmem_free(intr_prio_p, i); 872693Sgovinda } 873693Sgovinda 874693Sgovinda return (pri); 875693Sgovinda } 876693Sgovinda 877693Sgovinda int 878693Sgovinda i_ddi_get_nintrs(dev_info_t *dip) 879693Sgovinda { 880693Sgovinda int32_t intrlen; 881693Sgovinda prop_1275_cell_t intr_sz; 882693Sgovinda prop_1275_cell_t *ip; 883693Sgovinda int32_t ret = 0; 884693Sgovinda 885693Sgovinda if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS | 886693Sgovinda DDI_PROP_CANSLEEP, 887693Sgovinda "interrupts", (caddr_t)&ip, &intrlen) == DDI_SUCCESS) { 888693Sgovinda 889693Sgovinda intr_sz = ddi_getprop(DDI_DEV_T_ANY, dip, 0, 890693Sgovinda "#interrupt-cells", 1); 891693Sgovinda /* adjust for number of bytes */ 892693Sgovinda intr_sz = CELLS_1275_TO_BYTES(intr_sz); 893693Sgovinda 894693Sgovinda ret = intrlen / intr_sz; 895693Sgovinda 896693Sgovinda kmem_free(ip, intrlen); 897693Sgovinda } 898693Sgovinda 899693Sgovinda return (ret); 900693Sgovinda } 901693Sgovinda 902693Sgovinda /* 9030Sstevel@tonic-gate * i_ddi_add_softint - allocate and add a soft interrupt to the system 9040Sstevel@tonic-gate */ 9050Sstevel@tonic-gate int 9060Sstevel@tonic-gate i_ddi_add_softint(ddi_softint_hdl_impl_t *hdlp) 9070Sstevel@tonic-gate { 9080Sstevel@tonic-gate uint_t rval; 9090Sstevel@tonic-gate 910568Seota if ((rval = add_softintr(hdlp->ih_pri, hdlp->ih_cb_func, 911568Seota hdlp->ih_cb_arg1)) == 0) { 9120Sstevel@tonic-gate 9130Sstevel@tonic-gate return (DDI_FAILURE); 9140Sstevel@tonic-gate } 9150Sstevel@tonic-gate 916568Seota /* use uintptr_t to suppress the gcc warning */ 917568Seota hdlp->ih_private = (void *)(uintptr_t)rval; 9180Sstevel@tonic-gate 9190Sstevel@tonic-gate return (DDI_SUCCESS); 9200Sstevel@tonic-gate } 9210Sstevel@tonic-gate 9220Sstevel@tonic-gate void 9230Sstevel@tonic-gate i_ddi_remove_softint(ddi_softint_hdl_impl_t *hdlp) 9240Sstevel@tonic-gate { 9250Sstevel@tonic-gate uint_t intr_id; 9260Sstevel@tonic-gate 9270Sstevel@tonic-gate /* disable */ 9280Sstevel@tonic-gate ASSERT(hdlp->ih_private != NULL); 929693Sgovinda 930568Seota /* use uintptr_t to suppress the gcc warning */ 931568Seota intr_id = (uint_t)(uintptr_t)hdlp->ih_private; 932693Sgovinda 9330Sstevel@tonic-gate rem_softintr(intr_id); 9340Sstevel@tonic-gate hdlp->ih_private = NULL; 9350Sstevel@tonic-gate } 9360Sstevel@tonic-gate 9370Sstevel@tonic-gate int 938278Sgovinda i_ddi_trigger_softint(ddi_softint_hdl_impl_t *hdlp, void *arg2) 9390Sstevel@tonic-gate { 9400Sstevel@tonic-gate uint_t intr_id; 9410Sstevel@tonic-gate int ret; 9420Sstevel@tonic-gate 9430Sstevel@tonic-gate ASSERT(hdlp != NULL); 9440Sstevel@tonic-gate ASSERT(hdlp->ih_private != NULL); 9450Sstevel@tonic-gate 9461009Smathue /* use uintptr_t to suppress the gcc warning */ 9471009Smathue intr_id = (uint_t)(uintptr_t)hdlp->ih_private; 9480Sstevel@tonic-gate 9490Sstevel@tonic-gate /* update the vector table for the 2nd arg */ 950278Sgovinda ret = update_softint_arg2(intr_id, arg2); 9510Sstevel@tonic-gate if (ret == DDI_SUCCESS) 9520Sstevel@tonic-gate setsoftint(intr_id); 9530Sstevel@tonic-gate 9540Sstevel@tonic-gate return (ret); 9550Sstevel@tonic-gate } 9560Sstevel@tonic-gate 9570Sstevel@tonic-gate /* ARGSUSED */ 9580Sstevel@tonic-gate int 9590Sstevel@tonic-gate i_ddi_set_softint_pri(ddi_softint_hdl_impl_t *hdlp, uint_t old_pri) 9600Sstevel@tonic-gate { 9610Sstevel@tonic-gate uint_t intr_id; 9620Sstevel@tonic-gate int ret; 9630Sstevel@tonic-gate 9640Sstevel@tonic-gate ASSERT(hdlp != NULL); 9650Sstevel@tonic-gate ASSERT(hdlp->ih_private != NULL); 9660Sstevel@tonic-gate 9671009Smathue /* use uintptr_t to suppress the gcc warning */ 9681009Smathue intr_id = (uint_t)(uintptr_t)hdlp->ih_private; 9690Sstevel@tonic-gate 9700Sstevel@tonic-gate /* update the vector table for the new priority */ 9710Sstevel@tonic-gate ret = update_softint_pri(intr_id, hdlp->ih_pri); 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate return (ret); 9740Sstevel@tonic-gate } 9750Sstevel@tonic-gate 976916Sschwartz /*ARGSUSED*/ 977916Sschwartz void 978916Sschwartz i_ddi_alloc_intr_phdl(ddi_intr_handle_impl_t *hdlp) 979916Sschwartz { 980916Sschwartz } 981916Sschwartz 982916Sschwartz /*ARGSUSED*/ 983916Sschwartz void 984916Sschwartz i_ddi_free_intr_phdl(ddi_intr_handle_impl_t *hdlp) 985916Sschwartz { 986916Sschwartz } 987916Sschwartz 9880Sstevel@tonic-gate /* 9890Sstevel@tonic-gate * SECTION: DDI Memory/DMA 9900Sstevel@tonic-gate */ 9910Sstevel@tonic-gate 9920Sstevel@tonic-gate static vmem_t *little_endian_arena; 9930Sstevel@tonic-gate static vmem_t *big_endian_arena; 9940Sstevel@tonic-gate 9950Sstevel@tonic-gate static void * 9960Sstevel@tonic-gate segkmem_alloc_le(vmem_t *vmp, size_t size, int flag) 9970Sstevel@tonic-gate { 9980Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, flag, HAT_STRUCTURE_LE, 9990Sstevel@tonic-gate segkmem_page_create, NULL)); 10000Sstevel@tonic-gate } 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate static void * 10030Sstevel@tonic-gate segkmem_alloc_be(vmem_t *vmp, size_t size, int flag) 10040Sstevel@tonic-gate { 10050Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, flag, HAT_STRUCTURE_BE, 10060Sstevel@tonic-gate segkmem_page_create, NULL)); 10070Sstevel@tonic-gate } 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate void 10100Sstevel@tonic-gate ka_init(void) 10110Sstevel@tonic-gate { 10120Sstevel@tonic-gate little_endian_arena = vmem_create("little_endian", NULL, 0, 1, 10130Sstevel@tonic-gate segkmem_alloc_le, segkmem_free, heap_arena, 0, VM_SLEEP); 10140Sstevel@tonic-gate big_endian_arena = vmem_create("big_endian", NULL, 0, 1, 10150Sstevel@tonic-gate segkmem_alloc_be, segkmem_free, heap_arena, 0, VM_SLEEP); 10160Sstevel@tonic-gate } 10170Sstevel@tonic-gate 10180Sstevel@tonic-gate /* 10190Sstevel@tonic-gate * Allocate from the system, aligned on a specific boundary. 10200Sstevel@tonic-gate * The alignment, if non-zero, must be a power of 2. 10210Sstevel@tonic-gate */ 10220Sstevel@tonic-gate static void * 10230Sstevel@tonic-gate kalloca(size_t size, size_t align, int cansleep, uint_t endian_flags) 10240Sstevel@tonic-gate { 10250Sstevel@tonic-gate size_t *addr, *raddr, rsize; 10260Sstevel@tonic-gate size_t hdrsize = 4 * sizeof (size_t); /* must be power of 2 */ 10270Sstevel@tonic-gate 10280Sstevel@tonic-gate align = MAX(align, hdrsize); 10290Sstevel@tonic-gate ASSERT((align & (align - 1)) == 0); 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate /* 10320Sstevel@tonic-gate * We need to allocate 10330Sstevel@tonic-gate * rsize = size + hdrsize + align - MIN(hdrsize, buffer_alignment) 10340Sstevel@tonic-gate * bytes to be sure we have enough freedom to satisfy the request. 10350Sstevel@tonic-gate * Since the buffer alignment depends on the request size, this is 10360Sstevel@tonic-gate * not straightforward to use directly. 10370Sstevel@tonic-gate * 10380Sstevel@tonic-gate * kmem guarantees that any allocation of a 64-byte multiple will be 10390Sstevel@tonic-gate * 64-byte aligned. Since rounding up the request could add more 10400Sstevel@tonic-gate * than we save, we compute the size with and without alignment, and 10410Sstevel@tonic-gate * use the smaller of the two. 10420Sstevel@tonic-gate */ 10430Sstevel@tonic-gate rsize = size + hdrsize + align; 10440Sstevel@tonic-gate 10450Sstevel@tonic-gate if (endian_flags == DDI_STRUCTURE_LE_ACC) { 10460Sstevel@tonic-gate raddr = vmem_alloc(little_endian_arena, rsize, 10470Sstevel@tonic-gate cansleep ? VM_SLEEP : VM_NOSLEEP); 10480Sstevel@tonic-gate } else { 10490Sstevel@tonic-gate raddr = vmem_alloc(big_endian_arena, rsize, 10500Sstevel@tonic-gate cansleep ? VM_SLEEP : VM_NOSLEEP); 10510Sstevel@tonic-gate } 10520Sstevel@tonic-gate 10530Sstevel@tonic-gate if (raddr == NULL) 10540Sstevel@tonic-gate return (NULL); 10550Sstevel@tonic-gate 10560Sstevel@tonic-gate addr = (size_t *)P2ROUNDUP((uintptr_t)raddr + hdrsize, align); 10570Sstevel@tonic-gate ASSERT((uintptr_t)addr + size - (uintptr_t)raddr <= rsize); 10580Sstevel@tonic-gate 10590Sstevel@tonic-gate addr[-3] = (size_t)endian_flags; 10600Sstevel@tonic-gate addr[-2] = (size_t)raddr; 10610Sstevel@tonic-gate addr[-1] = rsize; 10620Sstevel@tonic-gate 10630Sstevel@tonic-gate return (addr); 10640Sstevel@tonic-gate } 10650Sstevel@tonic-gate 10660Sstevel@tonic-gate static void 10670Sstevel@tonic-gate kfreea(void *addr) 10680Sstevel@tonic-gate { 10690Sstevel@tonic-gate size_t *saddr = addr; 10700Sstevel@tonic-gate 10710Sstevel@tonic-gate if (saddr[-3] == DDI_STRUCTURE_LE_ACC) 10720Sstevel@tonic-gate vmem_free(little_endian_arena, (void *)saddr[-2], saddr[-1]); 10730Sstevel@tonic-gate else 10740Sstevel@tonic-gate vmem_free(big_endian_arena, (void *)saddr[-2], saddr[-1]); 10750Sstevel@tonic-gate } 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate int 10780Sstevel@tonic-gate i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attr, 10790Sstevel@tonic-gate size_t length, int cansleep, int streaming, 10800Sstevel@tonic-gate ddi_device_acc_attr_t *accattrp, 10810Sstevel@tonic-gate caddr_t *kaddrp, size_t *real_length, ddi_acc_hdl_t *handlep) 10820Sstevel@tonic-gate { 10830Sstevel@tonic-gate caddr_t a; 10840Sstevel@tonic-gate int iomin, align; 10850Sstevel@tonic-gate uint_t endian_flags = DDI_NEVERSWAP_ACC; 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate #if defined(lint) 10880Sstevel@tonic-gate *handlep = *handlep; 10890Sstevel@tonic-gate #endif 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate /* 10920Sstevel@tonic-gate * Check legality of arguments 10930Sstevel@tonic-gate */ 10940Sstevel@tonic-gate if (length == 0 || kaddrp == NULL || attr == NULL) { 10950Sstevel@tonic-gate return (DDI_FAILURE); 10960Sstevel@tonic-gate } 10970Sstevel@tonic-gate if (attr->dma_attr_minxfer == 0 || attr->dma_attr_align == 0 || 10980Sstevel@tonic-gate (attr->dma_attr_align & (attr->dma_attr_align - 1)) || 10990Sstevel@tonic-gate (attr->dma_attr_minxfer & (attr->dma_attr_minxfer - 1))) { 11000Sstevel@tonic-gate return (DDI_FAILURE); 11010Sstevel@tonic-gate } 11020Sstevel@tonic-gate 11030Sstevel@tonic-gate /* 11040Sstevel@tonic-gate * Drivers for 64-bit capable SBus devices will encode 11050Sstevel@tonic-gate * the burtsizes for 64-bit xfers in the upper 16-bits. 11060Sstevel@tonic-gate * For DMA alignment, we use the most restrictive 11070Sstevel@tonic-gate * alignment of 32-bit and 64-bit xfers. 11080Sstevel@tonic-gate */ 11090Sstevel@tonic-gate iomin = (attr->dma_attr_burstsizes & 0xffff) | 11100Sstevel@tonic-gate ((attr->dma_attr_burstsizes >> 16) & 0xffff); 11110Sstevel@tonic-gate /* 11120Sstevel@tonic-gate * If a driver set burtsizes to 0, we give him byte alignment. 11130Sstevel@tonic-gate * Otherwise align at the burtsizes boundary. 11140Sstevel@tonic-gate */ 11150Sstevel@tonic-gate if (iomin == 0) 11160Sstevel@tonic-gate iomin = 1; 11170Sstevel@tonic-gate else 11180Sstevel@tonic-gate iomin = 1 << (ddi_fls(iomin) - 1); 11190Sstevel@tonic-gate iomin = maxbit(iomin, attr->dma_attr_minxfer); 11200Sstevel@tonic-gate iomin = maxbit(iomin, attr->dma_attr_align); 11210Sstevel@tonic-gate iomin = ddi_iomin(dip, iomin, streaming); 11220Sstevel@tonic-gate if (iomin == 0) 11230Sstevel@tonic-gate return (DDI_FAILURE); 11240Sstevel@tonic-gate 11250Sstevel@tonic-gate ASSERT((iomin & (iomin - 1)) == 0); 11260Sstevel@tonic-gate ASSERT(iomin >= attr->dma_attr_minxfer); 11270Sstevel@tonic-gate ASSERT(iomin >= attr->dma_attr_align); 11280Sstevel@tonic-gate 11290Sstevel@tonic-gate length = P2ROUNDUP(length, iomin); 11300Sstevel@tonic-gate align = iomin; 11310Sstevel@tonic-gate 11320Sstevel@tonic-gate if (accattrp != NULL) 11330Sstevel@tonic-gate endian_flags = accattrp->devacc_attr_endian_flags; 11340Sstevel@tonic-gate 11350Sstevel@tonic-gate a = kalloca(length, align, cansleep, endian_flags); 11360Sstevel@tonic-gate if ((*kaddrp = a) == 0) { 11370Sstevel@tonic-gate return (DDI_FAILURE); 11380Sstevel@tonic-gate } else { 11390Sstevel@tonic-gate if (real_length) { 11400Sstevel@tonic-gate *real_length = length; 11410Sstevel@tonic-gate } 11420Sstevel@tonic-gate if (handlep) { 11430Sstevel@tonic-gate /* 11440Sstevel@tonic-gate * assign handle information 11450Sstevel@tonic-gate */ 11460Sstevel@tonic-gate impl_acc_hdl_init(handlep); 11470Sstevel@tonic-gate } 11480Sstevel@tonic-gate return (DDI_SUCCESS); 11490Sstevel@tonic-gate } 11500Sstevel@tonic-gate } 11510Sstevel@tonic-gate 11520Sstevel@tonic-gate /* 11530Sstevel@tonic-gate * covert old DMA limits structure to DMA attribute structure 11540Sstevel@tonic-gate * and continue 11550Sstevel@tonic-gate */ 11560Sstevel@tonic-gate int 11570Sstevel@tonic-gate i_ddi_mem_alloc_lim(dev_info_t *dip, ddi_dma_lim_t *limits, 11580Sstevel@tonic-gate size_t length, int cansleep, int streaming, 11590Sstevel@tonic-gate ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, 11600Sstevel@tonic-gate uint_t *real_length, ddi_acc_hdl_t *ap) 11610Sstevel@tonic-gate { 11620Sstevel@tonic-gate ddi_dma_attr_t dma_attr, *attrp; 11630Sstevel@tonic-gate size_t rlen; 11640Sstevel@tonic-gate int ret; 11650Sstevel@tonic-gate 11660Sstevel@tonic-gate ASSERT(limits); 11670Sstevel@tonic-gate attrp = &dma_attr; 11680Sstevel@tonic-gate attrp->dma_attr_version = DMA_ATTR_V0; 11690Sstevel@tonic-gate attrp->dma_attr_addr_lo = (uint64_t)limits->dlim_addr_lo; 11700Sstevel@tonic-gate attrp->dma_attr_addr_hi = (uint64_t)limits->dlim_addr_hi; 11710Sstevel@tonic-gate attrp->dma_attr_count_max = (uint64_t)-1; 11720Sstevel@tonic-gate attrp->dma_attr_align = 1; 11730Sstevel@tonic-gate attrp->dma_attr_burstsizes = (uint_t)limits->dlim_burstsizes; 11740Sstevel@tonic-gate attrp->dma_attr_minxfer = (uint32_t)limits->dlim_minxfer; 11750Sstevel@tonic-gate attrp->dma_attr_maxxfer = (uint64_t)-1; 11760Sstevel@tonic-gate attrp->dma_attr_seg = (uint64_t)limits->dlim_cntr_max; 11770Sstevel@tonic-gate attrp->dma_attr_sgllen = 1; 11780Sstevel@tonic-gate attrp->dma_attr_granular = 1; 11790Sstevel@tonic-gate attrp->dma_attr_flags = 0; 11800Sstevel@tonic-gate 11810Sstevel@tonic-gate ret = i_ddi_mem_alloc(dip, attrp, length, cansleep, streaming, 11820Sstevel@tonic-gate accattrp, kaddrp, &rlen, ap); 11830Sstevel@tonic-gate if (ret == DDI_SUCCESS) { 11840Sstevel@tonic-gate if (real_length) 11850Sstevel@tonic-gate *real_length = (uint_t)rlen; 11860Sstevel@tonic-gate } 11870Sstevel@tonic-gate return (ret); 11880Sstevel@tonic-gate } 11890Sstevel@tonic-gate 11900Sstevel@tonic-gate /* ARGSUSED */ 11910Sstevel@tonic-gate void 11920Sstevel@tonic-gate i_ddi_mem_free(caddr_t kaddr, int stream) 11930Sstevel@tonic-gate { 11940Sstevel@tonic-gate kfreea(kaddr); 11950Sstevel@tonic-gate } 11960Sstevel@tonic-gate 11970Sstevel@tonic-gate /* 11980Sstevel@tonic-gate * SECTION: DDI Data Access 11990Sstevel@tonic-gate */ 12000Sstevel@tonic-gate 12010Sstevel@tonic-gate static uintptr_t impl_acc_hdl_id = 0; 12020Sstevel@tonic-gate 12030Sstevel@tonic-gate /* 12040Sstevel@tonic-gate * access handle allocator 12050Sstevel@tonic-gate */ 12060Sstevel@tonic-gate ddi_acc_hdl_t * 12070Sstevel@tonic-gate impl_acc_hdl_get(ddi_acc_handle_t hdl) 12080Sstevel@tonic-gate { 12090Sstevel@tonic-gate /* 12100Sstevel@tonic-gate * Extract the access handle address from the DDI implemented 12110Sstevel@tonic-gate * access handle 12120Sstevel@tonic-gate */ 12130Sstevel@tonic-gate return (&((ddi_acc_impl_t *)hdl)->ahi_common); 12140Sstevel@tonic-gate } 12150Sstevel@tonic-gate 12160Sstevel@tonic-gate ddi_acc_handle_t 12170Sstevel@tonic-gate impl_acc_hdl_alloc(int (*waitfp)(caddr_t), caddr_t arg) 12180Sstevel@tonic-gate { 12190Sstevel@tonic-gate ddi_acc_impl_t *hp; 12200Sstevel@tonic-gate on_trap_data_t *otp; 12210Sstevel@tonic-gate int sleepflag; 12220Sstevel@tonic-gate 12230Sstevel@tonic-gate sleepflag = ((waitfp == (int (*)())KM_SLEEP) ? KM_SLEEP : KM_NOSLEEP); 12240Sstevel@tonic-gate 12250Sstevel@tonic-gate /* 12260Sstevel@tonic-gate * Allocate and initialize the data access handle and error status. 12270Sstevel@tonic-gate */ 12280Sstevel@tonic-gate if ((hp = kmem_zalloc(sizeof (ddi_acc_impl_t), sleepflag)) == NULL) 12290Sstevel@tonic-gate goto fail; 12300Sstevel@tonic-gate if ((hp->ahi_err = (ndi_err_t *)kmem_zalloc( 12310Sstevel@tonic-gate sizeof (ndi_err_t), sleepflag)) == NULL) { 12320Sstevel@tonic-gate kmem_free(hp, sizeof (ddi_acc_impl_t)); 12330Sstevel@tonic-gate goto fail; 12340Sstevel@tonic-gate } 12350Sstevel@tonic-gate if ((otp = (on_trap_data_t *)kmem_zalloc( 12360Sstevel@tonic-gate sizeof (on_trap_data_t), sleepflag)) == NULL) { 12370Sstevel@tonic-gate kmem_free(hp->ahi_err, sizeof (ndi_err_t)); 12380Sstevel@tonic-gate kmem_free(hp, sizeof (ddi_acc_impl_t)); 12390Sstevel@tonic-gate goto fail; 12400Sstevel@tonic-gate } 12410Sstevel@tonic-gate hp->ahi_err->err_ontrap = otp; 12420Sstevel@tonic-gate hp->ahi_common.ah_platform_private = (void *)hp; 12430Sstevel@tonic-gate 12440Sstevel@tonic-gate return ((ddi_acc_handle_t)hp); 12450Sstevel@tonic-gate fail: 12460Sstevel@tonic-gate if ((waitfp != (int (*)())KM_SLEEP) && 12470Sstevel@tonic-gate (waitfp != (int (*)())KM_NOSLEEP)) 12480Sstevel@tonic-gate ddi_set_callback(waitfp, arg, &impl_acc_hdl_id); 12490Sstevel@tonic-gate return (NULL); 12500Sstevel@tonic-gate } 12510Sstevel@tonic-gate 12520Sstevel@tonic-gate void 12530Sstevel@tonic-gate impl_acc_hdl_free(ddi_acc_handle_t handle) 12540Sstevel@tonic-gate { 12550Sstevel@tonic-gate ddi_acc_impl_t *hp; 12560Sstevel@tonic-gate 12570Sstevel@tonic-gate /* 12580Sstevel@tonic-gate * The supplied (ddi_acc_handle_t) is actually a (ddi_acc_impl_t *), 12590Sstevel@tonic-gate * because that's what we allocated in impl_acc_hdl_alloc() above. 12600Sstevel@tonic-gate */ 12610Sstevel@tonic-gate hp = (ddi_acc_impl_t *)handle; 12620Sstevel@tonic-gate if (hp) { 12630Sstevel@tonic-gate kmem_free(hp->ahi_err->err_ontrap, sizeof (on_trap_data_t)); 12640Sstevel@tonic-gate kmem_free(hp->ahi_err, sizeof (ndi_err_t)); 12650Sstevel@tonic-gate kmem_free(hp, sizeof (ddi_acc_impl_t)); 12660Sstevel@tonic-gate if (impl_acc_hdl_id) 12670Sstevel@tonic-gate ddi_run_callback(&impl_acc_hdl_id); 12680Sstevel@tonic-gate } 12690Sstevel@tonic-gate } 12700Sstevel@tonic-gate 1271*1865Sdilpreet #define PCI_GET_MP_PFN(mp, page_no) ((mp)->dmai_ndvmapages == 1 ? \ 1272*1865Sdilpreet (pfn_t)(mp)->dmai_iopte:(((pfn_t *)(mp)->dmai_iopte)[page_no])) 1273*1865Sdilpreet 1274*1865Sdilpreet /* 1275*1865Sdilpreet * Function called after a dma fault occurred to find out whether the 1276*1865Sdilpreet * fault address is associated with a driver that is able to handle faults 1277*1865Sdilpreet * and recover from faults. 1278*1865Sdilpreet */ 1279*1865Sdilpreet /* ARGSUSED */ 1280*1865Sdilpreet int 1281*1865Sdilpreet impl_dma_check(dev_info_t *dip, const void *handle, const void *addr, 1282*1865Sdilpreet const void *not_used) 1283*1865Sdilpreet { 1284*1865Sdilpreet ddi_dma_impl_t *mp = (ddi_dma_impl_t *)handle; 1285*1865Sdilpreet pfn_t fault_pfn = mmu_btop(*(uint64_t *)addr); 1286*1865Sdilpreet pfn_t comp_pfn; 1287*1865Sdilpreet 1288*1865Sdilpreet /* 1289*1865Sdilpreet * The driver has to set DDI_DMA_FLAGERR to recover from dma faults. 1290*1865Sdilpreet */ 1291*1865Sdilpreet int page; 1292*1865Sdilpreet 1293*1865Sdilpreet ASSERT(mp); 1294*1865Sdilpreet for (page = 0; page < mp->dmai_ndvmapages; page++) { 1295*1865Sdilpreet comp_pfn = PCI_GET_MP_PFN(mp, page); 1296*1865Sdilpreet if (fault_pfn == comp_pfn) 1297*1865Sdilpreet return (DDI_FM_NONFATAL); 1298*1865Sdilpreet } 1299*1865Sdilpreet return (DDI_FM_UNKNOWN); 1300*1865Sdilpreet } 1301*1865Sdilpreet 1302*1865Sdilpreet /* 1303*1865Sdilpreet * Function used to check if a given access handle owns the failing address. 1304*1865Sdilpreet * Called by ndi_fmc_error, when we detect a PIO error. 1305*1865Sdilpreet */ 1306*1865Sdilpreet /* ARGSUSED */ 1307*1865Sdilpreet static int 1308*1865Sdilpreet impl_acc_check(dev_info_t *dip, const void *handle, const void *addr, 1309*1865Sdilpreet const void *not_used) 1310*1865Sdilpreet { 1311*1865Sdilpreet pfn_t pfn, fault_pfn; 1312*1865Sdilpreet ddi_acc_hdl_t *hp; 1313*1865Sdilpreet 1314*1865Sdilpreet hp = impl_acc_hdl_get((ddi_acc_handle_t)handle); 1315*1865Sdilpreet 1316*1865Sdilpreet ASSERT(hp); 1317*1865Sdilpreet 1318*1865Sdilpreet if (addr != NULL) { 1319*1865Sdilpreet pfn = hp->ah_pfn; 1320*1865Sdilpreet fault_pfn = mmu_btop(*(uint64_t *)addr); 1321*1865Sdilpreet if (fault_pfn >= pfn && fault_pfn < (pfn + hp->ah_pnum)) 1322*1865Sdilpreet return (DDI_FM_NONFATAL); 1323*1865Sdilpreet } 1324*1865Sdilpreet return (DDI_FM_UNKNOWN); 1325*1865Sdilpreet } 1326*1865Sdilpreet 13270Sstevel@tonic-gate void 13280Sstevel@tonic-gate impl_acc_err_init(ddi_acc_hdl_t *handlep) 13290Sstevel@tonic-gate { 13300Sstevel@tonic-gate int fmcap; 13310Sstevel@tonic-gate ndi_err_t *errp; 13320Sstevel@tonic-gate on_trap_data_t *otp; 13330Sstevel@tonic-gate ddi_acc_impl_t *hp = (ddi_acc_impl_t *)handlep; 13340Sstevel@tonic-gate 13350Sstevel@tonic-gate fmcap = ddi_fm_capable(handlep->ah_dip); 13360Sstevel@tonic-gate 13370Sstevel@tonic-gate if (handlep->ah_acc.devacc_attr_version < DDI_DEVICE_ATTR_V1 || 13380Sstevel@tonic-gate !DDI_FM_ACC_ERR_CAP(fmcap)) { 13390Sstevel@tonic-gate handlep->ah_acc.devacc_attr_access = DDI_DEFAULT_ACC; 13400Sstevel@tonic-gate } else if (DDI_FM_ACC_ERR_CAP(fmcap)) { 13410Sstevel@tonic-gate if (handlep->ah_acc.devacc_attr_access == DDI_DEFAULT_ACC) { 13420Sstevel@tonic-gate i_ddi_drv_ereport_post(handlep->ah_dip, DVR_EFMCAP, 13430Sstevel@tonic-gate NULL, DDI_NOSLEEP); 13440Sstevel@tonic-gate } else { 13450Sstevel@tonic-gate errp = hp->ahi_err; 13460Sstevel@tonic-gate otp = (on_trap_data_t *)errp->err_ontrap; 13470Sstevel@tonic-gate otp->ot_handle = (void *)(hp); 13480Sstevel@tonic-gate otp->ot_prot = OT_DATA_ACCESS; 13490Sstevel@tonic-gate if (handlep->ah_acc.devacc_attr_access == 13500Sstevel@tonic-gate DDI_CAUTIOUS_ACC) 13510Sstevel@tonic-gate otp->ot_trampoline = 13520Sstevel@tonic-gate (uintptr_t)&i_ddi_caut_trampoline; 13530Sstevel@tonic-gate else 13540Sstevel@tonic-gate otp->ot_trampoline = 13550Sstevel@tonic-gate (uintptr_t)&i_ddi_prot_trampoline; 13560Sstevel@tonic-gate errp->err_status = DDI_FM_OK; 13570Sstevel@tonic-gate errp->err_expected = DDI_FM_ERR_UNEXPECTED; 1358*1865Sdilpreet errp->err_cf = impl_acc_check; 13590Sstevel@tonic-gate } 13600Sstevel@tonic-gate } 13610Sstevel@tonic-gate } 13620Sstevel@tonic-gate 13630Sstevel@tonic-gate void 13640Sstevel@tonic-gate impl_acc_hdl_init(ddi_acc_hdl_t *handlep) 13650Sstevel@tonic-gate { 13660Sstevel@tonic-gate ddi_acc_impl_t *hp; 13670Sstevel@tonic-gate 13680Sstevel@tonic-gate ASSERT(handlep); 13690Sstevel@tonic-gate 13700Sstevel@tonic-gate hp = (ddi_acc_impl_t *)handlep; 13710Sstevel@tonic-gate 13720Sstevel@tonic-gate /* 13730Sstevel@tonic-gate * check for SW byte-swapping 13740Sstevel@tonic-gate */ 13750Sstevel@tonic-gate hp->ahi_get8 = i_ddi_get8; 13760Sstevel@tonic-gate hp->ahi_put8 = i_ddi_put8; 13770Sstevel@tonic-gate hp->ahi_rep_get8 = i_ddi_rep_get8; 13780Sstevel@tonic-gate hp->ahi_rep_put8 = i_ddi_rep_put8; 13790Sstevel@tonic-gate if (handlep->ah_acc.devacc_attr_endian_flags & DDI_STRUCTURE_LE_ACC) { 13800Sstevel@tonic-gate hp->ahi_get16 = i_ddi_swap_get16; 13810Sstevel@tonic-gate hp->ahi_get32 = i_ddi_swap_get32; 13820Sstevel@tonic-gate hp->ahi_get64 = i_ddi_swap_get64; 13830Sstevel@tonic-gate hp->ahi_put16 = i_ddi_swap_put16; 13840Sstevel@tonic-gate hp->ahi_put32 = i_ddi_swap_put32; 13850Sstevel@tonic-gate hp->ahi_put64 = i_ddi_swap_put64; 13860Sstevel@tonic-gate hp->ahi_rep_get16 = i_ddi_swap_rep_get16; 13870Sstevel@tonic-gate hp->ahi_rep_get32 = i_ddi_swap_rep_get32; 13880Sstevel@tonic-gate hp->ahi_rep_get64 = i_ddi_swap_rep_get64; 13890Sstevel@tonic-gate hp->ahi_rep_put16 = i_ddi_swap_rep_put16; 13900Sstevel@tonic-gate hp->ahi_rep_put32 = i_ddi_swap_rep_put32; 13910Sstevel@tonic-gate hp->ahi_rep_put64 = i_ddi_swap_rep_put64; 13920Sstevel@tonic-gate } else { 13930Sstevel@tonic-gate hp->ahi_get16 = i_ddi_get16; 13940Sstevel@tonic-gate hp->ahi_get32 = i_ddi_get32; 13950Sstevel@tonic-gate hp->ahi_get64 = i_ddi_get64; 13960Sstevel@tonic-gate hp->ahi_put16 = i_ddi_put16; 13970Sstevel@tonic-gate hp->ahi_put32 = i_ddi_put32; 13980Sstevel@tonic-gate hp->ahi_put64 = i_ddi_put64; 13990Sstevel@tonic-gate hp->ahi_rep_get16 = i_ddi_rep_get16; 14000Sstevel@tonic-gate hp->ahi_rep_get32 = i_ddi_rep_get32; 14010Sstevel@tonic-gate hp->ahi_rep_get64 = i_ddi_rep_get64; 14020Sstevel@tonic-gate hp->ahi_rep_put16 = i_ddi_rep_put16; 14030Sstevel@tonic-gate hp->ahi_rep_put32 = i_ddi_rep_put32; 14040Sstevel@tonic-gate hp->ahi_rep_put64 = i_ddi_rep_put64; 14050Sstevel@tonic-gate } 14060Sstevel@tonic-gate 14070Sstevel@tonic-gate /* Legacy fault flags and support */ 14080Sstevel@tonic-gate hp->ahi_fault_check = i_ddi_acc_fault_check; 14090Sstevel@tonic-gate hp->ahi_fault_notify = i_ddi_acc_fault_notify; 14100Sstevel@tonic-gate hp->ahi_fault = 0; 14110Sstevel@tonic-gate impl_acc_err_init(handlep); 14120Sstevel@tonic-gate } 14130Sstevel@tonic-gate 14140Sstevel@tonic-gate void 14150Sstevel@tonic-gate i_ddi_acc_set_fault(ddi_acc_handle_t handle) 14160Sstevel@tonic-gate { 14170Sstevel@tonic-gate ddi_acc_impl_t *hp = (ddi_acc_impl_t *)handle; 14180Sstevel@tonic-gate 14190Sstevel@tonic-gate if (!hp->ahi_fault) { 14200Sstevel@tonic-gate hp->ahi_fault = 1; 14210Sstevel@tonic-gate (*hp->ahi_fault_notify)(hp); 14220Sstevel@tonic-gate } 14230Sstevel@tonic-gate } 14240Sstevel@tonic-gate 14250Sstevel@tonic-gate void 14260Sstevel@tonic-gate i_ddi_acc_clr_fault(ddi_acc_handle_t handle) 14270Sstevel@tonic-gate { 14280Sstevel@tonic-gate ddi_acc_impl_t *hp = (ddi_acc_impl_t *)handle; 14290Sstevel@tonic-gate 14300Sstevel@tonic-gate if (hp->ahi_fault) { 14310Sstevel@tonic-gate hp->ahi_fault = 0; 14320Sstevel@tonic-gate (*hp->ahi_fault_notify)(hp); 14330Sstevel@tonic-gate } 14340Sstevel@tonic-gate } 14350Sstevel@tonic-gate 14360Sstevel@tonic-gate /* ARGSUSED */ 14370Sstevel@tonic-gate void 14380Sstevel@tonic-gate i_ddi_acc_fault_notify(ddi_acc_impl_t *hp) 14390Sstevel@tonic-gate { 14400Sstevel@tonic-gate /* Default version, does nothing */ 14410Sstevel@tonic-gate } 14420Sstevel@tonic-gate 14430Sstevel@tonic-gate /* 14440Sstevel@tonic-gate * SECTION: Misc functions 14450Sstevel@tonic-gate */ 14460Sstevel@tonic-gate 14470Sstevel@tonic-gate /* 14480Sstevel@tonic-gate * instance wrappers 14490Sstevel@tonic-gate */ 14500Sstevel@tonic-gate /*ARGSUSED*/ 14510Sstevel@tonic-gate uint_t 14520Sstevel@tonic-gate impl_assign_instance(dev_info_t *dip) 14530Sstevel@tonic-gate { 14540Sstevel@tonic-gate return ((uint_t)-1); 14550Sstevel@tonic-gate } 14560Sstevel@tonic-gate 14570Sstevel@tonic-gate /*ARGSUSED*/ 14580Sstevel@tonic-gate int 14590Sstevel@tonic-gate impl_keep_instance(dev_info_t *dip) 14600Sstevel@tonic-gate { 14610Sstevel@tonic-gate return (DDI_FAILURE); 14620Sstevel@tonic-gate } 14630Sstevel@tonic-gate 14640Sstevel@tonic-gate /*ARGSUSED*/ 14650Sstevel@tonic-gate int 14660Sstevel@tonic-gate impl_free_instance(dev_info_t *dip) 14670Sstevel@tonic-gate { 14680Sstevel@tonic-gate return (DDI_FAILURE); 14690Sstevel@tonic-gate } 14700Sstevel@tonic-gate 14710Sstevel@tonic-gate /*ARGSUSED*/ 14720Sstevel@tonic-gate int 14730Sstevel@tonic-gate impl_check_cpu(dev_info_t *devi) 14740Sstevel@tonic-gate { 14750Sstevel@tonic-gate return (DDI_SUCCESS); 14760Sstevel@tonic-gate } 14770Sstevel@tonic-gate 14780Sstevel@tonic-gate 14790Sstevel@tonic-gate static const char *nocopydevs[] = { 14800Sstevel@tonic-gate "SUNW,ffb", 14810Sstevel@tonic-gate "SUNW,afb", 14820Sstevel@tonic-gate NULL 14830Sstevel@tonic-gate }; 14840Sstevel@tonic-gate 14850Sstevel@tonic-gate /* 14860Sstevel@tonic-gate * Perform a copy from a memory mapped device (whose devinfo pointer is devi) 14870Sstevel@tonic-gate * separately mapped at devaddr in the kernel to a kernel buffer at kaddr. 14880Sstevel@tonic-gate */ 14890Sstevel@tonic-gate /*ARGSUSED*/ 14900Sstevel@tonic-gate int 14910Sstevel@tonic-gate e_ddi_copyfromdev(dev_info_t *devi, 14920Sstevel@tonic-gate off_t off, const void *devaddr, void *kaddr, size_t len) 14930Sstevel@tonic-gate { 14940Sstevel@tonic-gate const char **argv; 14950Sstevel@tonic-gate 14960Sstevel@tonic-gate for (argv = nocopydevs; *argv; argv++) 14970Sstevel@tonic-gate if (strcmp(ddi_binding_name(devi), *argv) == 0) { 14980Sstevel@tonic-gate bzero(kaddr, len); 14990Sstevel@tonic-gate return (0); 15000Sstevel@tonic-gate } 15010Sstevel@tonic-gate 15020Sstevel@tonic-gate bcopy(devaddr, kaddr, len); 15030Sstevel@tonic-gate return (0); 15040Sstevel@tonic-gate } 15050Sstevel@tonic-gate 15060Sstevel@tonic-gate /* 15070Sstevel@tonic-gate * Perform a copy to a memory mapped device (whose devinfo pointer is devi) 15080Sstevel@tonic-gate * separately mapped at devaddr in the kernel from a kernel buffer at kaddr. 15090Sstevel@tonic-gate */ 15100Sstevel@tonic-gate /*ARGSUSED*/ 15110Sstevel@tonic-gate int 15120Sstevel@tonic-gate e_ddi_copytodev(dev_info_t *devi, 15130Sstevel@tonic-gate off_t off, const void *kaddr, void *devaddr, size_t len) 15140Sstevel@tonic-gate { 15150Sstevel@tonic-gate const char **argv; 15160Sstevel@tonic-gate 15170Sstevel@tonic-gate for (argv = nocopydevs; *argv; argv++) 15180Sstevel@tonic-gate if (strcmp(ddi_binding_name(devi), *argv) == 0) 15190Sstevel@tonic-gate return (1); 15200Sstevel@tonic-gate 15210Sstevel@tonic-gate bcopy(kaddr, devaddr, len); 15220Sstevel@tonic-gate return (0); 15230Sstevel@tonic-gate } 15240Sstevel@tonic-gate 15250Sstevel@tonic-gate /* 15260Sstevel@tonic-gate * Boot Configuration 15270Sstevel@tonic-gate */ 15280Sstevel@tonic-gate idprom_t idprom; 15290Sstevel@tonic-gate 15300Sstevel@tonic-gate /* 15310Sstevel@tonic-gate * Configure the hardware on the system. 15320Sstevel@tonic-gate * Called before the rootfs is mounted 15330Sstevel@tonic-gate */ 15340Sstevel@tonic-gate void 15350Sstevel@tonic-gate configure(void) 15360Sstevel@tonic-gate { 15370Sstevel@tonic-gate extern void i_ddi_init_root(); 15380Sstevel@tonic-gate 15390Sstevel@tonic-gate /* We better have released boot by this time! */ 15400Sstevel@tonic-gate ASSERT(!bootops); 15410Sstevel@tonic-gate 15420Sstevel@tonic-gate /* 15430Sstevel@tonic-gate * Determine whether or not to use the fpu, V9 SPARC cpus 15440Sstevel@tonic-gate * always have one. Could check for existence of a fp queue, 15450Sstevel@tonic-gate * Ultra I, II and IIa do not have a fp queue. 15460Sstevel@tonic-gate */ 15470Sstevel@tonic-gate if (fpu_exists) 15480Sstevel@tonic-gate fpu_probe(); 15490Sstevel@tonic-gate else 15500Sstevel@tonic-gate cmn_err(CE_CONT, "FPU not in use\n"); 15510Sstevel@tonic-gate 15520Sstevel@tonic-gate #if 0 /* XXXQ - not necessary for sun4u */ 15530Sstevel@tonic-gate /* 15540Sstevel@tonic-gate * This following line fixes bugid 1041296; we need to do a 15550Sstevel@tonic-gate * prom_nextnode(0) because this call ALSO patches the DMA+ 15560Sstevel@tonic-gate * bug in Campus-B and Phoenix. The prom uncaches the traptable 15570Sstevel@tonic-gate * page as a side-effect of devr_next(0) (which prom_nextnode calls), 15580Sstevel@tonic-gate * so this *must* be executed early on. (XXX This is untrue for sun4u) 15590Sstevel@tonic-gate */ 1560789Sahrens (void) prom_nextnode((pnode_t)0); 15610Sstevel@tonic-gate #endif 15620Sstevel@tonic-gate 15630Sstevel@tonic-gate /* 15640Sstevel@tonic-gate * Initialize devices on the machine. 15650Sstevel@tonic-gate * Uses configuration tree built by the PROMs to determine what 15660Sstevel@tonic-gate * is present, and builds a tree of prototype dev_info nodes 15670Sstevel@tonic-gate * corresponding to the hardware which identified itself. 15680Sstevel@tonic-gate */ 15690Sstevel@tonic-gate i_ddi_init_root(); 15700Sstevel@tonic-gate 15710Sstevel@tonic-gate #ifdef DDI_PROP_DEBUG 15720Sstevel@tonic-gate (void) ddi_prop_debug(1); /* Enable property debugging */ 15730Sstevel@tonic-gate #endif /* DDI_PROP_DEBUG */ 15740Sstevel@tonic-gate } 15750Sstevel@tonic-gate 15760Sstevel@tonic-gate /* 15770Sstevel@tonic-gate * The "status" property indicates the operational status of a device. 15780Sstevel@tonic-gate * If this property is present, the value is a string indicating the 15790Sstevel@tonic-gate * status of the device as follows: 15800Sstevel@tonic-gate * 15810Sstevel@tonic-gate * "okay" operational. 15820Sstevel@tonic-gate * "disabled" not operational, but might become operational. 15830Sstevel@tonic-gate * "fail" not operational because a fault has been detected, 15840Sstevel@tonic-gate * and it is unlikely that the device will become 15850Sstevel@tonic-gate * operational without repair. no additional details 15860Sstevel@tonic-gate * are available. 15870Sstevel@tonic-gate * "fail-xxx" not operational because a fault has been detected, 15880Sstevel@tonic-gate * and it is unlikely that the device will become 15890Sstevel@tonic-gate * operational without repair. "xxx" is additional 15900Sstevel@tonic-gate * human-readable information about the particular 15910Sstevel@tonic-gate * fault condition that was detected. 15920Sstevel@tonic-gate * 15930Sstevel@tonic-gate * The absence of this property means that the operational status is 15940Sstevel@tonic-gate * unknown or okay. 15950Sstevel@tonic-gate * 15960Sstevel@tonic-gate * This routine checks the status property of the specified device node 15970Sstevel@tonic-gate * and returns 0 if the operational status indicates failure, and 1 otherwise. 15980Sstevel@tonic-gate * 15990Sstevel@tonic-gate * The property may exist on plug-in cards the existed before IEEE 1275-1994. 16000Sstevel@tonic-gate * And, in that case, the property may not even be a string. So we carefully 16010Sstevel@tonic-gate * check for the value "fail", in the beginning of the string, noting 16020Sstevel@tonic-gate * the property length. 16030Sstevel@tonic-gate */ 16040Sstevel@tonic-gate int 16050Sstevel@tonic-gate status_okay(int id, char *buf, int buflen) 16060Sstevel@tonic-gate { 16070Sstevel@tonic-gate char status_buf[OBP_MAXPROPNAME]; 16080Sstevel@tonic-gate char *bufp = buf; 16090Sstevel@tonic-gate int len = buflen; 16100Sstevel@tonic-gate int proplen; 16110Sstevel@tonic-gate static const char *status = "status"; 16120Sstevel@tonic-gate static const char *fail = "fail"; 16130Sstevel@tonic-gate size_t fail_len = strlen(fail); 16140Sstevel@tonic-gate 16150Sstevel@tonic-gate /* 16160Sstevel@tonic-gate * Get the proplen ... if it's smaller than "fail", 16170Sstevel@tonic-gate * or doesn't exist ... then we don't care, since 16180Sstevel@tonic-gate * the value can't begin with the char string "fail". 16190Sstevel@tonic-gate * 16200Sstevel@tonic-gate * NB: proplen, if it's a string, includes the NULL in the 16210Sstevel@tonic-gate * the size of the property, and fail_len does not. 16220Sstevel@tonic-gate */ 1623789Sahrens proplen = prom_getproplen((pnode_t)id, (caddr_t)status); 16240Sstevel@tonic-gate if (proplen <= fail_len) /* nonexistent or uninteresting len */ 16250Sstevel@tonic-gate return (1); 16260Sstevel@tonic-gate 16270Sstevel@tonic-gate /* 16280Sstevel@tonic-gate * if a buffer was provided, use it 16290Sstevel@tonic-gate */ 16300Sstevel@tonic-gate if ((buf == (char *)NULL) || (buflen <= 0)) { 16310Sstevel@tonic-gate bufp = status_buf; 16320Sstevel@tonic-gate len = sizeof (status_buf); 16330Sstevel@tonic-gate } 16340Sstevel@tonic-gate *bufp = (char)0; 16350Sstevel@tonic-gate 16360Sstevel@tonic-gate /* 16370Sstevel@tonic-gate * Get the property into the buffer, to the extent of the buffer, 16380Sstevel@tonic-gate * and in case the buffer is smaller than the property size, 16390Sstevel@tonic-gate * NULL terminate the buffer. (This handles the case where 16400Sstevel@tonic-gate * a buffer was passed in and the caller wants to print the 16410Sstevel@tonic-gate * value, but the buffer was too small). 16420Sstevel@tonic-gate */ 1643789Sahrens (void) prom_bounded_getprop((pnode_t)id, (caddr_t)status, 16440Sstevel@tonic-gate (caddr_t)bufp, len); 16450Sstevel@tonic-gate *(bufp + len - 1) = (char)0; 16460Sstevel@tonic-gate 16470Sstevel@tonic-gate /* 16480Sstevel@tonic-gate * If the value begins with the char string "fail", 16490Sstevel@tonic-gate * then it means the node is failed. We don't care 16500Sstevel@tonic-gate * about any other values. We assume the node is ok 16510Sstevel@tonic-gate * although it might be 'disabled'. 16520Sstevel@tonic-gate */ 16530Sstevel@tonic-gate if (strncmp(bufp, fail, fail_len) == 0) 16540Sstevel@tonic-gate return (0); 16550Sstevel@tonic-gate 16560Sstevel@tonic-gate return (1); 16570Sstevel@tonic-gate } 16580Sstevel@tonic-gate 16590Sstevel@tonic-gate 16600Sstevel@tonic-gate /* 16610Sstevel@tonic-gate * We set the cpu type from the idprom, if we can. 16620Sstevel@tonic-gate * Note that we just read out the contents of it, for the most part. 16630Sstevel@tonic-gate */ 16640Sstevel@tonic-gate void 16650Sstevel@tonic-gate setcputype(void) 16660Sstevel@tonic-gate { 16670Sstevel@tonic-gate /* 16680Sstevel@tonic-gate * We cache the idprom info early on so that we don't 16690Sstevel@tonic-gate * rummage through the NVRAM unnecessarily later. 16700Sstevel@tonic-gate */ 16710Sstevel@tonic-gate (void) prom_getidprom((caddr_t)&idprom, sizeof (idprom)); 16720Sstevel@tonic-gate } 16730Sstevel@tonic-gate 16740Sstevel@tonic-gate /* 16750Sstevel@tonic-gate * Here is where we actually infer meanings to the members of idprom_t 16760Sstevel@tonic-gate */ 16770Sstevel@tonic-gate void 16780Sstevel@tonic-gate parse_idprom(void) 16790Sstevel@tonic-gate { 16800Sstevel@tonic-gate if (idprom.id_format == IDFORM_1) { 16810Sstevel@tonic-gate uint_t i; 16820Sstevel@tonic-gate 16830Sstevel@tonic-gate (void) localetheraddr((struct ether_addr *)idprom.id_ether, 16840Sstevel@tonic-gate (struct ether_addr *)NULL); 16850Sstevel@tonic-gate 16860Sstevel@tonic-gate i = idprom.id_machine << 24; 16870Sstevel@tonic-gate i = i + idprom.id_serial; 16880Sstevel@tonic-gate numtos((ulong_t)i, hw_serial); 16890Sstevel@tonic-gate } else 16900Sstevel@tonic-gate prom_printf("Invalid format code in IDprom.\n"); 16910Sstevel@tonic-gate } 16920Sstevel@tonic-gate 16930Sstevel@tonic-gate /* 16940Sstevel@tonic-gate * Allow for implementation specific correction of PROM property values. 16950Sstevel@tonic-gate */ 16960Sstevel@tonic-gate /*ARGSUSED*/ 16970Sstevel@tonic-gate void 16980Sstevel@tonic-gate impl_fix_props(dev_info_t *dip, dev_info_t *ch_dip, char *name, int len, 16990Sstevel@tonic-gate caddr_t buffer) 17000Sstevel@tonic-gate { 17010Sstevel@tonic-gate /* 17020Sstevel@tonic-gate * There are no adjustments needed in this implementation. 17030Sstevel@tonic-gate */ 17040Sstevel@tonic-gate } 17050Sstevel@tonic-gate 17060Sstevel@tonic-gate /* 17070Sstevel@tonic-gate * The following functions ready a cautious request to go up to the nexus 17080Sstevel@tonic-gate * driver. It is up to the nexus driver to decide how to process the request. 17090Sstevel@tonic-gate * It may choose to call i_ddi_do_caut_get/put in this file, or do it 17100Sstevel@tonic-gate * differently. 17110Sstevel@tonic-gate */ 17120Sstevel@tonic-gate 17130Sstevel@tonic-gate static void 17140Sstevel@tonic-gate i_ddi_caut_getput_ctlops( 17150Sstevel@tonic-gate ddi_acc_impl_t *hp, uint64_t host_addr, uint64_t dev_addr, size_t size, 17160Sstevel@tonic-gate size_t repcount, uint_t flags, ddi_ctl_enum_t cmd) 17170Sstevel@tonic-gate { 17180Sstevel@tonic-gate peekpoke_ctlops_t cautacc_ctlops_arg; 17190Sstevel@tonic-gate 17200Sstevel@tonic-gate cautacc_ctlops_arg.size = size; 17210Sstevel@tonic-gate cautacc_ctlops_arg.dev_addr = dev_addr; 17220Sstevel@tonic-gate cautacc_ctlops_arg.host_addr = host_addr; 17230Sstevel@tonic-gate cautacc_ctlops_arg.handle = (ddi_acc_handle_t)hp; 17240Sstevel@tonic-gate cautacc_ctlops_arg.repcount = repcount; 17250Sstevel@tonic-gate cautacc_ctlops_arg.flags = flags; 17260Sstevel@tonic-gate 17270Sstevel@tonic-gate (void) ddi_ctlops(hp->ahi_common.ah_dip, hp->ahi_common.ah_dip, cmd, 17280Sstevel@tonic-gate &cautacc_ctlops_arg, NULL); 17290Sstevel@tonic-gate } 17300Sstevel@tonic-gate 17310Sstevel@tonic-gate uint8_t 17320Sstevel@tonic-gate i_ddi_caut_get8(ddi_acc_impl_t *hp, uint8_t *addr) 17330Sstevel@tonic-gate { 17340Sstevel@tonic-gate uint8_t value; 17350Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr, 17360Sstevel@tonic-gate sizeof (uint8_t), 1, 0, DDI_CTLOPS_PEEK); 17370Sstevel@tonic-gate 17380Sstevel@tonic-gate return (value); 17390Sstevel@tonic-gate } 17400Sstevel@tonic-gate 17410Sstevel@tonic-gate uint16_t 17420Sstevel@tonic-gate i_ddi_caut_get16(ddi_acc_impl_t *hp, uint16_t *addr) 17430Sstevel@tonic-gate { 17440Sstevel@tonic-gate uint16_t value; 17450Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr, 17460Sstevel@tonic-gate sizeof (uint16_t), 1, 0, DDI_CTLOPS_PEEK); 17470Sstevel@tonic-gate 17480Sstevel@tonic-gate return (value); 17490Sstevel@tonic-gate } 17500Sstevel@tonic-gate 17510Sstevel@tonic-gate uint32_t 17520Sstevel@tonic-gate i_ddi_caut_get32(ddi_acc_impl_t *hp, uint32_t *addr) 17530Sstevel@tonic-gate { 17540Sstevel@tonic-gate uint32_t value; 17550Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr, 17560Sstevel@tonic-gate sizeof (uint32_t), 1, 0, DDI_CTLOPS_PEEK); 17570Sstevel@tonic-gate 17580Sstevel@tonic-gate return (value); 17590Sstevel@tonic-gate } 17600Sstevel@tonic-gate 17610Sstevel@tonic-gate uint64_t 17620Sstevel@tonic-gate i_ddi_caut_get64(ddi_acc_impl_t *hp, uint64_t *addr) 17630Sstevel@tonic-gate { 17640Sstevel@tonic-gate uint64_t value; 17650Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr, 17660Sstevel@tonic-gate sizeof (uint64_t), 1, 0, DDI_CTLOPS_PEEK); 17670Sstevel@tonic-gate 17680Sstevel@tonic-gate return (value); 17690Sstevel@tonic-gate } 17700Sstevel@tonic-gate 17710Sstevel@tonic-gate void 17720Sstevel@tonic-gate i_ddi_caut_put8(ddi_acc_impl_t *hp, uint8_t *addr, uint8_t value) 17730Sstevel@tonic-gate { 17740Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr, 17750Sstevel@tonic-gate sizeof (uint8_t), 1, 0, DDI_CTLOPS_POKE); 17760Sstevel@tonic-gate } 17770Sstevel@tonic-gate 17780Sstevel@tonic-gate void 17790Sstevel@tonic-gate i_ddi_caut_put16(ddi_acc_impl_t *hp, uint16_t *addr, uint16_t value) 17800Sstevel@tonic-gate { 17810Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr, 17820Sstevel@tonic-gate sizeof (uint16_t), 1, 0, DDI_CTLOPS_POKE); 17830Sstevel@tonic-gate } 17840Sstevel@tonic-gate 17850Sstevel@tonic-gate void 17860Sstevel@tonic-gate i_ddi_caut_put32(ddi_acc_impl_t *hp, uint32_t *addr, uint32_t value) 17870Sstevel@tonic-gate { 17880Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr, 17890Sstevel@tonic-gate sizeof (uint32_t), 1, 0, DDI_CTLOPS_POKE); 17900Sstevel@tonic-gate } 17910Sstevel@tonic-gate 17920Sstevel@tonic-gate void 17930Sstevel@tonic-gate i_ddi_caut_put64(ddi_acc_impl_t *hp, uint64_t *addr, uint64_t value) 17940Sstevel@tonic-gate { 17950Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)&value, (uint64_t)addr, 17960Sstevel@tonic-gate sizeof (uint64_t), 1, 0, DDI_CTLOPS_POKE); 17970Sstevel@tonic-gate } 17980Sstevel@tonic-gate 17990Sstevel@tonic-gate void 18000Sstevel@tonic-gate i_ddi_caut_rep_get8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr, 18010Sstevel@tonic-gate size_t repcount, uint_t flags) 18020Sstevel@tonic-gate { 18030Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr, 18040Sstevel@tonic-gate sizeof (uint8_t), repcount, flags, DDI_CTLOPS_PEEK); 18050Sstevel@tonic-gate } 18060Sstevel@tonic-gate 18070Sstevel@tonic-gate void 18080Sstevel@tonic-gate i_ddi_caut_rep_get16(ddi_acc_impl_t *hp, uint16_t *host_addr, 18090Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags) 18100Sstevel@tonic-gate { 18110Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr, 18120Sstevel@tonic-gate sizeof (uint16_t), repcount, flags, DDI_CTLOPS_PEEK); 18130Sstevel@tonic-gate } 18140Sstevel@tonic-gate 18150Sstevel@tonic-gate void 18160Sstevel@tonic-gate i_ddi_caut_rep_get32(ddi_acc_impl_t *hp, uint32_t *host_addr, 18170Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags) 18180Sstevel@tonic-gate { 18190Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr, 18200Sstevel@tonic-gate sizeof (uint32_t), repcount, flags, DDI_CTLOPS_PEEK); 18210Sstevel@tonic-gate } 18220Sstevel@tonic-gate 18230Sstevel@tonic-gate void 18240Sstevel@tonic-gate i_ddi_caut_rep_get64(ddi_acc_impl_t *hp, uint64_t *host_addr, 18250Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags) 18260Sstevel@tonic-gate { 18270Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr, 18280Sstevel@tonic-gate sizeof (uint64_t), repcount, flags, DDI_CTLOPS_PEEK); 18290Sstevel@tonic-gate } 18300Sstevel@tonic-gate 18310Sstevel@tonic-gate void 18320Sstevel@tonic-gate i_ddi_caut_rep_put8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr, 18330Sstevel@tonic-gate size_t repcount, uint_t flags) 18340Sstevel@tonic-gate { 18350Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr, 18360Sstevel@tonic-gate sizeof (uint8_t), repcount, flags, DDI_CTLOPS_POKE); 18370Sstevel@tonic-gate } 18380Sstevel@tonic-gate 18390Sstevel@tonic-gate void 18400Sstevel@tonic-gate i_ddi_caut_rep_put16(ddi_acc_impl_t *hp, uint16_t *host_addr, 18410Sstevel@tonic-gate uint16_t *dev_addr, size_t repcount, uint_t flags) 18420Sstevel@tonic-gate { 18430Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr, 18440Sstevel@tonic-gate sizeof (uint16_t), repcount, flags, DDI_CTLOPS_POKE); 18450Sstevel@tonic-gate } 18460Sstevel@tonic-gate 18470Sstevel@tonic-gate void 18480Sstevel@tonic-gate i_ddi_caut_rep_put32(ddi_acc_impl_t *hp, uint32_t *host_addr, 18490Sstevel@tonic-gate uint32_t *dev_addr, size_t repcount, uint_t flags) 18500Sstevel@tonic-gate { 18510Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr, 18520Sstevel@tonic-gate sizeof (uint32_t), repcount, flags, DDI_CTLOPS_POKE); 18530Sstevel@tonic-gate } 18540Sstevel@tonic-gate 18550Sstevel@tonic-gate void 18560Sstevel@tonic-gate i_ddi_caut_rep_put64(ddi_acc_impl_t *hp, uint64_t *host_addr, 18570Sstevel@tonic-gate uint64_t *dev_addr, size_t repcount, uint_t flags) 18580Sstevel@tonic-gate { 18590Sstevel@tonic-gate i_ddi_caut_getput_ctlops(hp, (uint64_t)host_addr, (uint64_t)dev_addr, 18600Sstevel@tonic-gate sizeof (uint64_t), repcount, flags, DDI_CTLOPS_POKE); 18610Sstevel@tonic-gate } 18620Sstevel@tonic-gate 18630Sstevel@tonic-gate /* 18640Sstevel@tonic-gate * This is called only to process peek/poke when the DIP is NULL. 18650Sstevel@tonic-gate * Assume that this is for memory, as nexi take care of device safe accesses. 18660Sstevel@tonic-gate */ 18670Sstevel@tonic-gate int 18680Sstevel@tonic-gate peekpoke_mem(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args) 18690Sstevel@tonic-gate { 18700Sstevel@tonic-gate int err = DDI_SUCCESS; 18710Sstevel@tonic-gate on_trap_data_t otd; 18720Sstevel@tonic-gate 18730Sstevel@tonic-gate /* Set up protected environment. */ 18740Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 18750Sstevel@tonic-gate uintptr_t tramp = otd.ot_trampoline; 18760Sstevel@tonic-gate 18770Sstevel@tonic-gate if (cmd == DDI_CTLOPS_POKE) { 18780Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&poke_fault; 18790Sstevel@tonic-gate err = do_poke(in_args->size, (void *)in_args->dev_addr, 18800Sstevel@tonic-gate (void *)in_args->host_addr); 18810Sstevel@tonic-gate } else { 18820Sstevel@tonic-gate otd.ot_trampoline = (uintptr_t)&peek_fault; 18830Sstevel@tonic-gate err = do_peek(in_args->size, (void *)in_args->dev_addr, 18840Sstevel@tonic-gate (void *)in_args->host_addr); 18850Sstevel@tonic-gate } 18860Sstevel@tonic-gate otd.ot_trampoline = tramp; 18870Sstevel@tonic-gate } else 18880Sstevel@tonic-gate err = DDI_FAILURE; 18890Sstevel@tonic-gate 18900Sstevel@tonic-gate /* Take down protected environment. */ 18910Sstevel@tonic-gate no_trap(); 18920Sstevel@tonic-gate 18930Sstevel@tonic-gate return (err); 18940Sstevel@tonic-gate } 1895