17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 500d0963fSdilpreet * Common Development and Distribution License (the "License"). 600d0963fSdilpreet * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217b93957cSeota 227c478bd9Sstevel@tonic-gate /* 237417cfdeSKuriakose Kuruvilla * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 24a7175e20SGarrett D'Amore * Copyright 2012 Garrett D'Amore <garrett@damore.org> 25a7175e20SGarrett D'Amore * Copyright 2014 Pluribus Networks, Inc. 26e373b6e4SYuri Pankov * Copyright 2016 Nexenta Systems, Inc. 277c478bd9Sstevel@tonic-gate */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * PC specific DDI implementation 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate #include <sys/types.h> 337c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 347c478bd9Sstevel@tonic-gate #include <sys/avintr.h> 357c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 367c478bd9Sstevel@tonic-gate #include <sys/conf.h> 377c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 387c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 397c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 407c478bd9Sstevel@tonic-gate #include <sys/ethernet.h> 417c478bd9Sstevel@tonic-gate #include <sys/fp.h> 427c478bd9Sstevel@tonic-gate #include <sys/instance.h> 437c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 447c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 457c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 467c478bd9Sstevel@tonic-gate #include <sys/promif.h> 477c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 487c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 497c478bd9Sstevel@tonic-gate #include <sys/ndi_impldefs.h> 507c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 517c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 527c478bd9Sstevel@tonic-gate #include <sys/systeminfo.h> 537c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 547c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 557c478bd9Sstevel@tonic-gate #include <sys/spl.h> 567c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 577c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 587c478bd9Sstevel@tonic-gate #include <sys/ontrap.h> 5900d0963fSdilpreet #include <sys/fm/protocol.h> 607c478bd9Sstevel@tonic-gate #include <sys/ramdisk.h> 617c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 627c478bd9Sstevel@tonic-gate #include <sys/vmem.h> 637c478bd9Sstevel@tonic-gate #include <sys/pci_impl.h> 64843e1988Sjohnlev #if defined(__xpv) 65843e1988Sjohnlev #include <sys/hypervisor.h> 66843e1988Sjohnlev #endif 677a364d25Sschwartz #include <sys/mach_intr.h> 687b93957cSeota #include <vm/hat_i86.h> 697b93957cSeota #include <sys/x86_archext.h> 70a7175e20SGarrett D'Amore #include <sys/avl.h> 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * DDI Boot Configuration 747c478bd9Sstevel@tonic-gate */ 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate /* 772df1fe9cSrandyf * Platform drivers on this platform 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate char *platform_module_list[] = { 802df1fe9cSrandyf "acpippm", 815cff7825Smh27603 "ppm", 827c478bd9Sstevel@tonic-gate (char *)0 837c478bd9Sstevel@tonic-gate }; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate /* pci bus resource maps */ 867c478bd9Sstevel@tonic-gate struct pci_bus_resource *pci_bus_res; 877c478bd9Sstevel@tonic-gate 8836945f79Smrj size_t dma_max_copybuf_size = 0x101000; /* 1M + 4K */ 8936945f79Smrj 907c478bd9Sstevel@tonic-gate uint64_t ramdisk_start, ramdisk_end; 917c478bd9Sstevel@tonic-gate 9278323854SJudy Chen int pseudo_isa = 0; 9378323854SJudy Chen 947c478bd9Sstevel@tonic-gate /* 957c478bd9Sstevel@tonic-gate * Forward declarations 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate static int getlongprop_buf(); 987c478bd9Sstevel@tonic-gate static void get_boot_properties(void); 997c478bd9Sstevel@tonic-gate static void impl_bus_initialprobe(void); 1007c478bd9Sstevel@tonic-gate static void impl_bus_reprobe(void); 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate static int poke_mem(peekpoke_ctlops_t *in_args); 1037c478bd9Sstevel@tonic-gate static int peek_mem(peekpoke_ctlops_t *in_args); 1047c478bd9Sstevel@tonic-gate 1057b93957cSeota static int kmem_override_cache_attrs(caddr_t, size_t, uint_t); 1067b93957cSeota 1073a634bfcSVikram Hegde #if defined(__amd64) && !defined(__xpv) 1083a634bfcSVikram Hegde extern void immu_init(void); 1093a634bfcSVikram Hegde #endif 1103a634bfcSVikram Hegde 111a7175e20SGarrett D'Amore /* 112a7175e20SGarrett D'Amore * We use an AVL tree to store contiguous address allocations made with the 113a7175e20SGarrett D'Amore * kalloca() routine, so that we can return the size to free with kfreea(). 114a7175e20SGarrett D'Amore * Note that in the future it would be vastly faster if we could eliminate 115a7175e20SGarrett D'Amore * this lookup by insisting that all callers keep track of their own sizes, 116a7175e20SGarrett D'Amore * just as for kmem_alloc(). 117a7175e20SGarrett D'Amore */ 118a7175e20SGarrett D'Amore struct ctgas { 119a7175e20SGarrett D'Amore avl_node_t ctg_link; 120a7175e20SGarrett D'Amore void *ctg_addr; 121a7175e20SGarrett D'Amore size_t ctg_size; 122a7175e20SGarrett D'Amore }; 1237c478bd9Sstevel@tonic-gate 124a7175e20SGarrett D'Amore static avl_tree_t ctgtree; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate static kmutex_t ctgmutex; 1277c478bd9Sstevel@tonic-gate #define CTGLOCK() mutex_enter(&ctgmutex) 1287c478bd9Sstevel@tonic-gate #define CTGUNLOCK() mutex_exit(&ctgmutex) 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* 1317c478bd9Sstevel@tonic-gate * Minimum pfn value of page_t's put on the free list. This is to simplify 1327c478bd9Sstevel@tonic-gate * support of ddi dma memory requests which specify small, non-zero addr_lo 1337c478bd9Sstevel@tonic-gate * values. 1347c478bd9Sstevel@tonic-gate * 1357c478bd9Sstevel@tonic-gate * The default value of 2, which corresponds to the only known non-zero addr_lo 1367c478bd9Sstevel@tonic-gate * value used, means a single page will be sacrificed (pfn typically starts 1377c478bd9Sstevel@tonic-gate * at 1). ddiphysmin can be set to 0 to disable. It cannot be set above 0x100 1387c478bd9Sstevel@tonic-gate * otherwise mp startup panics. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate pfn_t ddiphysmin = 2; 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate static void 1437c478bd9Sstevel@tonic-gate check_driver_disable(void) 1447c478bd9Sstevel@tonic-gate { 1457c478bd9Sstevel@tonic-gate int proplen = 128; 1467c478bd9Sstevel@tonic-gate char *prop_name; 1477c478bd9Sstevel@tonic-gate char *drv_name, *propval; 1487c478bd9Sstevel@tonic-gate major_t major; 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate prop_name = kmem_alloc(proplen, KM_SLEEP); 1517c478bd9Sstevel@tonic-gate for (major = 0; major < devcnt; major++) { 1527c478bd9Sstevel@tonic-gate drv_name = ddi_major_to_name(major); 1537c478bd9Sstevel@tonic-gate if (drv_name == NULL) 1547c478bd9Sstevel@tonic-gate continue; 1557c478bd9Sstevel@tonic-gate (void) snprintf(prop_name, proplen, "disable-%s", drv_name); 1567c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, ddi_root_node(), 1577c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, prop_name, &propval) == DDI_SUCCESS) { 1587c478bd9Sstevel@tonic-gate if (strcmp(propval, "true") == 0) { 1597c478bd9Sstevel@tonic-gate devnamesp[major].dn_flags |= DN_DRIVER_REMOVED; 1607c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "driver %s disabled", 1617c478bd9Sstevel@tonic-gate drv_name); 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate ddi_prop_free(propval); 1647c478bd9Sstevel@tonic-gate } 1657c478bd9Sstevel@tonic-gate } 1667c478bd9Sstevel@tonic-gate kmem_free(prop_name, proplen); 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate /* 1717c478bd9Sstevel@tonic-gate * Configure the hardware on the system. 1727c478bd9Sstevel@tonic-gate * Called before the rootfs is mounted 1737c478bd9Sstevel@tonic-gate */ 1747c478bd9Sstevel@tonic-gate void 1757c478bd9Sstevel@tonic-gate configure(void) 1767c478bd9Sstevel@tonic-gate { 1777c478bd9Sstevel@tonic-gate extern void i_ddi_init_root(); 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate #if defined(__i386) 1807c478bd9Sstevel@tonic-gate extern int fpu_pentium_fdivbug; 1817c478bd9Sstevel@tonic-gate #endif /* __i386 */ 1827c478bd9Sstevel@tonic-gate extern int fpu_ignored; 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* 1857c478bd9Sstevel@tonic-gate * Determine if an FPU is attached 1867c478bd9Sstevel@tonic-gate */ 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate fpu_probe(); 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate #if defined(__i386) 1917c478bd9Sstevel@tonic-gate if (fpu_pentium_fdivbug) { 1927c478bd9Sstevel@tonic-gate printf("\ 1937c478bd9Sstevel@tonic-gate FP hardware exhibits Pentium floating point divide problem\n"); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate #endif /* __i386 */ 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate if (fpu_ignored) { 1987c478bd9Sstevel@tonic-gate printf("FP hardware will not be used\n"); 1997c478bd9Sstevel@tonic-gate } else if (!fpu_exists) { 2007c478bd9Sstevel@tonic-gate printf("No FPU in configuration\n"); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate /* 2047c478bd9Sstevel@tonic-gate * Initialize devices on the machine. 2057c478bd9Sstevel@tonic-gate * Uses configuration tree built by the PROMs to determine what 2067c478bd9Sstevel@tonic-gate * is present, and builds a tree of prototype dev_info nodes 2077c478bd9Sstevel@tonic-gate * corresponding to the hardware which identified itself. 2087c478bd9Sstevel@tonic-gate */ 209db9ce1c9SJerry Gilliam 2107c478bd9Sstevel@tonic-gate /* 211288e2932SJerry Gilliam * Initialize root node. 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate i_ddi_init_root(); 2147c478bd9Sstevel@tonic-gate 21537d6e245Slipeng sang - Sun Microsystems - Beijing China /* reprogram devices not set up by firmware (BIOS) */ 21637d6e245Slipeng sang - Sun Microsystems - Beijing China impl_bus_reprobe(); 21737d6e245Slipeng sang - Sun Microsystems - Beijing China 2183a634bfcSVikram Hegde #if defined(__amd64) && !defined(__xpv) 2193a634bfcSVikram Hegde /* 2203a634bfcSVikram Hegde * Setup but don't startup the IOMMU 2213a634bfcSVikram Hegde * Startup happens later via a direct call 2223a634bfcSVikram Hegde * to IOMMU code by boot code. 2233a634bfcSVikram Hegde * At this point, all PCI bus renumbering 2243a634bfcSVikram Hegde * is done, so safe to init the IMMU 2253a634bfcSVikram Hegde * AKA Intel IOMMU. 2263a634bfcSVikram Hegde */ 2273a634bfcSVikram Hegde immu_init(); 2283a634bfcSVikram Hegde #endif 2293a634bfcSVikram Hegde 2307c478bd9Sstevel@tonic-gate /* 2317c478bd9Sstevel@tonic-gate * attach the isa nexus to get ACPI resource usage 2327c478bd9Sstevel@tonic-gate * isa is "kind of" a pseudo node 2337c478bd9Sstevel@tonic-gate */ 234843e1988Sjohnlev #if defined(__xpv) 23578323854SJudy Chen if (DOMAIN_IS_INITDOMAIN(xen_info)) { 23678323854SJudy Chen if (pseudo_isa) 2377c478bd9Sstevel@tonic-gate (void) i_ddi_attach_pseudo_node("isa"); 23878323854SJudy Chen else 23978323854SJudy Chen (void) i_ddi_attach_hw_nodes("isa"); 24078323854SJudy Chen } 241843e1988Sjohnlev #else 24278323854SJudy Chen if (pseudo_isa) 243843e1988Sjohnlev (void) i_ddi_attach_pseudo_node("isa"); 24478323854SJudy Chen else 24578323854SJudy Chen (void) i_ddi_attach_hw_nodes("isa"); 246843e1988Sjohnlev #endif 2477c478bd9Sstevel@tonic-gate } 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate /* 2507c478bd9Sstevel@tonic-gate * The "status" property indicates the operational status of a device. 2517c478bd9Sstevel@tonic-gate * If this property is present, the value is a string indicating the 2527c478bd9Sstevel@tonic-gate * status of the device as follows: 2537c478bd9Sstevel@tonic-gate * 2547c478bd9Sstevel@tonic-gate * "okay" operational. 2557c478bd9Sstevel@tonic-gate * "disabled" not operational, but might become operational. 2567c478bd9Sstevel@tonic-gate * "fail" not operational because a fault has been detected, 2577c478bd9Sstevel@tonic-gate * and it is unlikely that the device will become 2587c478bd9Sstevel@tonic-gate * operational without repair. no additional details 2597c478bd9Sstevel@tonic-gate * are available. 2607c478bd9Sstevel@tonic-gate * "fail-xxx" not operational because a fault has been detected, 2617c478bd9Sstevel@tonic-gate * and it is unlikely that the device will become 2627c478bd9Sstevel@tonic-gate * operational without repair. "xxx" is additional 2637c478bd9Sstevel@tonic-gate * human-readable information about the particular 2647c478bd9Sstevel@tonic-gate * fault condition that was detected. 2657c478bd9Sstevel@tonic-gate * 2667c478bd9Sstevel@tonic-gate * The absence of this property means that the operational status is 2677c478bd9Sstevel@tonic-gate * unknown or okay. 2687c478bd9Sstevel@tonic-gate * 2697c478bd9Sstevel@tonic-gate * This routine checks the status property of the specified device node 2707c478bd9Sstevel@tonic-gate * and returns 0 if the operational status indicates failure, and 1 otherwise. 2717c478bd9Sstevel@tonic-gate * 2727c478bd9Sstevel@tonic-gate * The property may exist on plug-in cards the existed before IEEE 1275-1994. 2737c478bd9Sstevel@tonic-gate * And, in that case, the property may not even be a string. So we carefully 2747c478bd9Sstevel@tonic-gate * check for the value "fail", in the beginning of the string, noting 2757c478bd9Sstevel@tonic-gate * the property length. 2767c478bd9Sstevel@tonic-gate */ 2777c478bd9Sstevel@tonic-gate int 2787c478bd9Sstevel@tonic-gate status_okay(int id, char *buf, int buflen) 2797c478bd9Sstevel@tonic-gate { 2807c478bd9Sstevel@tonic-gate char status_buf[OBP_MAXPROPNAME]; 2817c478bd9Sstevel@tonic-gate char *bufp = buf; 2827c478bd9Sstevel@tonic-gate int len = buflen; 2837c478bd9Sstevel@tonic-gate int proplen; 2847c478bd9Sstevel@tonic-gate static const char *status = "status"; 2857c478bd9Sstevel@tonic-gate static const char *fail = "fail"; 2867c478bd9Sstevel@tonic-gate int fail_len = (int)strlen(fail); 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate /* 2897c478bd9Sstevel@tonic-gate * Get the proplen ... if it's smaller than "fail", 2907c478bd9Sstevel@tonic-gate * or doesn't exist ... then we don't care, since 2917c478bd9Sstevel@tonic-gate * the value can't begin with the char string "fail". 2927c478bd9Sstevel@tonic-gate * 2937c478bd9Sstevel@tonic-gate * NB: proplen, if it's a string, includes the NULL in the 2947c478bd9Sstevel@tonic-gate * the size of the property, and fail_len does not. 2957c478bd9Sstevel@tonic-gate */ 296fa9e4066Sahrens proplen = prom_getproplen((pnode_t)id, (caddr_t)status); 2977c478bd9Sstevel@tonic-gate if (proplen <= fail_len) /* nonexistant or uninteresting len */ 2987c478bd9Sstevel@tonic-gate return (1); 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate /* 3017c478bd9Sstevel@tonic-gate * if a buffer was provided, use it 3027c478bd9Sstevel@tonic-gate */ 3037c478bd9Sstevel@tonic-gate if ((buf == (char *)NULL) || (buflen <= 0)) { 3047c478bd9Sstevel@tonic-gate bufp = status_buf; 3057c478bd9Sstevel@tonic-gate len = sizeof (status_buf); 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate *bufp = (char)0; 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate /* 3107c478bd9Sstevel@tonic-gate * Get the property into the buffer, to the extent of the buffer, 3117c478bd9Sstevel@tonic-gate * and in case the buffer is smaller than the property size, 3127c478bd9Sstevel@tonic-gate * NULL terminate the buffer. (This handles the case where 3137c478bd9Sstevel@tonic-gate * a buffer was passed in and the caller wants to print the 3147c478bd9Sstevel@tonic-gate * value, but the buffer was too small). 3157c478bd9Sstevel@tonic-gate */ 316fa9e4066Sahrens (void) prom_bounded_getprop((pnode_t)id, (caddr_t)status, 3177c478bd9Sstevel@tonic-gate (caddr_t)bufp, len); 3187c478bd9Sstevel@tonic-gate *(bufp + len - 1) = (char)0; 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate /* 3217c478bd9Sstevel@tonic-gate * If the value begins with the char string "fail", 3227c478bd9Sstevel@tonic-gate * then it means the node is failed. We don't care 3237c478bd9Sstevel@tonic-gate * about any other values. We assume the node is ok 3247c478bd9Sstevel@tonic-gate * although it might be 'disabled'. 3257c478bd9Sstevel@tonic-gate */ 3267c478bd9Sstevel@tonic-gate if (strncmp(bufp, fail, fail_len) == 0) 3277c478bd9Sstevel@tonic-gate return (0); 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate return (1); 3307c478bd9Sstevel@tonic-gate } 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate /* 3337c478bd9Sstevel@tonic-gate * Check the status of the device node passed as an argument. 3347c478bd9Sstevel@tonic-gate * 3357c478bd9Sstevel@tonic-gate * if ((status is OKAY) || (status is DISABLED)) 3367c478bd9Sstevel@tonic-gate * return DDI_SUCCESS 3377c478bd9Sstevel@tonic-gate * else 3387c478bd9Sstevel@tonic-gate * print a warning and return DDI_FAILURE 3397c478bd9Sstevel@tonic-gate */ 3407c478bd9Sstevel@tonic-gate /*ARGSUSED1*/ 3417c478bd9Sstevel@tonic-gate int 3427c478bd9Sstevel@tonic-gate check_status(int id, char *name, dev_info_t *parent) 3437c478bd9Sstevel@tonic-gate { 3447c478bd9Sstevel@tonic-gate char status_buf[64]; 3457c478bd9Sstevel@tonic-gate char devtype_buf[OBP_MAXPROPNAME]; 3467c478bd9Sstevel@tonic-gate int retval = DDI_FAILURE; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate /* 3497c478bd9Sstevel@tonic-gate * is the status okay? 3507c478bd9Sstevel@tonic-gate */ 3517c478bd9Sstevel@tonic-gate if (status_okay(id, status_buf, sizeof (status_buf))) 3527c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 3537c478bd9Sstevel@tonic-gate 3547c478bd9Sstevel@tonic-gate /* 3557c478bd9Sstevel@tonic-gate * a status property indicating bad memory will be associated 3567c478bd9Sstevel@tonic-gate * with a node which has a "device_type" property with a value of 3577c478bd9Sstevel@tonic-gate * "memory-controller". in this situation, return DDI_SUCCESS 3587c478bd9Sstevel@tonic-gate */ 3597c478bd9Sstevel@tonic-gate if (getlongprop_buf(id, OBP_DEVICETYPE, devtype_buf, 3607c478bd9Sstevel@tonic-gate sizeof (devtype_buf)) > 0) { 3617c478bd9Sstevel@tonic-gate if (strcmp(devtype_buf, "memory-controller") == 0) 3627c478bd9Sstevel@tonic-gate retval = DDI_SUCCESS; 3637c478bd9Sstevel@tonic-gate } 3647c478bd9Sstevel@tonic-gate 3657c478bd9Sstevel@tonic-gate /* 3667c478bd9Sstevel@tonic-gate * print the status property information 3677c478bd9Sstevel@tonic-gate */ 3687c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "status '%s' for '%s'", status_buf, name); 3697c478bd9Sstevel@tonic-gate return (retval); 3707c478bd9Sstevel@tonic-gate } 3717c478bd9Sstevel@tonic-gate 3727c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3737c478bd9Sstevel@tonic-gate uint_t 3747c478bd9Sstevel@tonic-gate softlevel1(caddr_t arg1, caddr_t arg2) 3757c478bd9Sstevel@tonic-gate { 3767c478bd9Sstevel@tonic-gate softint(); 3777c478bd9Sstevel@tonic-gate return (1); 3787c478bd9Sstevel@tonic-gate } 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate /* 3817c478bd9Sstevel@tonic-gate * Allow for implementation specific correction of PROM property values. 3827c478bd9Sstevel@tonic-gate */ 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 3857c478bd9Sstevel@tonic-gate void 3867c478bd9Sstevel@tonic-gate impl_fix_props(dev_info_t *dip, dev_info_t *ch_dip, char *name, int len, 3877c478bd9Sstevel@tonic-gate caddr_t buffer) 3887c478bd9Sstevel@tonic-gate { 3897c478bd9Sstevel@tonic-gate /* 3907c478bd9Sstevel@tonic-gate * There are no adjustments needed in this implementation. 3917c478bd9Sstevel@tonic-gate */ 3927c478bd9Sstevel@tonic-gate } 3937c478bd9Sstevel@tonic-gate 3947c478bd9Sstevel@tonic-gate static int 3957c478bd9Sstevel@tonic-gate getlongprop_buf(int id, char *name, char *buf, int maxlen) 3967c478bd9Sstevel@tonic-gate { 3977c478bd9Sstevel@tonic-gate int size; 3987c478bd9Sstevel@tonic-gate 399fa9e4066Sahrens size = prom_getproplen((pnode_t)id, name); 4007c478bd9Sstevel@tonic-gate if (size <= 0 || (size > maxlen - 1)) 4017c478bd9Sstevel@tonic-gate return (-1); 4027c478bd9Sstevel@tonic-gate 403fa9e4066Sahrens if (-1 == prom_getprop((pnode_t)id, name, buf)) 4047c478bd9Sstevel@tonic-gate return (-1); 4057c478bd9Sstevel@tonic-gate 4067c478bd9Sstevel@tonic-gate if (strcmp("name", name) == 0) { 4077c478bd9Sstevel@tonic-gate if (buf[size - 1] != '\0') { 4087c478bd9Sstevel@tonic-gate buf[size] = '\0'; 4097c478bd9Sstevel@tonic-gate size += 1; 4107c478bd9Sstevel@tonic-gate } 4117c478bd9Sstevel@tonic-gate } 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate return (size); 4147c478bd9Sstevel@tonic-gate } 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate static int 4177c478bd9Sstevel@tonic-gate get_prop_int_array(dev_info_t *di, char *pname, int **pval, uint_t *plen) 4187c478bd9Sstevel@tonic-gate { 4197c478bd9Sstevel@tonic-gate int ret; 4207c478bd9Sstevel@tonic-gate 4217c478bd9Sstevel@tonic-gate if ((ret = ddi_prop_lookup_int_array(DDI_DEV_T_ANY, di, 4227c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, pname, pval, plen)) 4237c478bd9Sstevel@tonic-gate == DDI_PROP_SUCCESS) { 4247c478bd9Sstevel@tonic-gate *plen = (*plen) * (sizeof (int)); 4257c478bd9Sstevel@tonic-gate } 4267c478bd9Sstevel@tonic-gate return (ret); 4277c478bd9Sstevel@tonic-gate } 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate 4307c478bd9Sstevel@tonic-gate /* 4317c478bd9Sstevel@tonic-gate * Node Configuration 4327c478bd9Sstevel@tonic-gate */ 4337c478bd9Sstevel@tonic-gate 4347c478bd9Sstevel@tonic-gate struct prop_ispec { 4357c478bd9Sstevel@tonic-gate uint_t pri, vec; 4367c478bd9Sstevel@tonic-gate }; 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate /* 439a195726fSgovinda * For the x86, we're prepared to claim that the interrupt string 440a195726fSgovinda * is in the form of a list of <ipl,vec> specifications. 441a195726fSgovinda */ 442a195726fSgovinda 443a195726fSgovinda #define VEC_MIN 1 444a195726fSgovinda #define VEC_MAX 255 445a195726fSgovinda 446a195726fSgovinda static int 447a195726fSgovinda impl_xlate_intrs(dev_info_t *child, int *in, 448a195726fSgovinda struct ddi_parent_private_data *pdptr) 449a195726fSgovinda { 450a195726fSgovinda size_t size; 451a195726fSgovinda int n; 452a195726fSgovinda struct intrspec *new; 453a195726fSgovinda caddr_t got_prop; 454a195726fSgovinda int *inpri; 455a195726fSgovinda int got_len; 456a195726fSgovinda extern int ignore_hardware_nodes; /* force flag from ddi_impl.c */ 457a195726fSgovinda 458a195726fSgovinda static char bad_intr_fmt[] = 459a195726fSgovinda "bad interrupt spec from %s%d - ipl %d, irq %d\n"; 460a195726fSgovinda 461a195726fSgovinda /* 462a195726fSgovinda * determine if the driver is expecting the new style "interrupts" 463a195726fSgovinda * property which just contains the IRQ, or the old style which 464a195726fSgovinda * contains pairs of <IPL,IRQ>. if it is the new style, we always 465a195726fSgovinda * assign IPL 5 unless an "interrupt-priorities" property exists. 466a195726fSgovinda * in that case, the "interrupt-priorities" property contains the 467a195726fSgovinda * IPL values that match, one for one, the IRQ values in the 468a195726fSgovinda * "interrupts" property. 469a195726fSgovinda */ 470a195726fSgovinda inpri = NULL; 471a195726fSgovinda if ((ddi_getprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 472a195726fSgovinda "ignore-hardware-nodes", -1) != -1) || ignore_hardware_nodes) { 473a195726fSgovinda /* the old style "interrupts" property... */ 474a195726fSgovinda 475a195726fSgovinda /* 476a195726fSgovinda * The list consists of <ipl,vec> elements 477a195726fSgovinda */ 478a195726fSgovinda if ((n = (*in++ >> 1)) < 1) 479a195726fSgovinda return (DDI_FAILURE); 480a195726fSgovinda 481a195726fSgovinda pdptr->par_nintr = n; 482a195726fSgovinda size = n * sizeof (struct intrspec); 483a195726fSgovinda new = pdptr->par_intr = kmem_zalloc(size, KM_SLEEP); 484a195726fSgovinda 485a195726fSgovinda while (n--) { 486a195726fSgovinda int level = *in++; 487a195726fSgovinda int vec = *in++; 488a195726fSgovinda 489a195726fSgovinda if (level < 1 || level > MAXIPL || 490a195726fSgovinda vec < VEC_MIN || vec > VEC_MAX) { 491a195726fSgovinda cmn_err(CE_CONT, bad_intr_fmt, 492a195726fSgovinda DEVI(child)->devi_name, 493a195726fSgovinda DEVI(child)->devi_instance, level, vec); 494a195726fSgovinda goto broken; 495a195726fSgovinda } 496a195726fSgovinda new->intrspec_pri = level; 497a195726fSgovinda if (vec != 2) 498a195726fSgovinda new->intrspec_vec = vec; 499a195726fSgovinda else 500a195726fSgovinda /* 501a195726fSgovinda * irq 2 on the PC bus is tied to irq 9 502a195726fSgovinda * on ISA, EISA and MicroChannel 503a195726fSgovinda */ 504a195726fSgovinda new->intrspec_vec = 9; 505a195726fSgovinda new++; 506a195726fSgovinda } 507a195726fSgovinda 508a195726fSgovinda return (DDI_SUCCESS); 509a195726fSgovinda } else { 510a195726fSgovinda /* the new style "interrupts" property... */ 511a195726fSgovinda 512a195726fSgovinda /* 513a195726fSgovinda * The list consists of <vec> elements 514a195726fSgovinda */ 515a195726fSgovinda if ((n = (*in++)) < 1) 516a195726fSgovinda return (DDI_FAILURE); 517a195726fSgovinda 518a195726fSgovinda pdptr->par_nintr = n; 519a195726fSgovinda size = n * sizeof (struct intrspec); 520a195726fSgovinda new = pdptr->par_intr = kmem_zalloc(size, KM_SLEEP); 521a195726fSgovinda 522a195726fSgovinda /* XXX check for "interrupt-priorities" property... */ 523a195726fSgovinda if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 524a195726fSgovinda "interrupt-priorities", (caddr_t)&got_prop, &got_len) 525a195726fSgovinda == DDI_PROP_SUCCESS) { 526a195726fSgovinda if (n != (got_len / sizeof (int))) { 527a195726fSgovinda cmn_err(CE_CONT, 528a195726fSgovinda "bad interrupt-priorities length" 529a195726fSgovinda " from %s%d: expected %d, got %d\n", 530a195726fSgovinda DEVI(child)->devi_name, 531a195726fSgovinda DEVI(child)->devi_instance, n, 532a195726fSgovinda (int)(got_len / sizeof (int))); 533a195726fSgovinda goto broken; 534a195726fSgovinda } 535a195726fSgovinda inpri = (int *)got_prop; 536a195726fSgovinda } 537a195726fSgovinda 538a195726fSgovinda while (n--) { 539a195726fSgovinda int level; 540a195726fSgovinda int vec = *in++; 541a195726fSgovinda 542a195726fSgovinda if (inpri == NULL) 543a195726fSgovinda level = 5; 544a195726fSgovinda else 545a195726fSgovinda level = *inpri++; 546a195726fSgovinda 547a195726fSgovinda if (level < 1 || level > MAXIPL || 548a195726fSgovinda vec < VEC_MIN || vec > VEC_MAX) { 549a195726fSgovinda cmn_err(CE_CONT, bad_intr_fmt, 550a195726fSgovinda DEVI(child)->devi_name, 551a195726fSgovinda DEVI(child)->devi_instance, level, vec); 552a195726fSgovinda goto broken; 553a195726fSgovinda } 554a195726fSgovinda new->intrspec_pri = level; 555a195726fSgovinda if (vec != 2) 556a195726fSgovinda new->intrspec_vec = vec; 557a195726fSgovinda else 558a195726fSgovinda /* 559a195726fSgovinda * irq 2 on the PC bus is tied to irq 9 560a195726fSgovinda * on ISA, EISA and MicroChannel 561a195726fSgovinda */ 562a195726fSgovinda new->intrspec_vec = 9; 563a195726fSgovinda new++; 564a195726fSgovinda } 565a195726fSgovinda 566a195726fSgovinda if (inpri != NULL) 567a195726fSgovinda kmem_free(got_prop, got_len); 568a195726fSgovinda return (DDI_SUCCESS); 569a195726fSgovinda } 570a195726fSgovinda 571a195726fSgovinda broken: 572a195726fSgovinda kmem_free(pdptr->par_intr, size); 573a195726fSgovinda pdptr->par_intr = NULL; 574a195726fSgovinda pdptr->par_nintr = 0; 575a195726fSgovinda if (inpri != NULL) 576a195726fSgovinda kmem_free(got_prop, got_len); 577a195726fSgovinda 578a195726fSgovinda return (DDI_FAILURE); 579a195726fSgovinda } 580a195726fSgovinda 581a195726fSgovinda /* 5827c478bd9Sstevel@tonic-gate * Create a ddi_parent_private_data structure from the ddi properties of 5837c478bd9Sstevel@tonic-gate * the dev_info node. 5847c478bd9Sstevel@tonic-gate * 5857c478bd9Sstevel@tonic-gate * The "reg" and either an "intr" or "interrupts" properties are required 5867c478bd9Sstevel@tonic-gate * if the driver wishes to create mappings or field interrupts on behalf 5877c478bd9Sstevel@tonic-gate * of the device. 5887c478bd9Sstevel@tonic-gate * 5897c478bd9Sstevel@tonic-gate * The "reg" property is assumed to be a list of at least one triple 5907c478bd9Sstevel@tonic-gate * 5917c478bd9Sstevel@tonic-gate * <bustype, address, size>*1 5927c478bd9Sstevel@tonic-gate * 5937c478bd9Sstevel@tonic-gate * The "intr" property is assumed to be a list of at least one duple 5947c478bd9Sstevel@tonic-gate * 5957c478bd9Sstevel@tonic-gate * <SPARC ipl, vector#>*1 5967c478bd9Sstevel@tonic-gate * 5977c478bd9Sstevel@tonic-gate * The "interrupts" property is assumed to be a list of at least one 5987c478bd9Sstevel@tonic-gate * n-tuples that describes the interrupt capabilities of the bus the device 5997c478bd9Sstevel@tonic-gate * is connected to. For SBus, this looks like 6007c478bd9Sstevel@tonic-gate * 6017c478bd9Sstevel@tonic-gate * <SBus-level>*1 6027c478bd9Sstevel@tonic-gate * 6037c478bd9Sstevel@tonic-gate * (This property obsoletes the 'intr' property). 6047c478bd9Sstevel@tonic-gate * 6057c478bd9Sstevel@tonic-gate * The "ranges" property is optional. 6067c478bd9Sstevel@tonic-gate */ 6077c478bd9Sstevel@tonic-gate void 6087c478bd9Sstevel@tonic-gate make_ddi_ppd(dev_info_t *child, struct ddi_parent_private_data **ppd) 6097c478bd9Sstevel@tonic-gate { 6107c478bd9Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 6117c478bd9Sstevel@tonic-gate int n; 6127c478bd9Sstevel@tonic-gate int *reg_prop, *rng_prop, *intr_prop, *irupts_prop; 6137c478bd9Sstevel@tonic-gate uint_t reg_len, rng_len, intr_len, irupts_len; 6147c478bd9Sstevel@tonic-gate 6157c478bd9Sstevel@tonic-gate *ppd = pdptr = kmem_zalloc(sizeof (*pdptr), KM_SLEEP); 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate /* 6187c478bd9Sstevel@tonic-gate * Handle the 'reg' property. 6197c478bd9Sstevel@tonic-gate */ 6207c478bd9Sstevel@tonic-gate if ((get_prop_int_array(child, "reg", ®_prop, ®_len) == 6217c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS) && (reg_len != 0)) { 6227c478bd9Sstevel@tonic-gate pdptr->par_nreg = reg_len / (int)sizeof (struct regspec); 6237c478bd9Sstevel@tonic-gate pdptr->par_reg = (struct regspec *)reg_prop; 6247c478bd9Sstevel@tonic-gate } 6257c478bd9Sstevel@tonic-gate 6267c478bd9Sstevel@tonic-gate /* 6277c478bd9Sstevel@tonic-gate * See if I have a range (adding one where needed - this 6287c478bd9Sstevel@tonic-gate * means to add one for sbus node in sun4c, when romvec > 0, 6297c478bd9Sstevel@tonic-gate * if no range is already defined in the PROM node. 6307c478bd9Sstevel@tonic-gate * (Currently no sun4c PROMS define range properties, 6317c478bd9Sstevel@tonic-gate * but they should and may in the future.) For the SBus 6327c478bd9Sstevel@tonic-gate * node, the range is defined by the SBus reg property. 6337c478bd9Sstevel@tonic-gate */ 6347c478bd9Sstevel@tonic-gate if (get_prop_int_array(child, "ranges", &rng_prop, &rng_len) 6357c478bd9Sstevel@tonic-gate == DDI_PROP_SUCCESS) { 6367c478bd9Sstevel@tonic-gate pdptr->par_nrng = rng_len / (int)(sizeof (struct rangespec)); 6377c478bd9Sstevel@tonic-gate pdptr->par_rng = (struct rangespec *)rng_prop; 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate /* 6417c478bd9Sstevel@tonic-gate * Handle the 'intr' and 'interrupts' properties 6427c478bd9Sstevel@tonic-gate */ 6437c478bd9Sstevel@tonic-gate 6447c478bd9Sstevel@tonic-gate /* 6457c478bd9Sstevel@tonic-gate * For backwards compatibility 6467c478bd9Sstevel@tonic-gate * we first look for the 'intr' property for the device. 6477c478bd9Sstevel@tonic-gate */ 6487c478bd9Sstevel@tonic-gate if (get_prop_int_array(child, "intr", &intr_prop, &intr_len) 6497c478bd9Sstevel@tonic-gate != DDI_PROP_SUCCESS) { 6507c478bd9Sstevel@tonic-gate intr_len = 0; 6517c478bd9Sstevel@tonic-gate } 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate /* 6547c478bd9Sstevel@tonic-gate * If we're to support bus adapters and future platforms cleanly, 6557c478bd9Sstevel@tonic-gate * we need to support the generalized 'interrupts' property. 6567c478bd9Sstevel@tonic-gate */ 6577c478bd9Sstevel@tonic-gate if (get_prop_int_array(child, "interrupts", &irupts_prop, 6587c478bd9Sstevel@tonic-gate &irupts_len) != DDI_PROP_SUCCESS) { 6597c478bd9Sstevel@tonic-gate irupts_len = 0; 6607c478bd9Sstevel@tonic-gate } else if (intr_len != 0) { 6617c478bd9Sstevel@tonic-gate /* 6627c478bd9Sstevel@tonic-gate * If both 'intr' and 'interrupts' are defined, 6637c478bd9Sstevel@tonic-gate * then 'interrupts' wins and we toss the 'intr' away. 6647c478bd9Sstevel@tonic-gate */ 6657c478bd9Sstevel@tonic-gate ddi_prop_free((void *)intr_prop); 6667c478bd9Sstevel@tonic-gate intr_len = 0; 6677c478bd9Sstevel@tonic-gate } 6687c478bd9Sstevel@tonic-gate 6697c478bd9Sstevel@tonic-gate if (intr_len != 0) { 6707c478bd9Sstevel@tonic-gate 6717c478bd9Sstevel@tonic-gate /* 6727c478bd9Sstevel@tonic-gate * Translate the 'intr' property into an array 6737c478bd9Sstevel@tonic-gate * an array of struct intrspec's. There's not really 6747c478bd9Sstevel@tonic-gate * very much to do here except copy what's out there. 6757c478bd9Sstevel@tonic-gate */ 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate struct intrspec *new; 6787c478bd9Sstevel@tonic-gate struct prop_ispec *l; 6797c478bd9Sstevel@tonic-gate 680843e1988Sjohnlev n = pdptr->par_nintr = intr_len / sizeof (struct prop_ispec); 6817c478bd9Sstevel@tonic-gate l = (struct prop_ispec *)intr_prop; 6827c478bd9Sstevel@tonic-gate pdptr->par_intr = 6837c478bd9Sstevel@tonic-gate new = kmem_zalloc(n * sizeof (struct intrspec), KM_SLEEP); 6847c478bd9Sstevel@tonic-gate while (n--) { 6857c478bd9Sstevel@tonic-gate new->intrspec_pri = l->pri; 6867c478bd9Sstevel@tonic-gate new->intrspec_vec = l->vec; 6877c478bd9Sstevel@tonic-gate new++; 6887c478bd9Sstevel@tonic-gate l++; 6897c478bd9Sstevel@tonic-gate } 6907c478bd9Sstevel@tonic-gate ddi_prop_free((void *)intr_prop); 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate } else if ((n = irupts_len) != 0) { 6937c478bd9Sstevel@tonic-gate size_t size; 6947c478bd9Sstevel@tonic-gate int *out; 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate /* 6977c478bd9Sstevel@tonic-gate * Translate the 'interrupts' property into an array 6987c478bd9Sstevel@tonic-gate * of intrspecs for the rest of the DDI framework to 6997c478bd9Sstevel@tonic-gate * toy with. Only our ancestors really know how to 7007c478bd9Sstevel@tonic-gate * do this, so ask 'em. We massage the 'interrupts' 7017c478bd9Sstevel@tonic-gate * property so that it is pre-pended by a count of 7027c478bd9Sstevel@tonic-gate * the number of integers in the argument. 7037c478bd9Sstevel@tonic-gate */ 7047c478bd9Sstevel@tonic-gate size = sizeof (int) + n; 7057c478bd9Sstevel@tonic-gate out = kmem_alloc(size, KM_SLEEP); 7067c478bd9Sstevel@tonic-gate *out = n / sizeof (int); 7077c478bd9Sstevel@tonic-gate bcopy(irupts_prop, out + 1, (size_t)n); 7087c478bd9Sstevel@tonic-gate ddi_prop_free((void *)irupts_prop); 709a195726fSgovinda if (impl_xlate_intrs(child, out, pdptr) != DDI_SUCCESS) { 7107c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, 7117c478bd9Sstevel@tonic-gate "Unable to translate 'interrupts' for %s%d\n", 7127c478bd9Sstevel@tonic-gate DEVI(child)->devi_binding_name, 7137c478bd9Sstevel@tonic-gate DEVI(child)->devi_instance); 7147c478bd9Sstevel@tonic-gate } 7157c478bd9Sstevel@tonic-gate kmem_free(out, size); 7167c478bd9Sstevel@tonic-gate } 7177c478bd9Sstevel@tonic-gate } 7187c478bd9Sstevel@tonic-gate 7197c478bd9Sstevel@tonic-gate /* 7207c478bd9Sstevel@tonic-gate * Name a child 7217c478bd9Sstevel@tonic-gate */ 7227c478bd9Sstevel@tonic-gate static int 7237c478bd9Sstevel@tonic-gate impl_sunbus_name_child(dev_info_t *child, char *name, int namelen) 7247c478bd9Sstevel@tonic-gate { 7257c478bd9Sstevel@tonic-gate /* 7267c478bd9Sstevel@tonic-gate * Fill in parent-private data and this function returns to us 7277c478bd9Sstevel@tonic-gate * an indication if it used "registers" to fill in the data. 7287c478bd9Sstevel@tonic-gate */ 7297c478bd9Sstevel@tonic-gate if (ddi_get_parent_data(child) == NULL) { 7307c478bd9Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 7317c478bd9Sstevel@tonic-gate make_ddi_ppd(child, &pdptr); 7327c478bd9Sstevel@tonic-gate ddi_set_parent_data(child, pdptr); 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate name[0] = '\0'; 7367c478bd9Sstevel@tonic-gate if (sparc_pd_getnreg(child) > 0) { 7377c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", 7387c478bd9Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_bustype, 7397c478bd9Sstevel@tonic-gate (uint_t)sparc_pd_getreg(child, 0)->regspec_addr); 7407c478bd9Sstevel@tonic-gate } 7417c478bd9Sstevel@tonic-gate 7427c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7437c478bd9Sstevel@tonic-gate } 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate /* 7467c478bd9Sstevel@tonic-gate * Called from the bus_ctl op of sunbus (sbus, obio, etc) nexus drivers 7477c478bd9Sstevel@tonic-gate * to implement the DDI_CTLOPS_INITCHILD operation. That is, it names 7487c478bd9Sstevel@tonic-gate * the children of sun busses based on the reg spec. 7497c478bd9Sstevel@tonic-gate * 7507c478bd9Sstevel@tonic-gate * Handles the following properties (in make_ddi_ppd): 7517c478bd9Sstevel@tonic-gate * Property value 7527c478bd9Sstevel@tonic-gate * Name type 7537c478bd9Sstevel@tonic-gate * reg register spec 7547c478bd9Sstevel@tonic-gate * intr old-form interrupt spec 7557c478bd9Sstevel@tonic-gate * interrupts new (bus-oriented) interrupt spec 7567c478bd9Sstevel@tonic-gate * ranges range spec 7577c478bd9Sstevel@tonic-gate */ 7587c478bd9Sstevel@tonic-gate int 7597c478bd9Sstevel@tonic-gate impl_ddi_sunbus_initchild(dev_info_t *child) 7607c478bd9Sstevel@tonic-gate { 7617c478bd9Sstevel@tonic-gate char name[MAXNAMELEN]; 7627c478bd9Sstevel@tonic-gate void impl_ddi_sunbus_removechild(dev_info_t *); 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate /* 7657c478bd9Sstevel@tonic-gate * Name the child, also makes parent private data 7667c478bd9Sstevel@tonic-gate */ 7677c478bd9Sstevel@tonic-gate (void) impl_sunbus_name_child(child, name, MAXNAMELEN); 7687c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 7697c478bd9Sstevel@tonic-gate 7707c478bd9Sstevel@tonic-gate /* 7717c478bd9Sstevel@tonic-gate * Attempt to merge a .conf node; if successful, remove the 7727c478bd9Sstevel@tonic-gate * .conf node. 7737c478bd9Sstevel@tonic-gate */ 7747c478bd9Sstevel@tonic-gate if ((ndi_dev_is_persistent_node(child) == 0) && 7757c478bd9Sstevel@tonic-gate (ndi_merge_node(child, impl_sunbus_name_child) == DDI_SUCCESS)) { 7767c478bd9Sstevel@tonic-gate /* 7777c478bd9Sstevel@tonic-gate * Return failure to remove node 7787c478bd9Sstevel@tonic-gate */ 7797c478bd9Sstevel@tonic-gate impl_ddi_sunbus_removechild(child); 7807c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 7817c478bd9Sstevel@tonic-gate } 7827c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7837c478bd9Sstevel@tonic-gate } 7847c478bd9Sstevel@tonic-gate 7857c478bd9Sstevel@tonic-gate void 7867c478bd9Sstevel@tonic-gate impl_free_ddi_ppd(dev_info_t *dip) 7877c478bd9Sstevel@tonic-gate { 7887c478bd9Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 7897c478bd9Sstevel@tonic-gate size_t n; 7907c478bd9Sstevel@tonic-gate 7917c478bd9Sstevel@tonic-gate if ((pdptr = ddi_get_parent_data(dip)) == NULL) 7927c478bd9Sstevel@tonic-gate return; 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate if ((n = (size_t)pdptr->par_nintr) != 0) 7957c478bd9Sstevel@tonic-gate /* 7967c478bd9Sstevel@tonic-gate * Note that kmem_free is used here (instead of 7977c478bd9Sstevel@tonic-gate * ddi_prop_free) because the contents of the 7987c478bd9Sstevel@tonic-gate * property were placed into a separate buffer and 7997c478bd9Sstevel@tonic-gate * mucked with a bit before being stored in par_intr. 8007c478bd9Sstevel@tonic-gate * The actual return value from the prop lookup 8017c478bd9Sstevel@tonic-gate * was freed with ddi_prop_free previously. 8027c478bd9Sstevel@tonic-gate */ 8037c478bd9Sstevel@tonic-gate kmem_free(pdptr->par_intr, n * sizeof (struct intrspec)); 8047c478bd9Sstevel@tonic-gate 8057c478bd9Sstevel@tonic-gate if ((n = (size_t)pdptr->par_nrng) != 0) 8067c478bd9Sstevel@tonic-gate ddi_prop_free((void *)pdptr->par_rng); 8077c478bd9Sstevel@tonic-gate 8087c478bd9Sstevel@tonic-gate if ((n = pdptr->par_nreg) != 0) 8097c478bd9Sstevel@tonic-gate ddi_prop_free((void *)pdptr->par_reg); 8107c478bd9Sstevel@tonic-gate 8117c478bd9Sstevel@tonic-gate kmem_free(pdptr, sizeof (*pdptr)); 8127c478bd9Sstevel@tonic-gate ddi_set_parent_data(dip, NULL); 8137c478bd9Sstevel@tonic-gate } 8147c478bd9Sstevel@tonic-gate 8157c478bd9Sstevel@tonic-gate void 8167c478bd9Sstevel@tonic-gate impl_ddi_sunbus_removechild(dev_info_t *dip) 8177c478bd9Sstevel@tonic-gate { 8187c478bd9Sstevel@tonic-gate impl_free_ddi_ppd(dip); 8197c478bd9Sstevel@tonic-gate ddi_set_name_addr(dip, NULL); 8207c478bd9Sstevel@tonic-gate /* 8217c478bd9Sstevel@tonic-gate * Strip the node to properly convert it back to prototype form 8227c478bd9Sstevel@tonic-gate */ 8237c478bd9Sstevel@tonic-gate impl_rem_dev_props(dip); 8247c478bd9Sstevel@tonic-gate } 8257c478bd9Sstevel@tonic-gate 8267c478bd9Sstevel@tonic-gate /* 8277c478bd9Sstevel@tonic-gate * DDI Interrupt 8287c478bd9Sstevel@tonic-gate */ 8297c478bd9Sstevel@tonic-gate 8307c478bd9Sstevel@tonic-gate /* 8317c478bd9Sstevel@tonic-gate * turn this on to force isa, eisa, and mca device to ignore the new 8327c478bd9Sstevel@tonic-gate * hardware nodes in the device tree (normally turned on only for 8337c478bd9Sstevel@tonic-gate * drivers that need it by setting the property "ignore-hardware-nodes" 8347c478bd9Sstevel@tonic-gate * in their driver.conf file). 8357c478bd9Sstevel@tonic-gate * 8367c478bd9Sstevel@tonic-gate * 7/31/96 -- Turned off globally. Leaving variable in for the moment 8377c478bd9Sstevel@tonic-gate * as safety valve. 8387c478bd9Sstevel@tonic-gate */ 8397c478bd9Sstevel@tonic-gate int ignore_hardware_nodes = 0; 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate /* 8427c478bd9Sstevel@tonic-gate * Local data 8437c478bd9Sstevel@tonic-gate */ 8447c478bd9Sstevel@tonic-gate static struct impl_bus_promops *impl_busp; 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate 8477c478bd9Sstevel@tonic-gate /* 8487c478bd9Sstevel@tonic-gate * New DDI interrupt framework 8497c478bd9Sstevel@tonic-gate */ 8507c478bd9Sstevel@tonic-gate 8517c478bd9Sstevel@tonic-gate /* 8527c478bd9Sstevel@tonic-gate * i_ddi_intr_ops: 8537c478bd9Sstevel@tonic-gate * 8547c478bd9Sstevel@tonic-gate * This is the interrupt operator function wrapper for the bus function 8557c478bd9Sstevel@tonic-gate * bus_intr_op. 8567c478bd9Sstevel@tonic-gate */ 8577c478bd9Sstevel@tonic-gate int 8587c478bd9Sstevel@tonic-gate i_ddi_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op, 8597c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void * result) 8607c478bd9Sstevel@tonic-gate { 8617c478bd9Sstevel@tonic-gate dev_info_t *pdip = (dev_info_t *)DEVI(dip)->devi_parent; 8627c478bd9Sstevel@tonic-gate int ret = DDI_FAILURE; 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate /* request parent to process this interrupt op */ 8657c478bd9Sstevel@tonic-gate if (NEXUS_HAS_INTR_OP(pdip)) 8667c478bd9Sstevel@tonic-gate ret = (*(DEVI(pdip)->devi_ops->devo_bus_ops->bus_intr_op))( 8677c478bd9Sstevel@tonic-gate pdip, rdip, op, hdlp, result); 8687c478bd9Sstevel@tonic-gate else 8697c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Failed to process interrupt " 8707c478bd9Sstevel@tonic-gate "for %s%d due to down-rev nexus driver %s%d", 8717c478bd9Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip), 8727c478bd9Sstevel@tonic-gate ddi_get_name(pdip), ddi_get_instance(pdip)); 8737c478bd9Sstevel@tonic-gate return (ret); 8747c478bd9Sstevel@tonic-gate } 8757c478bd9Sstevel@tonic-gate 8767c478bd9Sstevel@tonic-gate /* 8777c478bd9Sstevel@tonic-gate * i_ddi_add_softint - allocate and add a soft interrupt to the system 8787c478bd9Sstevel@tonic-gate */ 8797c478bd9Sstevel@tonic-gate int 8807c478bd9Sstevel@tonic-gate i_ddi_add_softint(ddi_softint_hdl_impl_t *hdlp) 8817c478bd9Sstevel@tonic-gate { 8827c478bd9Sstevel@tonic-gate int ret; 8837c478bd9Sstevel@tonic-gate 8847c478bd9Sstevel@tonic-gate /* add soft interrupt handler */ 8857c478bd9Sstevel@tonic-gate ret = add_avsoftintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func, 8867c478bd9Sstevel@tonic-gate DEVI(hdlp->ih_dip)->devi_name, hdlp->ih_cb_arg1, hdlp->ih_cb_arg2); 8877c478bd9Sstevel@tonic-gate return (ret ? DDI_SUCCESS : DDI_FAILURE); 8887c478bd9Sstevel@tonic-gate } 8897c478bd9Sstevel@tonic-gate 8907c478bd9Sstevel@tonic-gate 8917c478bd9Sstevel@tonic-gate void 8927c478bd9Sstevel@tonic-gate i_ddi_remove_softint(ddi_softint_hdl_impl_t *hdlp) 8937c478bd9Sstevel@tonic-gate { 8947c478bd9Sstevel@tonic-gate (void) rem_avsoftintr((void *)hdlp, hdlp->ih_pri, hdlp->ih_cb_func); 8957c478bd9Sstevel@tonic-gate } 8967c478bd9Sstevel@tonic-gate 8977c478bd9Sstevel@tonic-gate 898e23a7e34Slq150181 extern void (*setsoftint)(int, struct av_softinfo *); 899e23a7e34Slq150181 extern boolean_t av_check_softint_pending(struct av_softinfo *, boolean_t); 9007c478bd9Sstevel@tonic-gate 9017c478bd9Sstevel@tonic-gate int 902b08160e2Sgovinda i_ddi_trigger_softint(ddi_softint_hdl_impl_t *hdlp, void *arg2) 9037c478bd9Sstevel@tonic-gate { 904e23a7e34Slq150181 if (av_check_softint_pending(hdlp->ih_pending, B_FALSE)) 905e23a7e34Slq150181 return (DDI_EPENDING); 906b08160e2Sgovinda 907e23a7e34Slq150181 update_avsoftintr_args((void *)hdlp, hdlp->ih_pri, arg2); 908b08160e2Sgovinda 909e23a7e34Slq150181 (*setsoftint)(hdlp->ih_pri, hdlp->ih_pending); 910e23a7e34Slq150181 return (DDI_SUCCESS); 9117c478bd9Sstevel@tonic-gate } 9127c478bd9Sstevel@tonic-gate 9137c478bd9Sstevel@tonic-gate /* 9147c478bd9Sstevel@tonic-gate * i_ddi_set_softint_pri: 9157c478bd9Sstevel@tonic-gate * 9167c478bd9Sstevel@tonic-gate * The way this works is that it first tries to add a softint vector 9177c478bd9Sstevel@tonic-gate * at the new priority in hdlp. If that succeeds; then it removes the 9187c478bd9Sstevel@tonic-gate * existing softint vector at the old priority. 9197c478bd9Sstevel@tonic-gate */ 9207c478bd9Sstevel@tonic-gate int 9217c478bd9Sstevel@tonic-gate i_ddi_set_softint_pri(ddi_softint_hdl_impl_t *hdlp, uint_t old_pri) 9227c478bd9Sstevel@tonic-gate { 923e23a7e34Slq150181 int ret; 924e23a7e34Slq150181 9257c478bd9Sstevel@tonic-gate /* 9267c478bd9Sstevel@tonic-gate * If a softint is pending at the old priority then fail the request. 9277c478bd9Sstevel@tonic-gate */ 928e23a7e34Slq150181 if (av_check_softint_pending(hdlp->ih_pending, B_TRUE)) 9297c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 9307c478bd9Sstevel@tonic-gate 931e23a7e34Slq150181 ret = av_softint_movepri((void *)hdlp, old_pri); 932e23a7e34Slq150181 return (ret ? DDI_SUCCESS : DDI_FAILURE); 9337c478bd9Sstevel@tonic-gate } 9347c478bd9Sstevel@tonic-gate 9357a364d25Sschwartz void 9367a364d25Sschwartz i_ddi_alloc_intr_phdl(ddi_intr_handle_impl_t *hdlp) 9377a364d25Sschwartz { 9387a364d25Sschwartz hdlp->ih_private = (void *)kmem_zalloc(sizeof (ihdl_plat_t), KM_SLEEP); 9397a364d25Sschwartz } 9407a364d25Sschwartz 9417a364d25Sschwartz void 9427a364d25Sschwartz i_ddi_free_intr_phdl(ddi_intr_handle_impl_t *hdlp) 9437a364d25Sschwartz { 9447a364d25Sschwartz kmem_free(hdlp->ih_private, sizeof (ihdl_plat_t)); 9457a364d25Sschwartz hdlp->ih_private = NULL; 9467a364d25Sschwartz } 9477a364d25Sschwartz 948a54f81fbSanish int 949a54f81fbSanish i_ddi_get_intx_nintrs(dev_info_t *dip) 950a54f81fbSanish { 951a54f81fbSanish struct ddi_parent_private_data *pdp; 952a54f81fbSanish 953a54f81fbSanish if ((pdp = ddi_get_parent_data(dip)) == NULL) 954a54f81fbSanish return (0); 955a54f81fbSanish 956a54f81fbSanish return (pdp->par_nintr); 957a54f81fbSanish } 958a54f81fbSanish 9597c478bd9Sstevel@tonic-gate /* 9607c478bd9Sstevel@tonic-gate * DDI Memory/DMA 9617c478bd9Sstevel@tonic-gate */ 9627c478bd9Sstevel@tonic-gate 9637c478bd9Sstevel@tonic-gate /* 9647c478bd9Sstevel@tonic-gate * Support for allocating DMAable memory to implement 9657c478bd9Sstevel@tonic-gate * ddi_dma_mem_alloc(9F) interface. 9667c478bd9Sstevel@tonic-gate */ 9677c478bd9Sstevel@tonic-gate 9687c478bd9Sstevel@tonic-gate #define KA_ALIGN_SHIFT 7 9697c478bd9Sstevel@tonic-gate #define KA_ALIGN (1 << KA_ALIGN_SHIFT) 9707c478bd9Sstevel@tonic-gate #define KA_NCACHE (PAGESHIFT + 1 - KA_ALIGN_SHIFT) 9717c478bd9Sstevel@tonic-gate 9727c478bd9Sstevel@tonic-gate /* 9737c478bd9Sstevel@tonic-gate * Dummy DMA attribute template for kmem_io[].kmem_io_attr. We only 9747c478bd9Sstevel@tonic-gate * care about addr_lo, addr_hi, and align. addr_hi will be dynamically set. 9757c478bd9Sstevel@tonic-gate */ 9767c478bd9Sstevel@tonic-gate 9777c478bd9Sstevel@tonic-gate static ddi_dma_attr_t kmem_io_attr = { 9787c478bd9Sstevel@tonic-gate DMA_ATTR_V0, 9797c478bd9Sstevel@tonic-gate 0x0000000000000000ULL, /* dma_attr_addr_lo */ 9807c478bd9Sstevel@tonic-gate 0x0000000000000000ULL, /* dma_attr_addr_hi */ 9817c478bd9Sstevel@tonic-gate 0x00ffffff, 9827c478bd9Sstevel@tonic-gate 0x1000, /* dma_attr_align */ 9837c478bd9Sstevel@tonic-gate 1, 1, 0xffffffffULL, 0xffffffffULL, 0x1, 1, 0 9847c478bd9Sstevel@tonic-gate }; 9857c478bd9Sstevel@tonic-gate 9867c478bd9Sstevel@tonic-gate /* kmem io memory ranges and indices */ 9877c478bd9Sstevel@tonic-gate enum { 9887c478bd9Sstevel@tonic-gate IO_4P, IO_64G, IO_4G, IO_2G, IO_1G, IO_512M, 9897c478bd9Sstevel@tonic-gate IO_256M, IO_128M, IO_64M, IO_32M, IO_16M, MAX_MEM_RANGES 9907c478bd9Sstevel@tonic-gate }; 9917c478bd9Sstevel@tonic-gate 9927c478bd9Sstevel@tonic-gate static struct { 9937c478bd9Sstevel@tonic-gate vmem_t *kmem_io_arena; 9947c478bd9Sstevel@tonic-gate kmem_cache_t *kmem_io_cache[KA_NCACHE]; 9957c478bd9Sstevel@tonic-gate ddi_dma_attr_t kmem_io_attr; 9967c478bd9Sstevel@tonic-gate } kmem_io[MAX_MEM_RANGES]; 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate static int kmem_io_idx; /* index of first populated kmem_io[] */ 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate static page_t * 10017c478bd9Sstevel@tonic-gate page_create_io_wrapper(void *addr, size_t len, int vmflag, void *arg) 10027c478bd9Sstevel@tonic-gate { 10037c478bd9Sstevel@tonic-gate extern page_t *page_create_io(vnode_t *, u_offset_t, uint_t, 10047c478bd9Sstevel@tonic-gate uint_t, struct as *, caddr_t, ddi_dma_attr_t *); 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate return (page_create_io(&kvp, (u_offset_t)(uintptr_t)addr, len, 10077c478bd9Sstevel@tonic-gate PG_EXCL | ((vmflag & VM_NOSLEEP) ? 0 : PG_WAIT), &kas, addr, arg)); 10087c478bd9Sstevel@tonic-gate } 10097c478bd9Sstevel@tonic-gate 1010843e1988Sjohnlev #ifdef __xpv 1011843e1988Sjohnlev static void 1012843e1988Sjohnlev segkmem_free_io(vmem_t *vmp, void * ptr, size_t size) 1013843e1988Sjohnlev { 1014843e1988Sjohnlev extern void page_destroy_io(page_t *); 1015843e1988Sjohnlev segkmem_xfree(vmp, ptr, size, page_destroy_io); 1016843e1988Sjohnlev } 1017843e1988Sjohnlev #endif 1018843e1988Sjohnlev 10197c478bd9Sstevel@tonic-gate static void * 10207c478bd9Sstevel@tonic-gate segkmem_alloc_io_4P(vmem_t *vmp, size_t size, int vmflag) 10217c478bd9Sstevel@tonic-gate { 10227c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10237c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_4P].kmem_io_attr)); 10247c478bd9Sstevel@tonic-gate } 10257c478bd9Sstevel@tonic-gate 10267c478bd9Sstevel@tonic-gate static void * 10277c478bd9Sstevel@tonic-gate segkmem_alloc_io_64G(vmem_t *vmp, size_t size, int vmflag) 10287c478bd9Sstevel@tonic-gate { 10297c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10307c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_64G].kmem_io_attr)); 10317c478bd9Sstevel@tonic-gate } 10327c478bd9Sstevel@tonic-gate 10337c478bd9Sstevel@tonic-gate static void * 10347c478bd9Sstevel@tonic-gate segkmem_alloc_io_4G(vmem_t *vmp, size_t size, int vmflag) 10357c478bd9Sstevel@tonic-gate { 10367c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10377c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_4G].kmem_io_attr)); 10387c478bd9Sstevel@tonic-gate } 10397c478bd9Sstevel@tonic-gate 10407c478bd9Sstevel@tonic-gate static void * 10417c478bd9Sstevel@tonic-gate segkmem_alloc_io_2G(vmem_t *vmp, size_t size, int vmflag) 10427c478bd9Sstevel@tonic-gate { 10437c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10447c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_2G].kmem_io_attr)); 10457c478bd9Sstevel@tonic-gate } 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate static void * 10487c478bd9Sstevel@tonic-gate segkmem_alloc_io_1G(vmem_t *vmp, size_t size, int vmflag) 10497c478bd9Sstevel@tonic-gate { 10507c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10517c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_1G].kmem_io_attr)); 10527c478bd9Sstevel@tonic-gate } 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate static void * 10557c478bd9Sstevel@tonic-gate segkmem_alloc_io_512M(vmem_t *vmp, size_t size, int vmflag) 10567c478bd9Sstevel@tonic-gate { 10577c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10587c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_512M].kmem_io_attr)); 10597c478bd9Sstevel@tonic-gate } 10607c478bd9Sstevel@tonic-gate 10617c478bd9Sstevel@tonic-gate static void * 10627c478bd9Sstevel@tonic-gate segkmem_alloc_io_256M(vmem_t *vmp, size_t size, int vmflag) 10637c478bd9Sstevel@tonic-gate { 10647c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10657c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_256M].kmem_io_attr)); 10667c478bd9Sstevel@tonic-gate } 10677c478bd9Sstevel@tonic-gate 10687c478bd9Sstevel@tonic-gate static void * 10697c478bd9Sstevel@tonic-gate segkmem_alloc_io_128M(vmem_t *vmp, size_t size, int vmflag) 10707c478bd9Sstevel@tonic-gate { 10717c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10727c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_128M].kmem_io_attr)); 10737c478bd9Sstevel@tonic-gate } 10747c478bd9Sstevel@tonic-gate 10757c478bd9Sstevel@tonic-gate static void * 10767c478bd9Sstevel@tonic-gate segkmem_alloc_io_64M(vmem_t *vmp, size_t size, int vmflag) 10777c478bd9Sstevel@tonic-gate { 10787c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10797c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_64M].kmem_io_attr)); 10807c478bd9Sstevel@tonic-gate } 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate static void * 10837c478bd9Sstevel@tonic-gate segkmem_alloc_io_32M(vmem_t *vmp, size_t size, int vmflag) 10847c478bd9Sstevel@tonic-gate { 10857c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10867c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_32M].kmem_io_attr)); 10877c478bd9Sstevel@tonic-gate } 10887c478bd9Sstevel@tonic-gate 10897c478bd9Sstevel@tonic-gate static void * 10907c478bd9Sstevel@tonic-gate segkmem_alloc_io_16M(vmem_t *vmp, size_t size, int vmflag) 10917c478bd9Sstevel@tonic-gate { 10927c478bd9Sstevel@tonic-gate return (segkmem_xalloc(vmp, NULL, size, vmflag, 0, 10937c478bd9Sstevel@tonic-gate page_create_io_wrapper, &kmem_io[IO_16M].kmem_io_attr)); 10947c478bd9Sstevel@tonic-gate } 10957c478bd9Sstevel@tonic-gate 10967c478bd9Sstevel@tonic-gate struct { 10977c478bd9Sstevel@tonic-gate uint64_t io_limit; 10987c478bd9Sstevel@tonic-gate char *io_name; 10997c478bd9Sstevel@tonic-gate void *(*io_alloc)(vmem_t *, size_t, int); 11007c478bd9Sstevel@tonic-gate int io_initial; /* kmem_io_init during startup */ 11017c478bd9Sstevel@tonic-gate } io_arena_params[MAX_MEM_RANGES] = { 11027c478bd9Sstevel@tonic-gate {0x000fffffffffffffULL, "kmem_io_4P", segkmem_alloc_io_4P, 1}, 11037c478bd9Sstevel@tonic-gate {0x0000000fffffffffULL, "kmem_io_64G", segkmem_alloc_io_64G, 0}, 11047c478bd9Sstevel@tonic-gate {0x00000000ffffffffULL, "kmem_io_4G", segkmem_alloc_io_4G, 1}, 11057c478bd9Sstevel@tonic-gate {0x000000007fffffffULL, "kmem_io_2G", segkmem_alloc_io_2G, 1}, 11067c478bd9Sstevel@tonic-gate {0x000000003fffffffULL, "kmem_io_1G", segkmem_alloc_io_1G, 0}, 11077c478bd9Sstevel@tonic-gate {0x000000001fffffffULL, "kmem_io_512M", segkmem_alloc_io_512M, 0}, 11087c478bd9Sstevel@tonic-gate {0x000000000fffffffULL, "kmem_io_256M", segkmem_alloc_io_256M, 0}, 11097c478bd9Sstevel@tonic-gate {0x0000000007ffffffULL, "kmem_io_128M", segkmem_alloc_io_128M, 0}, 11107c478bd9Sstevel@tonic-gate {0x0000000003ffffffULL, "kmem_io_64M", segkmem_alloc_io_64M, 0}, 11117c478bd9Sstevel@tonic-gate {0x0000000001ffffffULL, "kmem_io_32M", segkmem_alloc_io_32M, 0}, 11127c478bd9Sstevel@tonic-gate {0x0000000000ffffffULL, "kmem_io_16M", segkmem_alloc_io_16M, 1} 11137c478bd9Sstevel@tonic-gate }; 11147c478bd9Sstevel@tonic-gate 11157c478bd9Sstevel@tonic-gate void 11167c478bd9Sstevel@tonic-gate kmem_io_init(int a) 11177c478bd9Sstevel@tonic-gate { 11187c478bd9Sstevel@tonic-gate int c; 11197c478bd9Sstevel@tonic-gate char name[40]; 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate kmem_io[a].kmem_io_arena = vmem_create(io_arena_params[a].io_name, 11227c478bd9Sstevel@tonic-gate NULL, 0, PAGESIZE, io_arena_params[a].io_alloc, 1123843e1988Sjohnlev #ifdef __xpv 1124843e1988Sjohnlev segkmem_free_io, 1125843e1988Sjohnlev #else 1126843e1988Sjohnlev segkmem_free, 1127843e1988Sjohnlev #endif 1128843e1988Sjohnlev heap_arena, 0, VM_SLEEP); 1129843e1988Sjohnlev 11307c478bd9Sstevel@tonic-gate for (c = 0; c < KA_NCACHE; c++) { 11317c478bd9Sstevel@tonic-gate size_t size = KA_ALIGN << c; 11327c478bd9Sstevel@tonic-gate (void) sprintf(name, "%s_%lu", 11337c478bd9Sstevel@tonic-gate io_arena_params[a].io_name, size); 11347c478bd9Sstevel@tonic-gate kmem_io[a].kmem_io_cache[c] = kmem_cache_create(name, 11357c478bd9Sstevel@tonic-gate size, size, NULL, NULL, NULL, NULL, 11367c478bd9Sstevel@tonic-gate kmem_io[a].kmem_io_arena, 0); 11377c478bd9Sstevel@tonic-gate } 11387c478bd9Sstevel@tonic-gate } 11397c478bd9Sstevel@tonic-gate 11407c478bd9Sstevel@tonic-gate /* 11417c478bd9Sstevel@tonic-gate * Return the index of the highest memory range for addr. 11427c478bd9Sstevel@tonic-gate */ 11437c478bd9Sstevel@tonic-gate static int 11447c478bd9Sstevel@tonic-gate kmem_io_index(uint64_t addr) 11457c478bd9Sstevel@tonic-gate { 11467c478bd9Sstevel@tonic-gate int n; 11477c478bd9Sstevel@tonic-gate 11487c478bd9Sstevel@tonic-gate for (n = kmem_io_idx; n < MAX_MEM_RANGES; n++) { 11497c478bd9Sstevel@tonic-gate if (kmem_io[n].kmem_io_attr.dma_attr_addr_hi <= addr) { 11507c478bd9Sstevel@tonic-gate if (kmem_io[n].kmem_io_arena == NULL) 11517c478bd9Sstevel@tonic-gate kmem_io_init(n); 11527c478bd9Sstevel@tonic-gate return (n); 11537c478bd9Sstevel@tonic-gate } 11547c478bd9Sstevel@tonic-gate } 11557c478bd9Sstevel@tonic-gate panic("kmem_io_index: invalid addr - must be at least 16m"); 11567c478bd9Sstevel@tonic-gate 11577c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 11587c478bd9Sstevel@tonic-gate } 11597c478bd9Sstevel@tonic-gate 11607c478bd9Sstevel@tonic-gate /* 11617c478bd9Sstevel@tonic-gate * Return the index of the next kmem_io populated memory range 11627c478bd9Sstevel@tonic-gate * after curindex. 11637c478bd9Sstevel@tonic-gate */ 11647c478bd9Sstevel@tonic-gate static int 11657c478bd9Sstevel@tonic-gate kmem_io_index_next(int curindex) 11667c478bd9Sstevel@tonic-gate { 11677c478bd9Sstevel@tonic-gate int n; 11687c478bd9Sstevel@tonic-gate 11697c478bd9Sstevel@tonic-gate for (n = curindex + 1; n < MAX_MEM_RANGES; n++) { 11707c478bd9Sstevel@tonic-gate if (kmem_io[n].kmem_io_arena) 11717c478bd9Sstevel@tonic-gate return (n); 11727c478bd9Sstevel@tonic-gate } 11737c478bd9Sstevel@tonic-gate return (-1); 11747c478bd9Sstevel@tonic-gate } 11757c478bd9Sstevel@tonic-gate 11767b93957cSeota /* 11777b93957cSeota * allow kmem to be mapped in with different PTE cache attribute settings. 11787b93957cSeota * Used by i_ddi_mem_alloc() 11797b93957cSeota */ 11807b93957cSeota int 11817b93957cSeota kmem_override_cache_attrs(caddr_t kva, size_t size, uint_t order) 11827b93957cSeota { 11837b93957cSeota uint_t hat_flags; 11847b93957cSeota caddr_t kva_end; 11857b93957cSeota uint_t hat_attr; 11867b93957cSeota pfn_t pfn; 11877b93957cSeota 11887b93957cSeota if (hat_getattr(kas.a_hat, kva, &hat_attr) == -1) { 11897b93957cSeota return (-1); 11907b93957cSeota } 11917b93957cSeota 11927b93957cSeota hat_attr &= ~HAT_ORDER_MASK; 11937b93957cSeota hat_attr |= order | HAT_NOSYNC; 11947b93957cSeota hat_flags = HAT_LOAD_LOCK; 11957b93957cSeota 11967b93957cSeota kva_end = (caddr_t)(((uintptr_t)kva + size + PAGEOFFSET) & 11977b93957cSeota (uintptr_t)PAGEMASK); 11987b93957cSeota kva = (caddr_t)((uintptr_t)kva & (uintptr_t)PAGEMASK); 11997b93957cSeota 12007b93957cSeota while (kva < kva_end) { 12017b93957cSeota pfn = hat_getpfnum(kas.a_hat, kva); 12027b93957cSeota hat_unload(kas.a_hat, kva, PAGESIZE, HAT_UNLOAD_UNLOCK); 12037b93957cSeota hat_devload(kas.a_hat, kva, PAGESIZE, pfn, hat_attr, hat_flags); 12047b93957cSeota kva += MMU_PAGESIZE; 12057b93957cSeota } 12067b93957cSeota 12077b93957cSeota return (0); 12087b93957cSeota } 12097b93957cSeota 1210a7175e20SGarrett D'Amore static int 1211a7175e20SGarrett D'Amore ctgcompare(const void *a1, const void *a2) 1212a7175e20SGarrett D'Amore { 1213a7175e20SGarrett D'Amore /* we just want to compare virtual addresses */ 1214a7175e20SGarrett D'Amore a1 = ((struct ctgas *)a1)->ctg_addr; 1215a7175e20SGarrett D'Amore a2 = ((struct ctgas *)a2)->ctg_addr; 1216a7175e20SGarrett D'Amore return (a1 == a2 ? 0 : (a1 < a2 ? -1 : 1)); 1217a7175e20SGarrett D'Amore } 1218a7175e20SGarrett D'Amore 12197c478bd9Sstevel@tonic-gate void 12207c478bd9Sstevel@tonic-gate ka_init(void) 12217c478bd9Sstevel@tonic-gate { 12227c478bd9Sstevel@tonic-gate int a; 1223843e1988Sjohnlev paddr_t maxphysaddr; 1224843e1988Sjohnlev #if !defined(__xpv) 12257c478bd9Sstevel@tonic-gate extern pfn_t physmax; 1226843e1988Sjohnlev 1227843e1988Sjohnlev maxphysaddr = mmu_ptob((paddr_t)physmax) + MMU_PAGEOFFSET; 1228843e1988Sjohnlev #else 1229843e1988Sjohnlev maxphysaddr = mmu_ptob((paddr_t)HYPERVISOR_memory_op( 1230843e1988Sjohnlev XENMEM_maximum_ram_page, NULL)) + MMU_PAGEOFFSET; 1231843e1988Sjohnlev #endif 12327c478bd9Sstevel@tonic-gate 12337c478bd9Sstevel@tonic-gate ASSERT(maxphysaddr <= io_arena_params[0].io_limit); 12347c478bd9Sstevel@tonic-gate 12357c478bd9Sstevel@tonic-gate for (a = 0; a < MAX_MEM_RANGES; a++) { 12367c478bd9Sstevel@tonic-gate if (maxphysaddr >= io_arena_params[a + 1].io_limit) { 12377c478bd9Sstevel@tonic-gate if (maxphysaddr > io_arena_params[a + 1].io_limit) 12387c478bd9Sstevel@tonic-gate io_arena_params[a].io_limit = maxphysaddr; 12397c478bd9Sstevel@tonic-gate else 12407c478bd9Sstevel@tonic-gate a++; 12417c478bd9Sstevel@tonic-gate break; 12427c478bd9Sstevel@tonic-gate } 12437c478bd9Sstevel@tonic-gate } 12447c478bd9Sstevel@tonic-gate kmem_io_idx = a; 12457c478bd9Sstevel@tonic-gate 12467c478bd9Sstevel@tonic-gate for (; a < MAX_MEM_RANGES; a++) { 12477c478bd9Sstevel@tonic-gate kmem_io[a].kmem_io_attr = kmem_io_attr; 12487c478bd9Sstevel@tonic-gate kmem_io[a].kmem_io_attr.dma_attr_addr_hi = 12497c478bd9Sstevel@tonic-gate io_arena_params[a].io_limit; 12507c478bd9Sstevel@tonic-gate /* 12517c478bd9Sstevel@tonic-gate * initialize kmem_io[] arena/cache corresponding to 12527c478bd9Sstevel@tonic-gate * maxphysaddr and to the "common" io memory ranges that 12537c478bd9Sstevel@tonic-gate * have io_initial set to a non-zero value. 12547c478bd9Sstevel@tonic-gate */ 12557c478bd9Sstevel@tonic-gate if (io_arena_params[a].io_initial || a == kmem_io_idx) 12567c478bd9Sstevel@tonic-gate kmem_io_init(a); 12577c478bd9Sstevel@tonic-gate } 1258a7175e20SGarrett D'Amore 1259a7175e20SGarrett D'Amore /* initialize ctgtree */ 1260a7175e20SGarrett D'Amore avl_create(&ctgtree, ctgcompare, sizeof (struct ctgas), 1261a7175e20SGarrett D'Amore offsetof(struct ctgas, ctg_link)); 12627c478bd9Sstevel@tonic-gate } 12637c478bd9Sstevel@tonic-gate 12647c478bd9Sstevel@tonic-gate /* 12657c478bd9Sstevel@tonic-gate * put contig address/size 12667c478bd9Sstevel@tonic-gate */ 12677c478bd9Sstevel@tonic-gate static void * 12687c478bd9Sstevel@tonic-gate putctgas(void *addr, size_t size) 12697c478bd9Sstevel@tonic-gate { 1270a7175e20SGarrett D'Amore struct ctgas *ctgp; 1271a7175e20SGarrett D'Amore if ((ctgp = kmem_zalloc(sizeof (*ctgp), KM_NOSLEEP)) != NULL) { 1272a7175e20SGarrett D'Amore ctgp->ctg_addr = addr; 1273a7175e20SGarrett D'Amore ctgp->ctg_size = size; 12747c478bd9Sstevel@tonic-gate CTGLOCK(); 1275a7175e20SGarrett D'Amore avl_add(&ctgtree, ctgp); 12767c478bd9Sstevel@tonic-gate CTGUNLOCK(); 1277a7175e20SGarrett D'Amore } 12787c478bd9Sstevel@tonic-gate return (ctgp); 12797c478bd9Sstevel@tonic-gate } 12807c478bd9Sstevel@tonic-gate 12817c478bd9Sstevel@tonic-gate /* 12827c478bd9Sstevel@tonic-gate * get contig size by addr 12837c478bd9Sstevel@tonic-gate */ 12847c478bd9Sstevel@tonic-gate static size_t 12857c478bd9Sstevel@tonic-gate getctgsz(void *addr) 12867c478bd9Sstevel@tonic-gate { 1287a7175e20SGarrett D'Amore struct ctgas *ctgp; 1288a7175e20SGarrett D'Amore struct ctgas find; 1289a7175e20SGarrett D'Amore size_t sz = 0; 12907c478bd9Sstevel@tonic-gate 1291a7175e20SGarrett D'Amore find.ctg_addr = addr; 12927c478bd9Sstevel@tonic-gate CTGLOCK(); 1293a7175e20SGarrett D'Amore if ((ctgp = avl_find(&ctgtree, &find, NULL)) != NULL) { 1294a7175e20SGarrett D'Amore avl_remove(&ctgtree, ctgp); 12957c478bd9Sstevel@tonic-gate } 12967c478bd9Sstevel@tonic-gate CTGUNLOCK(); 1297a7175e20SGarrett D'Amore 1298a7175e20SGarrett D'Amore if (ctgp != NULL) { 1299a7175e20SGarrett D'Amore sz = ctgp->ctg_size; 1300a7175e20SGarrett D'Amore kmem_free(ctgp, sizeof (*ctgp)); 1301a7175e20SGarrett D'Amore } 1302a7175e20SGarrett D'Amore 13037c478bd9Sstevel@tonic-gate return (sz); 13047c478bd9Sstevel@tonic-gate } 13057c478bd9Sstevel@tonic-gate 13067c478bd9Sstevel@tonic-gate /* 13077c478bd9Sstevel@tonic-gate * contig_alloc: 13087c478bd9Sstevel@tonic-gate * 13097c478bd9Sstevel@tonic-gate * allocates contiguous memory to satisfy the 'size' and dma attributes 13107c478bd9Sstevel@tonic-gate * specified in 'attr'. 13117c478bd9Sstevel@tonic-gate * 13127c478bd9Sstevel@tonic-gate * Not all of memory need to be physically contiguous if the 13137c478bd9Sstevel@tonic-gate * scatter-gather list length is greater than 1. 13147c478bd9Sstevel@tonic-gate */ 13157c478bd9Sstevel@tonic-gate 13167c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 13177c478bd9Sstevel@tonic-gate void * 13187c478bd9Sstevel@tonic-gate contig_alloc(size_t size, ddi_dma_attr_t *attr, uintptr_t align, int cansleep) 13197c478bd9Sstevel@tonic-gate { 13207c478bd9Sstevel@tonic-gate pgcnt_t pgcnt = btopr(size); 13217c478bd9Sstevel@tonic-gate size_t asize = pgcnt * PAGESIZE; 13227c478bd9Sstevel@tonic-gate page_t *ppl; 13237c478bd9Sstevel@tonic-gate int pflag; 13247c478bd9Sstevel@tonic-gate void *addr; 13257c478bd9Sstevel@tonic-gate 13267c478bd9Sstevel@tonic-gate extern page_t *page_create_io(vnode_t *, u_offset_t, uint_t, 13277c478bd9Sstevel@tonic-gate uint_t, struct as *, caddr_t, ddi_dma_attr_t *); 13287c478bd9Sstevel@tonic-gate 13297c478bd9Sstevel@tonic-gate /* segkmem_xalloc */ 13307c478bd9Sstevel@tonic-gate 13317c478bd9Sstevel@tonic-gate if (align <= PAGESIZE) 13327c478bd9Sstevel@tonic-gate addr = vmem_alloc(heap_arena, asize, 13337c478bd9Sstevel@tonic-gate (cansleep) ? VM_SLEEP : VM_NOSLEEP); 13347c478bd9Sstevel@tonic-gate else 13357c478bd9Sstevel@tonic-gate addr = vmem_xalloc(heap_arena, asize, align, 0, 0, NULL, NULL, 13367c478bd9Sstevel@tonic-gate (cansleep) ? VM_SLEEP : VM_NOSLEEP); 13377c478bd9Sstevel@tonic-gate if (addr) { 13387c478bd9Sstevel@tonic-gate ASSERT(!((uintptr_t)addr & (align - 1))); 13397c478bd9Sstevel@tonic-gate 1340843e1988Sjohnlev if (page_resv(pgcnt, (cansleep) ? KM_SLEEP : KM_NOSLEEP) == 0) { 13417c478bd9Sstevel@tonic-gate vmem_free(heap_arena, addr, asize); 13427c478bd9Sstevel@tonic-gate return (NULL); 13437c478bd9Sstevel@tonic-gate } 13447c478bd9Sstevel@tonic-gate pflag = PG_EXCL; 13457c478bd9Sstevel@tonic-gate 13467c478bd9Sstevel@tonic-gate if (cansleep) 13477c478bd9Sstevel@tonic-gate pflag |= PG_WAIT; 13487c478bd9Sstevel@tonic-gate 13497c478bd9Sstevel@tonic-gate /* 4k req gets from freelists rather than pfn search */ 13507c478bd9Sstevel@tonic-gate if (pgcnt > 1 || align > PAGESIZE) 13517c478bd9Sstevel@tonic-gate pflag |= PG_PHYSCONTIG; 13527c478bd9Sstevel@tonic-gate 13537c478bd9Sstevel@tonic-gate ppl = page_create_io(&kvp, (u_offset_t)(uintptr_t)addr, 13547c478bd9Sstevel@tonic-gate asize, pflag, &kas, (caddr_t)addr, attr); 13557c478bd9Sstevel@tonic-gate 13567c478bd9Sstevel@tonic-gate if (!ppl) { 13577c478bd9Sstevel@tonic-gate vmem_free(heap_arena, addr, asize); 13587c478bd9Sstevel@tonic-gate page_unresv(pgcnt); 13597c478bd9Sstevel@tonic-gate return (NULL); 13607c478bd9Sstevel@tonic-gate } 13617c478bd9Sstevel@tonic-gate 13627c478bd9Sstevel@tonic-gate while (ppl != NULL) { 13637c478bd9Sstevel@tonic-gate page_t *pp = ppl; 13647c478bd9Sstevel@tonic-gate page_sub(&ppl, pp); 13657c478bd9Sstevel@tonic-gate ASSERT(page_iolock_assert(pp)); 13667c478bd9Sstevel@tonic-gate page_io_unlock(pp); 13677c478bd9Sstevel@tonic-gate page_downgrade(pp); 13687c478bd9Sstevel@tonic-gate hat_memload(kas.a_hat, (caddr_t)(uintptr_t)pp->p_offset, 13697c478bd9Sstevel@tonic-gate pp, (PROT_ALL & ~PROT_USER) | 13707c478bd9Sstevel@tonic-gate HAT_NOSYNC, HAT_LOAD_LOCK); 13717c478bd9Sstevel@tonic-gate } 13727c478bd9Sstevel@tonic-gate } 13737c478bd9Sstevel@tonic-gate return (addr); 13747c478bd9Sstevel@tonic-gate } 13757c478bd9Sstevel@tonic-gate 13766bc8bc6aSSherry Moore void 13777c478bd9Sstevel@tonic-gate contig_free(void *addr, size_t size) 13787c478bd9Sstevel@tonic-gate { 13797c478bd9Sstevel@tonic-gate pgcnt_t pgcnt = btopr(size); 13807c478bd9Sstevel@tonic-gate size_t asize = pgcnt * PAGESIZE; 13817c478bd9Sstevel@tonic-gate caddr_t a, ea; 13827c478bd9Sstevel@tonic-gate page_t *pp; 13837c478bd9Sstevel@tonic-gate 13847c478bd9Sstevel@tonic-gate hat_unload(kas.a_hat, addr, asize, HAT_UNLOAD_UNLOCK); 13857c478bd9Sstevel@tonic-gate 13867c478bd9Sstevel@tonic-gate for (a = addr, ea = a + asize; a < ea; a += PAGESIZE) { 1387843e1988Sjohnlev pp = page_find(&kvp, (u_offset_t)(uintptr_t)a); 13887c478bd9Sstevel@tonic-gate if (!pp) 13897c478bd9Sstevel@tonic-gate panic("contig_free: contig pp not found"); 13907c478bd9Sstevel@tonic-gate 13917c478bd9Sstevel@tonic-gate if (!page_tryupgrade(pp)) { 13927c478bd9Sstevel@tonic-gate page_unlock(pp); 13937c478bd9Sstevel@tonic-gate pp = page_lookup(&kvp, 13947c478bd9Sstevel@tonic-gate (u_offset_t)(uintptr_t)a, SE_EXCL); 13957c478bd9Sstevel@tonic-gate if (pp == NULL) 13967c478bd9Sstevel@tonic-gate panic("contig_free: page freed"); 13977c478bd9Sstevel@tonic-gate } 13987c478bd9Sstevel@tonic-gate page_destroy(pp, 0); 13997c478bd9Sstevel@tonic-gate } 14007c478bd9Sstevel@tonic-gate 14017c478bd9Sstevel@tonic-gate page_unresv(pgcnt); 14027c478bd9Sstevel@tonic-gate vmem_free(heap_arena, addr, asize); 14037c478bd9Sstevel@tonic-gate } 14047c478bd9Sstevel@tonic-gate 14057c478bd9Sstevel@tonic-gate /* 14067c478bd9Sstevel@tonic-gate * Allocate from the system, aligned on a specific boundary. 14077c478bd9Sstevel@tonic-gate * The alignment, if non-zero, must be a power of 2. 14087c478bd9Sstevel@tonic-gate */ 14097c478bd9Sstevel@tonic-gate static void * 14107c478bd9Sstevel@tonic-gate kalloca(size_t size, size_t align, int cansleep, int physcontig, 14117c478bd9Sstevel@tonic-gate ddi_dma_attr_t *attr) 14127c478bd9Sstevel@tonic-gate { 14137c478bd9Sstevel@tonic-gate size_t *addr, *raddr, rsize; 14147c478bd9Sstevel@tonic-gate size_t hdrsize = 4 * sizeof (size_t); /* must be power of 2 */ 14157c478bd9Sstevel@tonic-gate int a, i, c; 14167c478bd9Sstevel@tonic-gate vmem_t *vmp; 14177c478bd9Sstevel@tonic-gate kmem_cache_t *cp = NULL; 14187c478bd9Sstevel@tonic-gate 14198a552b2dScth if (attr->dma_attr_addr_lo > mmu_ptob((uint64_t)ddiphysmin)) 14208a552b2dScth return (NULL); 14218a552b2dScth 14227c478bd9Sstevel@tonic-gate align = MAX(align, hdrsize); 14237c478bd9Sstevel@tonic-gate ASSERT((align & (align - 1)) == 0); 14247c478bd9Sstevel@tonic-gate 14257c478bd9Sstevel@tonic-gate /* 14267c478bd9Sstevel@tonic-gate * All of our allocators guarantee 16-byte alignment, so we don't 14277c478bd9Sstevel@tonic-gate * need to reserve additional space for the header. 14287c478bd9Sstevel@tonic-gate * To simplify picking the correct kmem_io_cache, we round up to 14297c478bd9Sstevel@tonic-gate * a multiple of KA_ALIGN. 14307c478bd9Sstevel@tonic-gate */ 14317c478bd9Sstevel@tonic-gate rsize = P2ROUNDUP_TYPED(size + align, KA_ALIGN, size_t); 14327c478bd9Sstevel@tonic-gate 14337c478bd9Sstevel@tonic-gate if (physcontig && rsize > PAGESIZE) { 14347c478bd9Sstevel@tonic-gate if (addr = contig_alloc(size, attr, align, cansleep)) { 14357c478bd9Sstevel@tonic-gate if (!putctgas(addr, size)) 14367c478bd9Sstevel@tonic-gate contig_free(addr, size); 14377c478bd9Sstevel@tonic-gate else 14387c478bd9Sstevel@tonic-gate return (addr); 14397c478bd9Sstevel@tonic-gate } 14407c478bd9Sstevel@tonic-gate return (NULL); 14417c478bd9Sstevel@tonic-gate } 14427c478bd9Sstevel@tonic-gate 14437c478bd9Sstevel@tonic-gate a = kmem_io_index(attr->dma_attr_addr_hi); 14447c478bd9Sstevel@tonic-gate 14457c478bd9Sstevel@tonic-gate if (rsize > PAGESIZE) { 14467c478bd9Sstevel@tonic-gate vmp = kmem_io[a].kmem_io_arena; 14477c478bd9Sstevel@tonic-gate raddr = vmem_alloc(vmp, rsize, 14487c478bd9Sstevel@tonic-gate (cansleep) ? VM_SLEEP : VM_NOSLEEP); 14497c478bd9Sstevel@tonic-gate } else { 14507c478bd9Sstevel@tonic-gate c = highbit((rsize >> KA_ALIGN_SHIFT) - 1); 14517c478bd9Sstevel@tonic-gate cp = kmem_io[a].kmem_io_cache[c]; 14527c478bd9Sstevel@tonic-gate raddr = kmem_cache_alloc(cp, (cansleep) ? KM_SLEEP : 14537c478bd9Sstevel@tonic-gate KM_NOSLEEP); 14547c478bd9Sstevel@tonic-gate } 14557c478bd9Sstevel@tonic-gate 14567c478bd9Sstevel@tonic-gate if (raddr == NULL) { 14577c478bd9Sstevel@tonic-gate int na; 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate ASSERT(cansleep == 0); 14607c478bd9Sstevel@tonic-gate if (rsize > PAGESIZE) 14617c478bd9Sstevel@tonic-gate return (NULL); 14627c478bd9Sstevel@tonic-gate /* 14637c478bd9Sstevel@tonic-gate * System does not have memory in the requested range. 14647c478bd9Sstevel@tonic-gate * Try smaller kmem io ranges and larger cache sizes 14657c478bd9Sstevel@tonic-gate * to see if there might be memory available in 14667c478bd9Sstevel@tonic-gate * these other caches. 14677c478bd9Sstevel@tonic-gate */ 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate for (na = kmem_io_index_next(a); na >= 0; 14707c478bd9Sstevel@tonic-gate na = kmem_io_index_next(na)) { 14717c478bd9Sstevel@tonic-gate ASSERT(kmem_io[na].kmem_io_arena); 14727c478bd9Sstevel@tonic-gate cp = kmem_io[na].kmem_io_cache[c]; 14737c478bd9Sstevel@tonic-gate raddr = kmem_cache_alloc(cp, KM_NOSLEEP); 14747c478bd9Sstevel@tonic-gate if (raddr) 14757c478bd9Sstevel@tonic-gate goto kallocdone; 14767c478bd9Sstevel@tonic-gate } 14777c478bd9Sstevel@tonic-gate /* now try the larger kmem io cache sizes */ 14787c478bd9Sstevel@tonic-gate for (na = a; na >= 0; na = kmem_io_index_next(na)) { 14797c478bd9Sstevel@tonic-gate for (i = c + 1; i < KA_NCACHE; i++) { 14807c478bd9Sstevel@tonic-gate cp = kmem_io[na].kmem_io_cache[i]; 14817c478bd9Sstevel@tonic-gate raddr = kmem_cache_alloc(cp, KM_NOSLEEP); 14827c478bd9Sstevel@tonic-gate if (raddr) 14837c478bd9Sstevel@tonic-gate goto kallocdone; 14847c478bd9Sstevel@tonic-gate } 14857c478bd9Sstevel@tonic-gate } 14867c478bd9Sstevel@tonic-gate return (NULL); 14877c478bd9Sstevel@tonic-gate } 14887c478bd9Sstevel@tonic-gate 14897c478bd9Sstevel@tonic-gate kallocdone: 149088b7b0f2SMatthew Ahrens ASSERT(!P2BOUNDARY((uintptr_t)raddr, rsize, PAGESIZE) || 149188b7b0f2SMatthew Ahrens rsize > PAGESIZE); 14927c478bd9Sstevel@tonic-gate 14937c478bd9Sstevel@tonic-gate addr = (size_t *)P2ROUNDUP((uintptr_t)raddr + hdrsize, align); 14947c478bd9Sstevel@tonic-gate ASSERT((uintptr_t)addr + size - (uintptr_t)raddr <= rsize); 14957c478bd9Sstevel@tonic-gate 14967c478bd9Sstevel@tonic-gate addr[-4] = (size_t)cp; 14977c478bd9Sstevel@tonic-gate addr[-3] = (size_t)vmp; 14987c478bd9Sstevel@tonic-gate addr[-2] = (size_t)raddr; 14997c478bd9Sstevel@tonic-gate addr[-1] = rsize; 15007c478bd9Sstevel@tonic-gate 15017c478bd9Sstevel@tonic-gate return (addr); 15027c478bd9Sstevel@tonic-gate } 15037c478bd9Sstevel@tonic-gate 15047c478bd9Sstevel@tonic-gate static void 15057c478bd9Sstevel@tonic-gate kfreea(void *addr) 15067c478bd9Sstevel@tonic-gate { 15077c478bd9Sstevel@tonic-gate size_t size; 15087c478bd9Sstevel@tonic-gate 15097c478bd9Sstevel@tonic-gate if (!((uintptr_t)addr & PAGEOFFSET) && (size = getctgsz(addr))) { 15107c478bd9Sstevel@tonic-gate contig_free(addr, size); 15117c478bd9Sstevel@tonic-gate } else { 15127c478bd9Sstevel@tonic-gate size_t *saddr = addr; 15137c478bd9Sstevel@tonic-gate if (saddr[-4] == 0) 15147c478bd9Sstevel@tonic-gate vmem_free((vmem_t *)saddr[-3], (void *)saddr[-2], 15157c478bd9Sstevel@tonic-gate saddr[-1]); 15167c478bd9Sstevel@tonic-gate else 15177c478bd9Sstevel@tonic-gate kmem_cache_free((kmem_cache_t *)saddr[-4], 15187c478bd9Sstevel@tonic-gate (void *)saddr[-2]); 15197c478bd9Sstevel@tonic-gate } 15207c478bd9Sstevel@tonic-gate } 15217c478bd9Sstevel@tonic-gate 152283220025Seota /*ARGSUSED*/ 15237b93957cSeota void 15247b93957cSeota i_ddi_devacc_to_hatacc(ddi_device_acc_attr_t *devaccp, uint_t *hataccp) 15257b93957cSeota { 15267b93957cSeota } 15277b93957cSeota 15287b93957cSeota /* 15297b93957cSeota * Check if the specified cache attribute is supported on the platform. 15307b93957cSeota * This function must be called before i_ddi_cacheattr_to_hatacc(). 15317b93957cSeota */ 15327b93957cSeota boolean_t 15337b93957cSeota i_ddi_check_cache_attr(uint_t flags) 15347b93957cSeota { 15357b93957cSeota /* 15367b93957cSeota * The cache attributes are mutually exclusive. Any combination of 15377b93957cSeota * the attributes leads to a failure. 15387b93957cSeota */ 15397b93957cSeota uint_t cache_attr = IOMEM_CACHE_ATTR(flags); 1540de710d24SJosef 'Jeff' Sipek if ((cache_attr != 0) && !ISP2(cache_attr)) 15417b93957cSeota return (B_FALSE); 15427b93957cSeota 15437b93957cSeota /* All cache attributes are supported on X86/X64 */ 15447b93957cSeota if (cache_attr & (IOMEM_DATA_UNCACHED | IOMEM_DATA_CACHED | 15457b93957cSeota IOMEM_DATA_UC_WR_COMBINE)) 15467b93957cSeota return (B_TRUE); 15477b93957cSeota 15487b93957cSeota /* undefined attributes */ 15497b93957cSeota return (B_FALSE); 15507b93957cSeota } 15517b93957cSeota 15527b93957cSeota /* set HAT cache attributes from the cache attributes */ 15537b93957cSeota void 15547b93957cSeota i_ddi_cacheattr_to_hatacc(uint_t flags, uint_t *hataccp) 15557b93957cSeota { 15567b93957cSeota uint_t cache_attr = IOMEM_CACHE_ATTR(flags); 15577b93957cSeota static char *fname = "i_ddi_cacheattr_to_hatacc"; 15587b93957cSeota 15597b93957cSeota /* 15607b93957cSeota * If write-combining is not supported, then it falls back 15617b93957cSeota * to uncacheable. 15627b93957cSeota */ 15637417cfdeSKuriakose Kuruvilla if (cache_attr == IOMEM_DATA_UC_WR_COMBINE && 15647417cfdeSKuriakose Kuruvilla !is_x86_feature(x86_featureset, X86FSET_PAT)) 15657b93957cSeota cache_attr = IOMEM_DATA_UNCACHED; 15667b93957cSeota 15677b93957cSeota /* 15687b93957cSeota * set HAT attrs according to the cache attrs. 15697b93957cSeota */ 15707b93957cSeota switch (cache_attr) { 15717b93957cSeota case IOMEM_DATA_UNCACHED: 15727b93957cSeota *hataccp &= ~HAT_ORDER_MASK; 15737b93957cSeota *hataccp |= (HAT_STRICTORDER | HAT_PLAT_NOCACHE); 15747b93957cSeota break; 15757b93957cSeota case IOMEM_DATA_UC_WR_COMBINE: 15767b93957cSeota *hataccp &= ~HAT_ORDER_MASK; 15777b93957cSeota *hataccp |= (HAT_MERGING_OK | HAT_PLAT_NOCACHE); 15787b93957cSeota break; 15797b93957cSeota case IOMEM_DATA_CACHED: 15807b93957cSeota *hataccp &= ~HAT_ORDER_MASK; 15817b93957cSeota *hataccp |= HAT_UNORDERED_OK; 15827b93957cSeota break; 15837b93957cSeota /* 15847b93957cSeota * This case must not occur because the cache attribute is scrutinized 15857b93957cSeota * before this function is called. 15867b93957cSeota */ 15877b93957cSeota default: 15887b93957cSeota /* 15897b93957cSeota * set cacheable to hat attrs. 15907b93957cSeota */ 15917b93957cSeota *hataccp &= ~HAT_ORDER_MASK; 15927b93957cSeota *hataccp |= HAT_UNORDERED_OK; 15937b93957cSeota cmn_err(CE_WARN, "%s: cache_attr=0x%x is ignored.", 15947b93957cSeota fname, cache_attr); 15957b93957cSeota } 15967b93957cSeota } 15977b93957cSeota 15987b93957cSeota /* 15997c478bd9Sstevel@tonic-gate * This should actually be called i_ddi_dma_mem_alloc. There should 16007c478bd9Sstevel@tonic-gate * also be an i_ddi_pio_mem_alloc. i_ddi_dma_mem_alloc should call 16017c478bd9Sstevel@tonic-gate * through the device tree with the DDI_CTLOPS_DMA_ALIGN ctl ops to 16027c478bd9Sstevel@tonic-gate * get alignment requirements for DMA memory. i_ddi_pio_mem_alloc 16037c478bd9Sstevel@tonic-gate * should use DDI_CTLOPS_PIO_ALIGN. Since we only have i_ddi_mem_alloc 16047c478bd9Sstevel@tonic-gate * so far which is used for both, DMA and PIO, we have to use the DMA 16057c478bd9Sstevel@tonic-gate * ctl ops to make everybody happy. 16067c478bd9Sstevel@tonic-gate */ 16077c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 16087c478bd9Sstevel@tonic-gate int 16097c478bd9Sstevel@tonic-gate i_ddi_mem_alloc(dev_info_t *dip, ddi_dma_attr_t *attr, 16107b93957cSeota size_t length, int cansleep, int flags, 16117c478bd9Sstevel@tonic-gate ddi_device_acc_attr_t *accattrp, caddr_t *kaddrp, 16127c478bd9Sstevel@tonic-gate size_t *real_length, ddi_acc_hdl_t *ap) 16137c478bd9Sstevel@tonic-gate { 16147c478bd9Sstevel@tonic-gate caddr_t a; 16157c478bd9Sstevel@tonic-gate int iomin; 16167c478bd9Sstevel@tonic-gate ddi_acc_impl_t *iap; 16177c478bd9Sstevel@tonic-gate int physcontig = 0; 16187c478bd9Sstevel@tonic-gate pgcnt_t npages; 16197c478bd9Sstevel@tonic-gate pgcnt_t minctg; 16207b93957cSeota uint_t order; 16217b93957cSeota int e; 16227c478bd9Sstevel@tonic-gate 16237c478bd9Sstevel@tonic-gate /* 16247c478bd9Sstevel@tonic-gate * Check legality of arguments 16257c478bd9Sstevel@tonic-gate */ 16267c478bd9Sstevel@tonic-gate if (length == 0 || kaddrp == NULL || attr == NULL) { 16277c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 16287c478bd9Sstevel@tonic-gate } 16297b93957cSeota 16307c478bd9Sstevel@tonic-gate if (attr->dma_attr_minxfer == 0 || attr->dma_attr_align == 0 || 1631de710d24SJosef 'Jeff' Sipek !ISP2(attr->dma_attr_align) || !ISP2(attr->dma_attr_minxfer)) { 16327c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 16337c478bd9Sstevel@tonic-gate } 16347c478bd9Sstevel@tonic-gate 16357c478bd9Sstevel@tonic-gate /* 16367c478bd9Sstevel@tonic-gate * figure out most restrictive alignment requirement 16377c478bd9Sstevel@tonic-gate */ 16387c478bd9Sstevel@tonic-gate iomin = attr->dma_attr_minxfer; 16397c478bd9Sstevel@tonic-gate iomin = maxbit(iomin, attr->dma_attr_align); 16407c478bd9Sstevel@tonic-gate if (iomin == 0) 16417c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 16427c478bd9Sstevel@tonic-gate 16437c478bd9Sstevel@tonic-gate ASSERT((iomin & (iomin - 1)) == 0); 16447c478bd9Sstevel@tonic-gate 16457b93957cSeota /* 16467b93957cSeota * if we allocate memory with IOMEM_DATA_UNCACHED or 16477b93957cSeota * IOMEM_DATA_UC_WR_COMBINE, make sure we allocate a page aligned 16487b93957cSeota * memory that ends on a page boundry. 16497b93957cSeota * Don't want to have to different cache mappings to the same 16507b93957cSeota * physical page. 16517b93957cSeota */ 16527b93957cSeota if (OVERRIDE_CACHE_ATTR(flags)) { 16537b93957cSeota iomin = (iomin + MMU_PAGEOFFSET) & MMU_PAGEMASK; 16547b93957cSeota length = (length + MMU_PAGEOFFSET) & (size_t)MMU_PAGEMASK; 16557b93957cSeota } 16567c478bd9Sstevel@tonic-gate 16577c478bd9Sstevel@tonic-gate /* 16587c478bd9Sstevel@tonic-gate * Determine if we need to satisfy the request for physically 16597c478bd9Sstevel@tonic-gate * contiguous memory or alignments larger than pagesize. 16607c478bd9Sstevel@tonic-gate */ 16617c478bd9Sstevel@tonic-gate npages = btopr(length + attr->dma_attr_align); 16627c478bd9Sstevel@tonic-gate minctg = howmany(npages, attr->dma_attr_sgllen); 16637c478bd9Sstevel@tonic-gate 16647c478bd9Sstevel@tonic-gate if (minctg > 1) { 16657c478bd9Sstevel@tonic-gate uint64_t pfnseg = attr->dma_attr_seg >> PAGESHIFT; 16667c478bd9Sstevel@tonic-gate /* 16677c478bd9Sstevel@tonic-gate * verify that the minimum contig requirement for the 16687c478bd9Sstevel@tonic-gate * actual length does not cross segment boundary. 16697c478bd9Sstevel@tonic-gate */ 16707c478bd9Sstevel@tonic-gate length = P2ROUNDUP_TYPED(length, attr->dma_attr_minxfer, 16717c478bd9Sstevel@tonic-gate size_t); 16727c478bd9Sstevel@tonic-gate npages = btopr(length); 16737c478bd9Sstevel@tonic-gate minctg = howmany(npages, attr->dma_attr_sgllen); 16747c478bd9Sstevel@tonic-gate if (minctg > pfnseg + 1) 16757c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 16767c478bd9Sstevel@tonic-gate physcontig = 1; 16777c478bd9Sstevel@tonic-gate } else { 16787c478bd9Sstevel@tonic-gate length = P2ROUNDUP_TYPED(length, iomin, size_t); 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate 16817c478bd9Sstevel@tonic-gate /* 16827c478bd9Sstevel@tonic-gate * Allocate the requested amount from the system. 16837c478bd9Sstevel@tonic-gate */ 16847c478bd9Sstevel@tonic-gate a = kalloca(length, iomin, cansleep, physcontig, attr); 16857c478bd9Sstevel@tonic-gate 16867c478bd9Sstevel@tonic-gate if ((*kaddrp = a) == NULL) 16877c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 16887c478bd9Sstevel@tonic-gate 16897b93957cSeota /* 16907b93957cSeota * if we to modify the cache attributes, go back and muck with the 16917b93957cSeota * mappings. 16927b93957cSeota */ 16937b93957cSeota if (OVERRIDE_CACHE_ATTR(flags)) { 16947b93957cSeota order = 0; 16957b93957cSeota i_ddi_cacheattr_to_hatacc(flags, &order); 16967b93957cSeota e = kmem_override_cache_attrs(a, length, order); 16977b93957cSeota if (e != 0) { 16987b93957cSeota kfreea(a); 16997b93957cSeota return (DDI_FAILURE); 17007b93957cSeota } 17017b93957cSeota } 17027b93957cSeota 17037c478bd9Sstevel@tonic-gate if (real_length) { 17047c478bd9Sstevel@tonic-gate *real_length = length; 17057c478bd9Sstevel@tonic-gate } 17067c478bd9Sstevel@tonic-gate if (ap) { 17077c478bd9Sstevel@tonic-gate /* 17087c478bd9Sstevel@tonic-gate * initialize access handle 17097c478bd9Sstevel@tonic-gate */ 17107c478bd9Sstevel@tonic-gate iap = (ddi_acc_impl_t *)ap->ah_platform_private; 17117c478bd9Sstevel@tonic-gate iap->ahi_acc_attr |= DDI_ACCATTR_CPU_VADDR; 17127c478bd9Sstevel@tonic-gate impl_acc_hdl_init(ap); 17137c478bd9Sstevel@tonic-gate } 17147b93957cSeota 17157c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 17167c478bd9Sstevel@tonic-gate } 17177c478bd9Sstevel@tonic-gate 17187c478bd9Sstevel@tonic-gate /* ARGSUSED */ 17197c478bd9Sstevel@tonic-gate void 17207b93957cSeota i_ddi_mem_free(caddr_t kaddr, ddi_acc_hdl_t *ap) 17217c478bd9Sstevel@tonic-gate { 17227b93957cSeota if (ap != NULL) { 17237b93957cSeota /* 17247b93957cSeota * if we modified the cache attributes on alloc, go back and 17257b93957cSeota * fix them since this memory could be returned to the 17267b93957cSeota * general pool. 17277b93957cSeota */ 17287b93957cSeota if (OVERRIDE_CACHE_ATTR(ap->ah_xfermodes)) { 17297b93957cSeota uint_t order = 0; 17307b93957cSeota int e; 17317b93957cSeota i_ddi_cacheattr_to_hatacc(IOMEM_DATA_CACHED, &order); 17327b93957cSeota e = kmem_override_cache_attrs(kaddr, ap->ah_len, order); 17337b93957cSeota if (e != 0) { 17347b93957cSeota cmn_err(CE_WARN, "i_ddi_mem_free() failed to " 17357b93957cSeota "override cache attrs, memory leaked\n"); 17367b93957cSeota return; 17377b93957cSeota } 17387b93957cSeota } 17397b93957cSeota } 17407c478bd9Sstevel@tonic-gate kfreea(kaddr); 17417c478bd9Sstevel@tonic-gate } 17427c478bd9Sstevel@tonic-gate 17437c478bd9Sstevel@tonic-gate /* 17447c478bd9Sstevel@tonic-gate * Access Barriers 17457c478bd9Sstevel@tonic-gate * 17467c478bd9Sstevel@tonic-gate */ 17477c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17487c478bd9Sstevel@tonic-gate int 17497c478bd9Sstevel@tonic-gate i_ddi_ontrap(ddi_acc_handle_t hp) 17507c478bd9Sstevel@tonic-gate { 17517c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 17527c478bd9Sstevel@tonic-gate } 17537c478bd9Sstevel@tonic-gate 17547c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17557c478bd9Sstevel@tonic-gate void 17567c478bd9Sstevel@tonic-gate i_ddi_notrap(ddi_acc_handle_t hp) 17577c478bd9Sstevel@tonic-gate { 17587c478bd9Sstevel@tonic-gate } 17597c478bd9Sstevel@tonic-gate 17607c478bd9Sstevel@tonic-gate 17617c478bd9Sstevel@tonic-gate /* 17627c478bd9Sstevel@tonic-gate * Misc Functions 17637c478bd9Sstevel@tonic-gate */ 17647c478bd9Sstevel@tonic-gate 17657c478bd9Sstevel@tonic-gate /* 17667c478bd9Sstevel@tonic-gate * Implementation instance override functions 17677c478bd9Sstevel@tonic-gate * 17687c478bd9Sstevel@tonic-gate * No override on i86pc 17697c478bd9Sstevel@tonic-gate */ 17707c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17717c478bd9Sstevel@tonic-gate uint_t 17727c478bd9Sstevel@tonic-gate impl_assign_instance(dev_info_t *dip) 17737c478bd9Sstevel@tonic-gate { 17747c478bd9Sstevel@tonic-gate return ((uint_t)-1); 17757c478bd9Sstevel@tonic-gate } 17767c478bd9Sstevel@tonic-gate 17777c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17787c478bd9Sstevel@tonic-gate int 17797c478bd9Sstevel@tonic-gate impl_keep_instance(dev_info_t *dip) 17807c478bd9Sstevel@tonic-gate { 1781843e1988Sjohnlev 1782843e1988Sjohnlev #if defined(__xpv) 1783843e1988Sjohnlev /* 1784843e1988Sjohnlev * Do not persist instance numbers assigned to devices in dom0 1785843e1988Sjohnlev */ 1786843e1988Sjohnlev dev_info_t *pdip; 1787843e1988Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info)) { 1788843e1988Sjohnlev if (((pdip = ddi_get_parent(dip)) != NULL) && 1789843e1988Sjohnlev (strcmp(ddi_get_name(pdip), "xpvd") == 0)) 1790843e1988Sjohnlev return (DDI_SUCCESS); 1791843e1988Sjohnlev } 1792843e1988Sjohnlev #endif 17937c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 17947c478bd9Sstevel@tonic-gate } 17957c478bd9Sstevel@tonic-gate 17967c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 17977c478bd9Sstevel@tonic-gate int 17987c478bd9Sstevel@tonic-gate impl_free_instance(dev_info_t *dip) 17997c478bd9Sstevel@tonic-gate { 18007c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 18017c478bd9Sstevel@tonic-gate } 18027c478bd9Sstevel@tonic-gate 18037c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 18047c478bd9Sstevel@tonic-gate int 18057c478bd9Sstevel@tonic-gate impl_check_cpu(dev_info_t *devi) 18067c478bd9Sstevel@tonic-gate { 18077c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 18087c478bd9Sstevel@tonic-gate } 18097c478bd9Sstevel@tonic-gate 18107c478bd9Sstevel@tonic-gate /* 18117c478bd9Sstevel@tonic-gate * Referenced in common/cpr_driver.c: Power off machine. 18127c478bd9Sstevel@tonic-gate * Don't know how to power off i86pc. 18137c478bd9Sstevel@tonic-gate */ 18147c478bd9Sstevel@tonic-gate void 18157c478bd9Sstevel@tonic-gate arch_power_down() 18167c478bd9Sstevel@tonic-gate {} 18177c478bd9Sstevel@tonic-gate 18187c478bd9Sstevel@tonic-gate /* 18197c478bd9Sstevel@tonic-gate * Copy name to property_name, since name 18207c478bd9Sstevel@tonic-gate * is in the low address range below kernelbase. 18217c478bd9Sstevel@tonic-gate */ 18227c478bd9Sstevel@tonic-gate static void 18237c478bd9Sstevel@tonic-gate copy_boot_str(const char *boot_str, char *kern_str, int len) 18247c478bd9Sstevel@tonic-gate { 18257c478bd9Sstevel@tonic-gate int i = 0; 18267c478bd9Sstevel@tonic-gate 18277c478bd9Sstevel@tonic-gate while (i < len - 1 && boot_str[i] != '\0') { 18287c478bd9Sstevel@tonic-gate kern_str[i] = boot_str[i]; 18297c478bd9Sstevel@tonic-gate i++; 18307c478bd9Sstevel@tonic-gate } 18317c478bd9Sstevel@tonic-gate 18327c478bd9Sstevel@tonic-gate kern_str[i] = 0; /* null terminate */ 18337c478bd9Sstevel@tonic-gate if (boot_str[i] != '\0') 18347c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 18357c478bd9Sstevel@tonic-gate "boot property string is truncated to %s", kern_str); 18367c478bd9Sstevel@tonic-gate } 18377c478bd9Sstevel@tonic-gate 18387c478bd9Sstevel@tonic-gate static void 18397c478bd9Sstevel@tonic-gate get_boot_properties(void) 18407c478bd9Sstevel@tonic-gate { 18417c478bd9Sstevel@tonic-gate extern char hw_provider[]; 18427c478bd9Sstevel@tonic-gate dev_info_t *devi; 18437c478bd9Sstevel@tonic-gate char *name; 18447c478bd9Sstevel@tonic-gate int length; 18457c478bd9Sstevel@tonic-gate char property_name[50], property_val[50]; 18467c478bd9Sstevel@tonic-gate void *bop_staging_area; 18477c478bd9Sstevel@tonic-gate 18487c478bd9Sstevel@tonic-gate bop_staging_area = kmem_zalloc(MMU_PAGESIZE, KM_NOSLEEP); 18497c478bd9Sstevel@tonic-gate 18507c478bd9Sstevel@tonic-gate /* 18517c478bd9Sstevel@tonic-gate * Import "root" properties from the boot. 18527c478bd9Sstevel@tonic-gate * 18537c478bd9Sstevel@tonic-gate * We do this by invoking BOP_NEXTPROP until the list 18547c478bd9Sstevel@tonic-gate * is completely copied in. 18557c478bd9Sstevel@tonic-gate */ 18567c478bd9Sstevel@tonic-gate 18577c478bd9Sstevel@tonic-gate devi = ddi_root_node(); 18587c478bd9Sstevel@tonic-gate for (name = BOP_NEXTPROP(bootops, ""); /* get first */ 18597c478bd9Sstevel@tonic-gate name; /* NULL => DONE */ 18607c478bd9Sstevel@tonic-gate name = BOP_NEXTPROP(bootops, name)) { /* get next */ 18617c478bd9Sstevel@tonic-gate 18627c478bd9Sstevel@tonic-gate /* copy string to memory above kernelbase */ 18637c478bd9Sstevel@tonic-gate copy_boot_str(name, property_name, 50); 18647c478bd9Sstevel@tonic-gate 18657c478bd9Sstevel@tonic-gate /* 18667c478bd9Sstevel@tonic-gate * Skip vga properties. They will be picked up later 18677c478bd9Sstevel@tonic-gate * by get_vga_properties. 18687c478bd9Sstevel@tonic-gate */ 18697c478bd9Sstevel@tonic-gate if (strcmp(property_name, "display-edif-block") == 0 || 18707c478bd9Sstevel@tonic-gate strcmp(property_name, "display-edif-id") == 0) { 18717c478bd9Sstevel@tonic-gate continue; 18727c478bd9Sstevel@tonic-gate } 18737c478bd9Sstevel@tonic-gate 18747c478bd9Sstevel@tonic-gate length = BOP_GETPROPLEN(bootops, property_name); 18757c478bd9Sstevel@tonic-gate if (length == 0) 18767c478bd9Sstevel@tonic-gate continue; 18777c478bd9Sstevel@tonic-gate if (length > MMU_PAGESIZE) { 18787c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, 18797c478bd9Sstevel@tonic-gate "boot property %s longer than 0x%x, ignored\n", 18807c478bd9Sstevel@tonic-gate property_name, MMU_PAGESIZE); 18817c478bd9Sstevel@tonic-gate continue; 18827c478bd9Sstevel@tonic-gate } 18837c478bd9Sstevel@tonic-gate BOP_GETPROP(bootops, property_name, bop_staging_area); 18847c478bd9Sstevel@tonic-gate 18857c478bd9Sstevel@tonic-gate /* 18867c478bd9Sstevel@tonic-gate * special properties: 18877c478bd9Sstevel@tonic-gate * si-machine, si-hw-provider 18887c478bd9Sstevel@tonic-gate * goes to kernel data structures. 18897c478bd9Sstevel@tonic-gate * bios-boot-device and stdout 18907c478bd9Sstevel@tonic-gate * goes to hardware property list so it may show up 18917c478bd9Sstevel@tonic-gate * in the prtconf -vp output. This is needed by 18927c478bd9Sstevel@tonic-gate * Install/Upgrade. Once we fix install upgrade, 18937c478bd9Sstevel@tonic-gate * this can be taken out. 18947c478bd9Sstevel@tonic-gate */ 18957c478bd9Sstevel@tonic-gate if (strcmp(name, "si-machine") == 0) { 18967c478bd9Sstevel@tonic-gate (void) strncpy(utsname.machine, bop_staging_area, 18977c478bd9Sstevel@tonic-gate SYS_NMLN); 18987c478bd9Sstevel@tonic-gate utsname.machine[SYS_NMLN - 1] = (char)NULL; 18997c478bd9Sstevel@tonic-gate } else if (strcmp(name, "si-hw-provider") == 0) { 19007c478bd9Sstevel@tonic-gate (void) strncpy(hw_provider, bop_staging_area, SYS_NMLN); 19017c478bd9Sstevel@tonic-gate hw_provider[SYS_NMLN - 1] = (char)NULL; 19027c478bd9Sstevel@tonic-gate } else if (strcmp(name, "bios-boot-device") == 0) { 19037c478bd9Sstevel@tonic-gate copy_boot_str(bop_staging_area, property_val, 50); 19047c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, devi, 19057c478bd9Sstevel@tonic-gate property_name, property_val); 1906*d2670fc4SToomas Soome } else if (strcmp(name, "acpi-root-tab") == 0) { 1907*d2670fc4SToomas Soome (void) ndi_prop_update_int64(DDI_DEV_T_NONE, devi, 1908*d2670fc4SToomas Soome property_name, *((int64_t *)bop_staging_area)); 19097c478bd9Sstevel@tonic-gate } else if (strcmp(name, "stdout") == 0) { 19107c478bd9Sstevel@tonic-gate (void) ndi_prop_update_int(DDI_DEV_T_NONE, devi, 19117c478bd9Sstevel@tonic-gate property_name, *((int *)bop_staging_area)); 19127c478bd9Sstevel@tonic-gate } else { 19137c478bd9Sstevel@tonic-gate /* Property type unknown, use old prop interface */ 19147c478bd9Sstevel@tonic-gate (void) e_ddi_prop_create(DDI_DEV_T_NONE, devi, 19157c478bd9Sstevel@tonic-gate DDI_PROP_CANSLEEP, property_name, bop_staging_area, 19167c478bd9Sstevel@tonic-gate length); 19177c478bd9Sstevel@tonic-gate } 19187c478bd9Sstevel@tonic-gate } 19197c478bd9Sstevel@tonic-gate 19207c478bd9Sstevel@tonic-gate kmem_free(bop_staging_area, MMU_PAGESIZE); 19217c478bd9Sstevel@tonic-gate } 19227c478bd9Sstevel@tonic-gate 19237c478bd9Sstevel@tonic-gate static void 19247c478bd9Sstevel@tonic-gate get_vga_properties(void) 19257c478bd9Sstevel@tonic-gate { 19267c478bd9Sstevel@tonic-gate dev_info_t *devi; 19277c478bd9Sstevel@tonic-gate major_t major; 19287c478bd9Sstevel@tonic-gate char *name; 19297c478bd9Sstevel@tonic-gate int length; 19307c478bd9Sstevel@tonic-gate char property_val[50]; 19317c478bd9Sstevel@tonic-gate void *bop_staging_area; 19327c478bd9Sstevel@tonic-gate 19332df1fe9cSrandyf /* 19342df1fe9cSrandyf * XXXX Hack Allert! 19352df1fe9cSrandyf * There really needs to be a better way for identifying various 19362df1fe9cSrandyf * console framebuffers and their related issues. Till then, 19372df1fe9cSrandyf * check for this one as a replacement to vgatext. 19382df1fe9cSrandyf */ 19392df1fe9cSrandyf major = ddi_name_to_major("ragexl"); 19402df1fe9cSrandyf if (major == (major_t)-1) { 19417c478bd9Sstevel@tonic-gate major = ddi_name_to_major("vgatext"); 19427c478bd9Sstevel@tonic-gate if (major == (major_t)-1) 19437c478bd9Sstevel@tonic-gate return; 19442df1fe9cSrandyf } 19457c478bd9Sstevel@tonic-gate devi = devnamesp[major].dn_head; 19467c478bd9Sstevel@tonic-gate if (devi == NULL) 19477c478bd9Sstevel@tonic-gate return; 19487c478bd9Sstevel@tonic-gate 19497c478bd9Sstevel@tonic-gate bop_staging_area = kmem_zalloc(MMU_PAGESIZE, KM_SLEEP); 19507c478bd9Sstevel@tonic-gate 19517c478bd9Sstevel@tonic-gate /* 19527c478bd9Sstevel@tonic-gate * Import "vga" properties from the boot. 19537c478bd9Sstevel@tonic-gate */ 19547c478bd9Sstevel@tonic-gate name = "display-edif-block"; 19557c478bd9Sstevel@tonic-gate length = BOP_GETPROPLEN(bootops, name); 19567c478bd9Sstevel@tonic-gate if (length > 0 && length < MMU_PAGESIZE) { 19577c478bd9Sstevel@tonic-gate BOP_GETPROP(bootops, name, bop_staging_area); 19587c478bd9Sstevel@tonic-gate (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE, 19597c478bd9Sstevel@tonic-gate devi, name, bop_staging_area, length); 19607c478bd9Sstevel@tonic-gate } 19617c478bd9Sstevel@tonic-gate 19627c478bd9Sstevel@tonic-gate /* 19637c478bd9Sstevel@tonic-gate * kdmconfig is also looking for display-type and 19647c478bd9Sstevel@tonic-gate * video-adapter-type. We default to color and svga. 19657c478bd9Sstevel@tonic-gate * 19667c478bd9Sstevel@tonic-gate * Could it be "monochrome", "vga"? 19677c478bd9Sstevel@tonic-gate * Nah, you've got to come to the 21st century... 19687c478bd9Sstevel@tonic-gate * And you can set monitor type manually in kdmconfig 19697c478bd9Sstevel@tonic-gate * if you are really an old junky. 19707c478bd9Sstevel@tonic-gate */ 19717c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 19727c478bd9Sstevel@tonic-gate devi, "display-type", "color"); 19737c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 19747c478bd9Sstevel@tonic-gate devi, "video-adapter-type", "svga"); 19757c478bd9Sstevel@tonic-gate 19767c478bd9Sstevel@tonic-gate name = "display-edif-id"; 19777c478bd9Sstevel@tonic-gate length = BOP_GETPROPLEN(bootops, name); 19787c478bd9Sstevel@tonic-gate if (length > 0 && length < MMU_PAGESIZE) { 19797c478bd9Sstevel@tonic-gate BOP_GETPROP(bootops, name, bop_staging_area); 19807c478bd9Sstevel@tonic-gate copy_boot_str(bop_staging_area, property_val, length); 19817c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 19827c478bd9Sstevel@tonic-gate devi, name, property_val); 19837c478bd9Sstevel@tonic-gate } 19847c478bd9Sstevel@tonic-gate 19857c478bd9Sstevel@tonic-gate kmem_free(bop_staging_area, MMU_PAGESIZE); 19867c478bd9Sstevel@tonic-gate } 19877c478bd9Sstevel@tonic-gate 19887c478bd9Sstevel@tonic-gate 19897c478bd9Sstevel@tonic-gate /* 19907c478bd9Sstevel@tonic-gate * This is temporary, but absolutely necessary. If we are being 19917c478bd9Sstevel@tonic-gate * booted with a device tree created by the DevConf project's bootconf 19927c478bd9Sstevel@tonic-gate * program, then we have device information nodes that reflect 19937c478bd9Sstevel@tonic-gate * reality. At this point in time in the Solaris release schedule, the 19947c478bd9Sstevel@tonic-gate * kernel drivers aren't prepared for reality. They still depend on their 19957c478bd9Sstevel@tonic-gate * own ad-hoc interpretations of the properties created when their .conf 19967c478bd9Sstevel@tonic-gate * files were interpreted. These drivers use an "ignore-hardware-nodes" 19977c478bd9Sstevel@tonic-gate * property to prevent them from using the nodes passed up from the bootconf 19987c478bd9Sstevel@tonic-gate * device tree. 19997c478bd9Sstevel@tonic-gate * 20007c478bd9Sstevel@tonic-gate * Trying to assemble root file system drivers as we are booting from 20017c478bd9Sstevel@tonic-gate * devconf will fail if the kernel driver is basing its name_addr's on the 20027c478bd9Sstevel@tonic-gate * psuedo-node device info while the bootpath passed up from bootconf is using 20037c478bd9Sstevel@tonic-gate * reality-based name_addrs. We help the boot along in this case by 20047c478bd9Sstevel@tonic-gate * looking at the pre-bootconf bootpath and determining if we would have 20057c478bd9Sstevel@tonic-gate * successfully matched if that had been the bootpath we had chosen. 20067c478bd9Sstevel@tonic-gate * 20077c478bd9Sstevel@tonic-gate * Note that we only even perform this extra check if we've booted 20087c478bd9Sstevel@tonic-gate * using bootconf's 1275 compliant bootpath, this is the boot device, and 20097c478bd9Sstevel@tonic-gate * we're trying to match the name_addr specified in the 1275 bootpath. 20107c478bd9Sstevel@tonic-gate */ 20117c478bd9Sstevel@tonic-gate 20127c478bd9Sstevel@tonic-gate #define MAXCOMPONENTLEN 32 20137c478bd9Sstevel@tonic-gate 20147c478bd9Sstevel@tonic-gate int 20157c478bd9Sstevel@tonic-gate x86_old_bootpath_name_addr_match(dev_info_t *cdip, char *caddr, char *naddr) 20167c478bd9Sstevel@tonic-gate { 20177c478bd9Sstevel@tonic-gate /* 20187c478bd9Sstevel@tonic-gate * There are multiple criteria to be met before we can even 20197c478bd9Sstevel@tonic-gate * consider allowing a name_addr match here. 20207c478bd9Sstevel@tonic-gate * 20217c478bd9Sstevel@tonic-gate * 1) We must have been booted such that the bootconf program 20227c478bd9Sstevel@tonic-gate * created device tree nodes and properties. This can be 20237c478bd9Sstevel@tonic-gate * determined by examining the 'bootpath' property. This 20247c478bd9Sstevel@tonic-gate * property will be a non-null string iff bootconf was 20257c478bd9Sstevel@tonic-gate * involved in the boot. 20267c478bd9Sstevel@tonic-gate * 20277c478bd9Sstevel@tonic-gate * 2) The module that we want to match must be the boot device. 20287c478bd9Sstevel@tonic-gate * 20297c478bd9Sstevel@tonic-gate * 3) The instance of the module we are thinking of letting be 20307c478bd9Sstevel@tonic-gate * our match must be ignoring hardware nodes. 20317c478bd9Sstevel@tonic-gate * 20327c478bd9Sstevel@tonic-gate * 4) The name_addr we want to match must be the name_addr 20337c478bd9Sstevel@tonic-gate * specified in the 1275 bootpath. 20347c478bd9Sstevel@tonic-gate */ 20357c478bd9Sstevel@tonic-gate static char bootdev_module[MAXCOMPONENTLEN]; 20367c478bd9Sstevel@tonic-gate static char bootdev_oldmod[MAXCOMPONENTLEN]; 20377c478bd9Sstevel@tonic-gate static char bootdev_newaddr[MAXCOMPONENTLEN]; 20387c478bd9Sstevel@tonic-gate static char bootdev_oldaddr[MAXCOMPONENTLEN]; 20397c478bd9Sstevel@tonic-gate static int quickexit; 20407c478bd9Sstevel@tonic-gate 20417c478bd9Sstevel@tonic-gate char *daddr; 20427c478bd9Sstevel@tonic-gate int dlen; 20437c478bd9Sstevel@tonic-gate 20447c478bd9Sstevel@tonic-gate char *lkupname; 20457c478bd9Sstevel@tonic-gate int rv = DDI_FAILURE; 20467c478bd9Sstevel@tonic-gate 20477c478bd9Sstevel@tonic-gate if ((ddi_getlongprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 20487c478bd9Sstevel@tonic-gate "devconf-addr", (caddr_t)&daddr, &dlen) == DDI_PROP_SUCCESS) && 20497c478bd9Sstevel@tonic-gate (ddi_getprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 20507c478bd9Sstevel@tonic-gate "ignore-hardware-nodes", -1) != -1)) { 20517c478bd9Sstevel@tonic-gate if (strcmp(daddr, caddr) == 0) { 20527c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 20537c478bd9Sstevel@tonic-gate } 20547c478bd9Sstevel@tonic-gate } 20557c478bd9Sstevel@tonic-gate 20567c478bd9Sstevel@tonic-gate if (quickexit) 20577c478bd9Sstevel@tonic-gate return (rv); 20587c478bd9Sstevel@tonic-gate 20597c478bd9Sstevel@tonic-gate if (bootdev_module[0] == '\0') { 20607c478bd9Sstevel@tonic-gate char *addrp, *eoaddrp; 20617c478bd9Sstevel@tonic-gate char *busp, *modp, *atp; 20627c478bd9Sstevel@tonic-gate char *bp1275, *bp; 20637c478bd9Sstevel@tonic-gate int bp1275len, bplen; 20647c478bd9Sstevel@tonic-gate 20657c478bd9Sstevel@tonic-gate bp1275 = bp = addrp = eoaddrp = busp = modp = atp = NULL; 20667c478bd9Sstevel@tonic-gate 20677c478bd9Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, 20687c478bd9Sstevel@tonic-gate ddi_root_node(), 0, "bootpath", 20697c478bd9Sstevel@tonic-gate (caddr_t)&bp1275, &bp1275len) != DDI_PROP_SUCCESS || 20707c478bd9Sstevel@tonic-gate bp1275len <= 1) { 20717c478bd9Sstevel@tonic-gate /* 20727c478bd9Sstevel@tonic-gate * We didn't boot from bootconf so we never need to 20737c478bd9Sstevel@tonic-gate * do any special matches. 20747c478bd9Sstevel@tonic-gate */ 20757c478bd9Sstevel@tonic-gate quickexit = 1; 20767c478bd9Sstevel@tonic-gate if (bp1275) 20777c478bd9Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 20787c478bd9Sstevel@tonic-gate return (rv); 20797c478bd9Sstevel@tonic-gate } 20807c478bd9Sstevel@tonic-gate 20817c478bd9Sstevel@tonic-gate if (ddi_getlongprop(DDI_DEV_T_ANY, 20827c478bd9Sstevel@tonic-gate ddi_root_node(), 0, "boot-path", 20837c478bd9Sstevel@tonic-gate (caddr_t)&bp, &bplen) != DDI_PROP_SUCCESS || bplen <= 1) { 20847c478bd9Sstevel@tonic-gate /* 20857c478bd9Sstevel@tonic-gate * No fallback position for matching. This is 20867c478bd9Sstevel@tonic-gate * certainly unexpected, but we'll handle it 20877c478bd9Sstevel@tonic-gate * just in case. 20887c478bd9Sstevel@tonic-gate */ 20897c478bd9Sstevel@tonic-gate quickexit = 1; 20907c478bd9Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 20917c478bd9Sstevel@tonic-gate if (bp) 20927c478bd9Sstevel@tonic-gate kmem_free(bp, bplen); 20937c478bd9Sstevel@tonic-gate return (rv); 20947c478bd9Sstevel@tonic-gate } 20957c478bd9Sstevel@tonic-gate 20967c478bd9Sstevel@tonic-gate /* 20977c478bd9Sstevel@tonic-gate * Determine boot device module and 1275 name_addr 20987c478bd9Sstevel@tonic-gate * 20997c478bd9Sstevel@tonic-gate * bootpath assumed to be of the form /bus/module@name_addr 21007c478bd9Sstevel@tonic-gate */ 21017c478bd9Sstevel@tonic-gate if (busp = strchr(bp1275, '/')) { 21027c478bd9Sstevel@tonic-gate if (modp = strchr(busp + 1, '/')) { 21037c478bd9Sstevel@tonic-gate if (atp = strchr(modp + 1, '@')) { 21047c478bd9Sstevel@tonic-gate *atp = '\0'; 21057c478bd9Sstevel@tonic-gate addrp = atp + 1; 21067c478bd9Sstevel@tonic-gate if (eoaddrp = strchr(addrp, '/')) 21077c478bd9Sstevel@tonic-gate *eoaddrp = '\0'; 21087c478bd9Sstevel@tonic-gate } 21097c478bd9Sstevel@tonic-gate } 21107c478bd9Sstevel@tonic-gate } 21117c478bd9Sstevel@tonic-gate 21127c478bd9Sstevel@tonic-gate if (modp && addrp) { 21137c478bd9Sstevel@tonic-gate (void) strncpy(bootdev_module, modp + 1, 21147c478bd9Sstevel@tonic-gate MAXCOMPONENTLEN); 21157c478bd9Sstevel@tonic-gate bootdev_module[MAXCOMPONENTLEN - 1] = '\0'; 21167c478bd9Sstevel@tonic-gate 21177c478bd9Sstevel@tonic-gate (void) strncpy(bootdev_newaddr, addrp, MAXCOMPONENTLEN); 21187c478bd9Sstevel@tonic-gate bootdev_newaddr[MAXCOMPONENTLEN - 1] = '\0'; 21197c478bd9Sstevel@tonic-gate } else { 21207c478bd9Sstevel@tonic-gate quickexit = 1; 21217c478bd9Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 21227c478bd9Sstevel@tonic-gate kmem_free(bp, bplen); 21237c478bd9Sstevel@tonic-gate return (rv); 21247c478bd9Sstevel@tonic-gate } 21257c478bd9Sstevel@tonic-gate 21267c478bd9Sstevel@tonic-gate /* 21277c478bd9Sstevel@tonic-gate * Determine fallback name_addr 21287c478bd9Sstevel@tonic-gate * 21297c478bd9Sstevel@tonic-gate * 10/3/96 - Also save fallback module name because it 21307c478bd9Sstevel@tonic-gate * might actually be different than the current module 21317c478bd9Sstevel@tonic-gate * name. E.G., ISA pnp drivers have new names. 21327c478bd9Sstevel@tonic-gate * 21337c478bd9Sstevel@tonic-gate * bootpath assumed to be of the form /bus/module@name_addr 21347c478bd9Sstevel@tonic-gate */ 21357c478bd9Sstevel@tonic-gate addrp = NULL; 21367c478bd9Sstevel@tonic-gate if (busp = strchr(bp, '/')) { 21377c478bd9Sstevel@tonic-gate if (modp = strchr(busp + 1, '/')) { 21387c478bd9Sstevel@tonic-gate if (atp = strchr(modp + 1, '@')) { 21397c478bd9Sstevel@tonic-gate *atp = '\0'; 21407c478bd9Sstevel@tonic-gate addrp = atp + 1; 21417c478bd9Sstevel@tonic-gate if (eoaddrp = strchr(addrp, '/')) 21427c478bd9Sstevel@tonic-gate *eoaddrp = '\0'; 21437c478bd9Sstevel@tonic-gate } 21447c478bd9Sstevel@tonic-gate } 21457c478bd9Sstevel@tonic-gate } 21467c478bd9Sstevel@tonic-gate 21477c478bd9Sstevel@tonic-gate if (modp && addrp) { 21487c478bd9Sstevel@tonic-gate (void) strncpy(bootdev_oldmod, modp + 1, 21497c478bd9Sstevel@tonic-gate MAXCOMPONENTLEN); 21507c478bd9Sstevel@tonic-gate bootdev_module[MAXCOMPONENTLEN - 1] = '\0'; 21517c478bd9Sstevel@tonic-gate 21527c478bd9Sstevel@tonic-gate (void) strncpy(bootdev_oldaddr, addrp, MAXCOMPONENTLEN); 21537c478bd9Sstevel@tonic-gate bootdev_oldaddr[MAXCOMPONENTLEN - 1] = '\0'; 21547c478bd9Sstevel@tonic-gate } 21557c478bd9Sstevel@tonic-gate 21567c478bd9Sstevel@tonic-gate /* Free up the bootpath storage now that we're done with it. */ 21577c478bd9Sstevel@tonic-gate kmem_free(bp1275, bp1275len); 21587c478bd9Sstevel@tonic-gate kmem_free(bp, bplen); 21597c478bd9Sstevel@tonic-gate 21607c478bd9Sstevel@tonic-gate if (bootdev_oldaddr[0] == '\0') { 21617c478bd9Sstevel@tonic-gate quickexit = 1; 21627c478bd9Sstevel@tonic-gate return (rv); 21637c478bd9Sstevel@tonic-gate } 21647c478bd9Sstevel@tonic-gate } 21657c478bd9Sstevel@tonic-gate 21667c478bd9Sstevel@tonic-gate if (((lkupname = ddi_get_name(cdip)) != NULL) && 21677c478bd9Sstevel@tonic-gate (strcmp(bootdev_module, lkupname) == 0 || 21687c478bd9Sstevel@tonic-gate strcmp(bootdev_oldmod, lkupname) == 0) && 21697c478bd9Sstevel@tonic-gate ((ddi_getprop(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 21707c478bd9Sstevel@tonic-gate "ignore-hardware-nodes", -1) != -1) || 21717c478bd9Sstevel@tonic-gate ignore_hardware_nodes) && 21727c478bd9Sstevel@tonic-gate strcmp(bootdev_newaddr, caddr) == 0 && 21737c478bd9Sstevel@tonic-gate strcmp(bootdev_oldaddr, naddr) == 0) { 21747c478bd9Sstevel@tonic-gate rv = DDI_SUCCESS; 21757c478bd9Sstevel@tonic-gate } 21767c478bd9Sstevel@tonic-gate 21777c478bd9Sstevel@tonic-gate return (rv); 21787c478bd9Sstevel@tonic-gate } 21797c478bd9Sstevel@tonic-gate 21807c478bd9Sstevel@tonic-gate /* 21817c478bd9Sstevel@tonic-gate * Perform a copy from a memory mapped device (whose devinfo pointer is devi) 21827c478bd9Sstevel@tonic-gate * separately mapped at devaddr in the kernel to a kernel buffer at kaddr. 21837c478bd9Sstevel@tonic-gate */ 21847c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 21857c478bd9Sstevel@tonic-gate int 21867c478bd9Sstevel@tonic-gate e_ddi_copyfromdev(dev_info_t *devi, 21877c478bd9Sstevel@tonic-gate off_t off, const void *devaddr, void *kaddr, size_t len) 21887c478bd9Sstevel@tonic-gate { 21897c478bd9Sstevel@tonic-gate bcopy(devaddr, kaddr, len); 21907c478bd9Sstevel@tonic-gate return (0); 21917c478bd9Sstevel@tonic-gate } 21927c478bd9Sstevel@tonic-gate 21937c478bd9Sstevel@tonic-gate /* 21947c478bd9Sstevel@tonic-gate * Perform a copy to a memory mapped device (whose devinfo pointer is devi) 21957c478bd9Sstevel@tonic-gate * separately mapped at devaddr in the kernel from a kernel buffer at kaddr. 21967c478bd9Sstevel@tonic-gate */ 21977c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 21987c478bd9Sstevel@tonic-gate int 21997c478bd9Sstevel@tonic-gate e_ddi_copytodev(dev_info_t *devi, 22007c478bd9Sstevel@tonic-gate off_t off, const void *kaddr, void *devaddr, size_t len) 22017c478bd9Sstevel@tonic-gate { 22027c478bd9Sstevel@tonic-gate bcopy(kaddr, devaddr, len); 22037c478bd9Sstevel@tonic-gate return (0); 22047c478bd9Sstevel@tonic-gate } 22057c478bd9Sstevel@tonic-gate 22067c478bd9Sstevel@tonic-gate 22077c478bd9Sstevel@tonic-gate static int 22087c478bd9Sstevel@tonic-gate poke_mem(peekpoke_ctlops_t *in_args) 22097c478bd9Sstevel@tonic-gate { 22107c478bd9Sstevel@tonic-gate int err = DDI_SUCCESS; 22117c478bd9Sstevel@tonic-gate on_trap_data_t otd; 22127c478bd9Sstevel@tonic-gate 22137c478bd9Sstevel@tonic-gate /* Set up protected environment. */ 22147c478bd9Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 22157c478bd9Sstevel@tonic-gate switch (in_args->size) { 22167c478bd9Sstevel@tonic-gate case sizeof (uint8_t): 22177c478bd9Sstevel@tonic-gate *(uint8_t *)(in_args->dev_addr) = 22187c478bd9Sstevel@tonic-gate *(uint8_t *)in_args->host_addr; 22197c478bd9Sstevel@tonic-gate break; 22207c478bd9Sstevel@tonic-gate 22217c478bd9Sstevel@tonic-gate case sizeof (uint16_t): 22227c478bd9Sstevel@tonic-gate *(uint16_t *)(in_args->dev_addr) = 22237c478bd9Sstevel@tonic-gate *(uint16_t *)in_args->host_addr; 22247c478bd9Sstevel@tonic-gate break; 22257c478bd9Sstevel@tonic-gate 22267c478bd9Sstevel@tonic-gate case sizeof (uint32_t): 22277c478bd9Sstevel@tonic-gate *(uint32_t *)(in_args->dev_addr) = 22287c478bd9Sstevel@tonic-gate *(uint32_t *)in_args->host_addr; 22297c478bd9Sstevel@tonic-gate break; 22307c478bd9Sstevel@tonic-gate 22317c478bd9Sstevel@tonic-gate case sizeof (uint64_t): 22327c478bd9Sstevel@tonic-gate *(uint64_t *)(in_args->dev_addr) = 22337c478bd9Sstevel@tonic-gate *(uint64_t *)in_args->host_addr; 22347c478bd9Sstevel@tonic-gate break; 22357c478bd9Sstevel@tonic-gate 22367c478bd9Sstevel@tonic-gate default: 22377c478bd9Sstevel@tonic-gate err = DDI_FAILURE; 22387c478bd9Sstevel@tonic-gate break; 22397c478bd9Sstevel@tonic-gate } 22407c478bd9Sstevel@tonic-gate } else 22417c478bd9Sstevel@tonic-gate err = DDI_FAILURE; 22427c478bd9Sstevel@tonic-gate 22437c478bd9Sstevel@tonic-gate /* Take down protected environment. */ 22447c478bd9Sstevel@tonic-gate no_trap(); 22457c478bd9Sstevel@tonic-gate 22467c478bd9Sstevel@tonic-gate return (err); 22477c478bd9Sstevel@tonic-gate } 22487c478bd9Sstevel@tonic-gate 22497c478bd9Sstevel@tonic-gate 22507c478bd9Sstevel@tonic-gate static int 22517c478bd9Sstevel@tonic-gate peek_mem(peekpoke_ctlops_t *in_args) 22527c478bd9Sstevel@tonic-gate { 22537c478bd9Sstevel@tonic-gate int err = DDI_SUCCESS; 22547c478bd9Sstevel@tonic-gate on_trap_data_t otd; 22557c478bd9Sstevel@tonic-gate 22567c478bd9Sstevel@tonic-gate if (!on_trap(&otd, OT_DATA_ACCESS)) { 22577c478bd9Sstevel@tonic-gate switch (in_args->size) { 22587c478bd9Sstevel@tonic-gate case sizeof (uint8_t): 22597c478bd9Sstevel@tonic-gate *(uint8_t *)in_args->host_addr = 22607c478bd9Sstevel@tonic-gate *(uint8_t *)in_args->dev_addr; 22617c478bd9Sstevel@tonic-gate break; 22627c478bd9Sstevel@tonic-gate 22637c478bd9Sstevel@tonic-gate case sizeof (uint16_t): 22647c478bd9Sstevel@tonic-gate *(uint16_t *)in_args->host_addr = 22657c478bd9Sstevel@tonic-gate *(uint16_t *)in_args->dev_addr; 22667c478bd9Sstevel@tonic-gate break; 22677c478bd9Sstevel@tonic-gate 22687c478bd9Sstevel@tonic-gate case sizeof (uint32_t): 22697c478bd9Sstevel@tonic-gate *(uint32_t *)in_args->host_addr = 22707c478bd9Sstevel@tonic-gate *(uint32_t *)in_args->dev_addr; 22717c478bd9Sstevel@tonic-gate break; 22727c478bd9Sstevel@tonic-gate 22737c478bd9Sstevel@tonic-gate case sizeof (uint64_t): 22747c478bd9Sstevel@tonic-gate *(uint64_t *)in_args->host_addr = 22757c478bd9Sstevel@tonic-gate *(uint64_t *)in_args->dev_addr; 22767c478bd9Sstevel@tonic-gate break; 22777c478bd9Sstevel@tonic-gate 22787c478bd9Sstevel@tonic-gate default: 22797c478bd9Sstevel@tonic-gate err = DDI_FAILURE; 22807c478bd9Sstevel@tonic-gate break; 22817c478bd9Sstevel@tonic-gate } 22827c478bd9Sstevel@tonic-gate } else 22837c478bd9Sstevel@tonic-gate err = DDI_FAILURE; 22847c478bd9Sstevel@tonic-gate 22857c478bd9Sstevel@tonic-gate no_trap(); 22867c478bd9Sstevel@tonic-gate return (err); 22877c478bd9Sstevel@tonic-gate } 22887c478bd9Sstevel@tonic-gate 22897c478bd9Sstevel@tonic-gate 22907c478bd9Sstevel@tonic-gate /* 22917c478bd9Sstevel@tonic-gate * This is called only to process peek/poke when the DIP is NULL. 22927c478bd9Sstevel@tonic-gate * Assume that this is for memory, as nexi take care of device safe accesses. 22937c478bd9Sstevel@tonic-gate */ 22947c478bd9Sstevel@tonic-gate int 22957c478bd9Sstevel@tonic-gate peekpoke_mem(ddi_ctl_enum_t cmd, peekpoke_ctlops_t *in_args) 22967c478bd9Sstevel@tonic-gate { 22977c478bd9Sstevel@tonic-gate return (cmd == DDI_CTLOPS_PEEK ? peek_mem(in_args) : poke_mem(in_args)); 22987c478bd9Sstevel@tonic-gate } 22997c478bd9Sstevel@tonic-gate 230000d0963fSdilpreet /* 230100d0963fSdilpreet * we've just done a cautious put/get. Check if it was successful by 230200d0963fSdilpreet * calling pci_ereport_post() on all puts and for any gets that return -1 230300d0963fSdilpreet */ 230400d0963fSdilpreet static int 2305eae2e508Skrishnae pci_peekpoke_check_fma(dev_info_t *dip, void *arg, ddi_ctl_enum_t ctlop, 2306eae2e508Skrishnae void (*scan)(dev_info_t *, ddi_fm_error_t *)) 230700d0963fSdilpreet { 230800d0963fSdilpreet int rval = DDI_SUCCESS; 230900d0963fSdilpreet peekpoke_ctlops_t *in_args = (peekpoke_ctlops_t *)arg; 231000d0963fSdilpreet ddi_fm_error_t de; 231100d0963fSdilpreet ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 231200d0963fSdilpreet ddi_acc_hdl_t *hdlp = (ddi_acc_hdl_t *)in_args->handle; 231300d0963fSdilpreet int check_err = 0; 231400d0963fSdilpreet int repcount = in_args->repcount; 231500d0963fSdilpreet 23167f58d724Sdilpreet if (ctlop == DDI_CTLOPS_POKE && 23177f58d724Sdilpreet hdlp->ah_acc.devacc_attr_access != DDI_CAUTIOUS_ACC) 23187f58d724Sdilpreet return (DDI_SUCCESS); 23197f58d724Sdilpreet 232000d0963fSdilpreet if (ctlop == DDI_CTLOPS_PEEK && 232100d0963fSdilpreet hdlp->ah_acc.devacc_attr_access != DDI_CAUTIOUS_ACC) { 232200d0963fSdilpreet for (; repcount; repcount--) { 232300d0963fSdilpreet switch (in_args->size) { 232400d0963fSdilpreet case sizeof (uint8_t): 232500d0963fSdilpreet if (*(uint8_t *)in_args->host_addr == 0xff) 232600d0963fSdilpreet check_err = 1; 232700d0963fSdilpreet break; 232800d0963fSdilpreet case sizeof (uint16_t): 232900d0963fSdilpreet if (*(uint16_t *)in_args->host_addr == 0xffff) 233000d0963fSdilpreet check_err = 1; 233100d0963fSdilpreet break; 233200d0963fSdilpreet case sizeof (uint32_t): 233300d0963fSdilpreet if (*(uint32_t *)in_args->host_addr == 233400d0963fSdilpreet 0xffffffff) 233500d0963fSdilpreet check_err = 1; 233600d0963fSdilpreet break; 233700d0963fSdilpreet case sizeof (uint64_t): 233800d0963fSdilpreet if (*(uint64_t *)in_args->host_addr == 233900d0963fSdilpreet 0xffffffffffffffff) 234000d0963fSdilpreet check_err = 1; 234100d0963fSdilpreet break; 234200d0963fSdilpreet } 234300d0963fSdilpreet } 234400d0963fSdilpreet if (check_err == 0) 234500d0963fSdilpreet return (DDI_SUCCESS); 234600d0963fSdilpreet } 234700d0963fSdilpreet /* 234800d0963fSdilpreet * for a cautious put or get or a non-cautious get that returned -1 call 234900d0963fSdilpreet * io framework to see if there really was an error 235000d0963fSdilpreet */ 235100d0963fSdilpreet bzero(&de, sizeof (ddi_fm_error_t)); 23528aec9182Sstephh de.fme_version = DDI_FME_VERSION; 235300d0963fSdilpreet de.fme_ena = fm_ena_generate(0, FM_ENA_FMT1); 235400d0963fSdilpreet if (hdlp->ah_acc.devacc_attr_access == DDI_CAUTIOUS_ACC) { 235500d0963fSdilpreet de.fme_flag = DDI_FM_ERR_EXPECTED; 235600d0963fSdilpreet de.fme_acc_handle = in_args->handle; 235700d0963fSdilpreet } else if (hdlp->ah_acc.devacc_attr_access == DDI_DEFAULT_ACC) { 235800d0963fSdilpreet /* 235900d0963fSdilpreet * We only get here with DDI_DEFAULT_ACC for config space gets. 236000d0963fSdilpreet * Non-hardened drivers may be probing the hardware and 236100d0963fSdilpreet * expecting -1 returned. So need to treat errors on 236200d0963fSdilpreet * DDI_DEFAULT_ACC as DDI_FM_ERR_EXPECTED. 236300d0963fSdilpreet */ 236400d0963fSdilpreet de.fme_flag = DDI_FM_ERR_EXPECTED; 236500d0963fSdilpreet de.fme_acc_handle = in_args->handle; 236600d0963fSdilpreet } else { 236700d0963fSdilpreet /* 236800d0963fSdilpreet * Hardened driver doing protected accesses shouldn't 236900d0963fSdilpreet * get errors unless there's a hardware problem. Treat 237000d0963fSdilpreet * as nonfatal if there's an error, but set UNEXPECTED 237100d0963fSdilpreet * so we raise ereports on any errors and potentially 237200d0963fSdilpreet * fault the device 237300d0963fSdilpreet */ 237400d0963fSdilpreet de.fme_flag = DDI_FM_ERR_UNEXPECTED; 237500d0963fSdilpreet } 2376eae2e508Skrishnae (void) scan(dip, &de); 237700d0963fSdilpreet if (hdlp->ah_acc.devacc_attr_access != DDI_DEFAULT_ACC && 237800d0963fSdilpreet de.fme_status != DDI_FM_OK) { 237900d0963fSdilpreet ndi_err_t *errp = (ndi_err_t *)hp->ahi_err; 238000d0963fSdilpreet rval = DDI_FAILURE; 238100d0963fSdilpreet errp->err_ena = de.fme_ena; 238200d0963fSdilpreet errp->err_expected = de.fme_flag; 238300d0963fSdilpreet errp->err_status = DDI_FM_NONFATAL; 238400d0963fSdilpreet } 238500d0963fSdilpreet return (rval); 238600d0963fSdilpreet } 238700d0963fSdilpreet 238800d0963fSdilpreet /* 238900d0963fSdilpreet * pci_peekpoke_check_nofma() is for when an error occurs on a register access 239000d0963fSdilpreet * during pci_ereport_post(). We can't call pci_ereport_post() again or we'd 239100d0963fSdilpreet * recurse, so assume all puts are OK and gets have failed if they return -1 239200d0963fSdilpreet */ 239300d0963fSdilpreet static int 239400d0963fSdilpreet pci_peekpoke_check_nofma(void *arg, ddi_ctl_enum_t ctlop) 239500d0963fSdilpreet { 239600d0963fSdilpreet int rval = DDI_SUCCESS; 239700d0963fSdilpreet peekpoke_ctlops_t *in_args = (peekpoke_ctlops_t *)arg; 239800d0963fSdilpreet ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 239900d0963fSdilpreet ddi_acc_hdl_t *hdlp = (ddi_acc_hdl_t *)in_args->handle; 240000d0963fSdilpreet int repcount = in_args->repcount; 240100d0963fSdilpreet 240200d0963fSdilpreet if (ctlop == DDI_CTLOPS_POKE) 240300d0963fSdilpreet return (rval); 240400d0963fSdilpreet 240500d0963fSdilpreet for (; repcount; repcount--) { 240600d0963fSdilpreet switch (in_args->size) { 240700d0963fSdilpreet case sizeof (uint8_t): 240800d0963fSdilpreet if (*(uint8_t *)in_args->host_addr == 0xff) 240900d0963fSdilpreet rval = DDI_FAILURE; 241000d0963fSdilpreet break; 241100d0963fSdilpreet case sizeof (uint16_t): 241200d0963fSdilpreet if (*(uint16_t *)in_args->host_addr == 0xffff) 241300d0963fSdilpreet rval = DDI_FAILURE; 241400d0963fSdilpreet break; 241500d0963fSdilpreet case sizeof (uint32_t): 241600d0963fSdilpreet if (*(uint32_t *)in_args->host_addr == 0xffffffff) 241700d0963fSdilpreet rval = DDI_FAILURE; 241800d0963fSdilpreet break; 241900d0963fSdilpreet case sizeof (uint64_t): 242000d0963fSdilpreet if (*(uint64_t *)in_args->host_addr == 242100d0963fSdilpreet 0xffffffffffffffff) 242200d0963fSdilpreet rval = DDI_FAILURE; 242300d0963fSdilpreet break; 242400d0963fSdilpreet } 242500d0963fSdilpreet } 242600d0963fSdilpreet if (hdlp->ah_acc.devacc_attr_access != DDI_DEFAULT_ACC && 242700d0963fSdilpreet rval == DDI_FAILURE) { 242800d0963fSdilpreet ndi_err_t *errp = (ndi_err_t *)hp->ahi_err; 242900d0963fSdilpreet errp->err_ena = fm_ena_generate(0, FM_ENA_FMT1); 243000d0963fSdilpreet errp->err_expected = DDI_FM_ERR_UNEXPECTED; 243100d0963fSdilpreet errp->err_status = DDI_FM_NONFATAL; 243200d0963fSdilpreet } 243300d0963fSdilpreet return (rval); 243400d0963fSdilpreet } 243500d0963fSdilpreet 243600d0963fSdilpreet int 243700d0963fSdilpreet pci_peekpoke_check(dev_info_t *dip, dev_info_t *rdip, 243800d0963fSdilpreet ddi_ctl_enum_t ctlop, void *arg, void *result, 243900d0963fSdilpreet int (*handler)(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, 2440eae2e508Skrishnae void *), kmutex_t *err_mutexp, kmutex_t *peek_poke_mutexp, 2441eae2e508Skrishnae void (*scan)(dev_info_t *, ddi_fm_error_t *)) 244200d0963fSdilpreet { 244300d0963fSdilpreet int rval; 244400d0963fSdilpreet peekpoke_ctlops_t *in_args = (peekpoke_ctlops_t *)arg; 244500d0963fSdilpreet ddi_acc_impl_t *hp = (ddi_acc_impl_t *)in_args->handle; 244600d0963fSdilpreet 24478aec9182Sstephh /* 24488aec9182Sstephh * this function only supports cautious accesses, not peeks/pokes 24498aec9182Sstephh * which don't have a handle 24508aec9182Sstephh */ 24518aec9182Sstephh if (hp == NULL) 24528aec9182Sstephh return (DDI_FAILURE); 24538aec9182Sstephh 245400d0963fSdilpreet if (hp->ahi_acc_attr & DDI_ACCATTR_CONFIG_SPACE) { 245500d0963fSdilpreet if (!mutex_tryenter(err_mutexp)) { 245600d0963fSdilpreet /* 245700d0963fSdilpreet * As this may be a recursive call from within 245800d0963fSdilpreet * pci_ereport_post() we can't wait for the mutexes. 245900d0963fSdilpreet * Fortunately we know someone is already calling 246000d0963fSdilpreet * pci_ereport_post() which will handle the error bits 246100d0963fSdilpreet * for us, and as this is a config space access we can 246200d0963fSdilpreet * just do the access and check return value for -1 246300d0963fSdilpreet * using pci_peekpoke_check_nofma(). 246400d0963fSdilpreet */ 246500d0963fSdilpreet rval = handler(dip, rdip, ctlop, arg, result); 246600d0963fSdilpreet if (rval == DDI_SUCCESS) 246700d0963fSdilpreet rval = pci_peekpoke_check_nofma(arg, ctlop); 246800d0963fSdilpreet return (rval); 246900d0963fSdilpreet } 247000d0963fSdilpreet /* 247100d0963fSdilpreet * This can't be a recursive call. Drop the err_mutex and get 247200d0963fSdilpreet * both mutexes in the right order. If an error hasn't already 247300d0963fSdilpreet * been detected by the ontrap code, use pci_peekpoke_check_fma 247400d0963fSdilpreet * which will call pci_ereport_post() to check error status. 247500d0963fSdilpreet */ 247600d0963fSdilpreet mutex_exit(err_mutexp); 247700d0963fSdilpreet } 247800d0963fSdilpreet mutex_enter(peek_poke_mutexp); 247900d0963fSdilpreet rval = handler(dip, rdip, ctlop, arg, result); 248000d0963fSdilpreet if (rval == DDI_SUCCESS) { 248100d0963fSdilpreet mutex_enter(err_mutexp); 2482eae2e508Skrishnae rval = pci_peekpoke_check_fma(dip, arg, ctlop, scan); 248300d0963fSdilpreet mutex_exit(err_mutexp); 248400d0963fSdilpreet } 248500d0963fSdilpreet mutex_exit(peek_poke_mutexp); 248600d0963fSdilpreet return (rval); 248700d0963fSdilpreet } 248800d0963fSdilpreet 24897c478bd9Sstevel@tonic-gate void 24907c478bd9Sstevel@tonic-gate impl_setup_ddi(void) 24917c478bd9Sstevel@tonic-gate { 24928770118eSlipeng sang - Sun Microsystems - Beijing China #if !defined(__xpv) 24938770118eSlipeng sang - Sun Microsystems - Beijing China extern void startup_bios_disk(void); 24948770118eSlipeng sang - Sun Microsystems - Beijing China extern int post_fastreboot; 24958770118eSlipeng sang - Sun Microsystems - Beijing China #endif 24967c478bd9Sstevel@tonic-gate dev_info_t *xdip, *isa_dip; 24977c478bd9Sstevel@tonic-gate rd_existing_t rd_mem_prop; 24987c478bd9Sstevel@tonic-gate int err; 24997c478bd9Sstevel@tonic-gate 25007c478bd9Sstevel@tonic-gate ndi_devi_alloc_sleep(ddi_root_node(), "ramdisk", 2501fa9e4066Sahrens (pnode_t)DEVI_SID_NODEID, &xdip); 25027c478bd9Sstevel@tonic-gate 25037c478bd9Sstevel@tonic-gate (void) BOP_GETPROP(bootops, 25047c478bd9Sstevel@tonic-gate "ramdisk_start", (void *)&ramdisk_start); 25057c478bd9Sstevel@tonic-gate (void) BOP_GETPROP(bootops, 25067c478bd9Sstevel@tonic-gate "ramdisk_end", (void *)&ramdisk_end); 25077c478bd9Sstevel@tonic-gate 2508843e1988Sjohnlev #ifdef __xpv 2509843e1988Sjohnlev ramdisk_start -= ONE_GIG; 2510843e1988Sjohnlev ramdisk_end -= ONE_GIG; 2511843e1988Sjohnlev #endif 25127c478bd9Sstevel@tonic-gate rd_mem_prop.phys = ramdisk_start; 25137c478bd9Sstevel@tonic-gate rd_mem_prop.size = ramdisk_end - ramdisk_start + 1; 25147c478bd9Sstevel@tonic-gate 25157c478bd9Sstevel@tonic-gate (void) ndi_prop_update_byte_array(DDI_DEV_T_NONE, xdip, 25167c478bd9Sstevel@tonic-gate RD_EXISTING_PROP_NAME, (uchar_t *)&rd_mem_prop, 25177c478bd9Sstevel@tonic-gate sizeof (rd_mem_prop)); 25187c478bd9Sstevel@tonic-gate err = ndi_devi_bind_driver(xdip, 0); 25197c478bd9Sstevel@tonic-gate ASSERT(err == 0); 25207c478bd9Sstevel@tonic-gate 25217c478bd9Sstevel@tonic-gate /* isa node */ 252278323854SJudy Chen if (pseudo_isa) { 25237c478bd9Sstevel@tonic-gate ndi_devi_alloc_sleep(ddi_root_node(), "isa", 2524fa9e4066Sahrens (pnode_t)DEVI_SID_NODEID, &isa_dip); 25257c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, isa_dip, 25267c478bd9Sstevel@tonic-gate "device_type", "isa"); 25277c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, isa_dip, 25287c478bd9Sstevel@tonic-gate "bus-type", "isa"); 25297c478bd9Sstevel@tonic-gate (void) ndi_devi_bind_driver(isa_dip, 0); 253078323854SJudy Chen } 25317c478bd9Sstevel@tonic-gate 25327c478bd9Sstevel@tonic-gate /* 25337c478bd9Sstevel@tonic-gate * Read in the properties from the boot. 25347c478bd9Sstevel@tonic-gate */ 25357c478bd9Sstevel@tonic-gate get_boot_properties(); 25367c478bd9Sstevel@tonic-gate 25377c478bd9Sstevel@tonic-gate /* not framebuffer should be enumerated, if present */ 25387c478bd9Sstevel@tonic-gate get_vga_properties(); 25398770118eSlipeng sang - Sun Microsystems - Beijing China 2540288e2932SJerry Gilliam /* 2541288e2932SJerry Gilliam * Check for administratively disabled drivers. 2542288e2932SJerry Gilliam */ 2543288e2932SJerry Gilliam check_driver_disable(); 2544288e2932SJerry Gilliam 25458770118eSlipeng sang - Sun Microsystems - Beijing China #if !defined(__xpv) 25468770118eSlipeng sang - Sun Microsystems - Beijing China if (!post_fastreboot) 25478770118eSlipeng sang - Sun Microsystems - Beijing China startup_bios_disk(); 25488770118eSlipeng sang - Sun Microsystems - Beijing China #endif 25498770118eSlipeng sang - Sun Microsystems - Beijing China /* do bus dependent probes. */ 25508770118eSlipeng sang - Sun Microsystems - Beijing China impl_bus_initialprobe(); 25517c478bd9Sstevel@tonic-gate } 25527c478bd9Sstevel@tonic-gate 25537c478bd9Sstevel@tonic-gate dev_t 25547c478bd9Sstevel@tonic-gate getrootdev(void) 25557c478bd9Sstevel@tonic-gate { 25567c478bd9Sstevel@tonic-gate /* 25577c478bd9Sstevel@tonic-gate * Usually rootfs.bo_name is initialized by the 25587c478bd9Sstevel@tonic-gate * the bootpath property from bootenv.rc, but 25597c478bd9Sstevel@tonic-gate * defaults to "/ramdisk:a" otherwise. 25607c478bd9Sstevel@tonic-gate */ 25617c478bd9Sstevel@tonic-gate return (ddi_pathname_to_dev_t(rootfs.bo_name)); 25627c478bd9Sstevel@tonic-gate } 25637c478bd9Sstevel@tonic-gate 25647c478bd9Sstevel@tonic-gate static struct bus_probe { 25657c478bd9Sstevel@tonic-gate struct bus_probe *next; 25667c478bd9Sstevel@tonic-gate void (*probe)(int); 25677c478bd9Sstevel@tonic-gate } *bus_probes; 25687c478bd9Sstevel@tonic-gate 25697c478bd9Sstevel@tonic-gate void 25707c478bd9Sstevel@tonic-gate impl_bus_add_probe(void (*func)(int)) 25717c478bd9Sstevel@tonic-gate { 25727c478bd9Sstevel@tonic-gate struct bus_probe *probe; 257337d6e245Slipeng sang - Sun Microsystems - Beijing China struct bus_probe *lastprobe = NULL; 25747c478bd9Sstevel@tonic-gate 25757c478bd9Sstevel@tonic-gate probe = kmem_alloc(sizeof (*probe), KM_SLEEP); 25767c478bd9Sstevel@tonic-gate probe->probe = func; 257737d6e245Slipeng sang - Sun Microsystems - Beijing China probe->next = NULL; 257837d6e245Slipeng sang - Sun Microsystems - Beijing China 257937d6e245Slipeng sang - Sun Microsystems - Beijing China if (!bus_probes) { 25807c478bd9Sstevel@tonic-gate bus_probes = probe; 258137d6e245Slipeng sang - Sun Microsystems - Beijing China return; 258237d6e245Slipeng sang - Sun Microsystems - Beijing China } 258337d6e245Slipeng sang - Sun Microsystems - Beijing China 258437d6e245Slipeng sang - Sun Microsystems - Beijing China lastprobe = bus_probes; 258537d6e245Slipeng sang - Sun Microsystems - Beijing China while (lastprobe->next) 258637d6e245Slipeng sang - Sun Microsystems - Beijing China lastprobe = lastprobe->next; 258737d6e245Slipeng sang - Sun Microsystems - Beijing China lastprobe->next = probe; 25887c478bd9Sstevel@tonic-gate } 25897c478bd9Sstevel@tonic-gate 25907c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 25917c478bd9Sstevel@tonic-gate void 25927c478bd9Sstevel@tonic-gate impl_bus_delete_probe(void (*func)(int)) 25937c478bd9Sstevel@tonic-gate { 25947c478bd9Sstevel@tonic-gate struct bus_probe *prev = NULL; 25957c478bd9Sstevel@tonic-gate struct bus_probe *probe = bus_probes; 25967c478bd9Sstevel@tonic-gate 25977c478bd9Sstevel@tonic-gate while (probe) { 25987c478bd9Sstevel@tonic-gate if (probe->probe == func) 25997c478bd9Sstevel@tonic-gate break; 26007c478bd9Sstevel@tonic-gate prev = probe; 26017c478bd9Sstevel@tonic-gate probe = probe->next; 26027c478bd9Sstevel@tonic-gate } 26037c478bd9Sstevel@tonic-gate 26047c478bd9Sstevel@tonic-gate if (probe == NULL) 26057c478bd9Sstevel@tonic-gate return; 26067c478bd9Sstevel@tonic-gate 26077c478bd9Sstevel@tonic-gate if (prev) 26087c478bd9Sstevel@tonic-gate prev->next = probe->next; 26097c478bd9Sstevel@tonic-gate else 26107c478bd9Sstevel@tonic-gate bus_probes = probe->next; 26117c478bd9Sstevel@tonic-gate 26127c478bd9Sstevel@tonic-gate kmem_free(probe, sizeof (struct bus_probe)); 26137c478bd9Sstevel@tonic-gate } 26147c478bd9Sstevel@tonic-gate 26157c478bd9Sstevel@tonic-gate /* 26167c478bd9Sstevel@tonic-gate * impl_bus_initialprobe 26177c478bd9Sstevel@tonic-gate * Modload the prom simulator, then let it probe to verify existence 26187c478bd9Sstevel@tonic-gate * and type of PCI support. 26197c478bd9Sstevel@tonic-gate */ 26207c478bd9Sstevel@tonic-gate static void 26217c478bd9Sstevel@tonic-gate impl_bus_initialprobe(void) 26227c478bd9Sstevel@tonic-gate { 26237c478bd9Sstevel@tonic-gate struct bus_probe *probe; 26247c478bd9Sstevel@tonic-gate 26257c478bd9Sstevel@tonic-gate /* load modules to install bus probes */ 2626843e1988Sjohnlev #if defined(__xpv) 2627843e1988Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info)) { 26287c478bd9Sstevel@tonic-gate if (modload("misc", "pci_autoconfig") < 0) { 2629843e1988Sjohnlev panic("failed to load misc/pci_autoconfig"); 26307c478bd9Sstevel@tonic-gate } 263137d6e245Slipeng sang - Sun Microsystems - Beijing China 263237d6e245Slipeng sang - Sun Microsystems - Beijing China if (modload("drv", "isa") < 0) 263337d6e245Slipeng sang - Sun Microsystems - Beijing China panic("failed to load drv/isa"); 2634843e1988Sjohnlev } 263537d6e245Slipeng sang - Sun Microsystems - Beijing China 2636843e1988Sjohnlev (void) modload("misc", "xpv_autoconfig"); 2637843e1988Sjohnlev #else 2638843e1988Sjohnlev if (modload("misc", "pci_autoconfig") < 0) { 2639843e1988Sjohnlev panic("failed to load misc/pci_autoconfig"); 2640843e1988Sjohnlev } 264137d6e245Slipeng sang - Sun Microsystems - Beijing China 2642432cf5a9SDana Myers (void) modload("misc", "acpidev"); 2643432cf5a9SDana Myers 264437d6e245Slipeng sang - Sun Microsystems - Beijing China if (modload("drv", "isa") < 0) 264537d6e245Slipeng sang - Sun Microsystems - Beijing China panic("failed to load drv/isa"); 2646843e1988Sjohnlev #endif 26477c478bd9Sstevel@tonic-gate 26487c478bd9Sstevel@tonic-gate probe = bus_probes; 26497c478bd9Sstevel@tonic-gate while (probe) { 2650843e1988Sjohnlev /* run the probe functions */ 26517c478bd9Sstevel@tonic-gate (*probe->probe)(0); 26527c478bd9Sstevel@tonic-gate probe = probe->next; 26537c478bd9Sstevel@tonic-gate } 26547c478bd9Sstevel@tonic-gate } 26557c478bd9Sstevel@tonic-gate 26567c478bd9Sstevel@tonic-gate /* 26577c478bd9Sstevel@tonic-gate * impl_bus_reprobe 26587c478bd9Sstevel@tonic-gate * Reprogram devices not set up by firmware. 26597c478bd9Sstevel@tonic-gate */ 26607c478bd9Sstevel@tonic-gate static void 26617c478bd9Sstevel@tonic-gate impl_bus_reprobe(void) 26627c478bd9Sstevel@tonic-gate { 26637c478bd9Sstevel@tonic-gate struct bus_probe *probe; 26647c478bd9Sstevel@tonic-gate 26657c478bd9Sstevel@tonic-gate probe = bus_probes; 26667c478bd9Sstevel@tonic-gate while (probe) { 26677c478bd9Sstevel@tonic-gate /* run the probe function */ 26687c478bd9Sstevel@tonic-gate (*probe->probe)(1); 26697c478bd9Sstevel@tonic-gate probe = probe->next; 26707c478bd9Sstevel@tonic-gate } 26717c478bd9Sstevel@tonic-gate } 267200d0963fSdilpreet 267300d0963fSdilpreet 267400d0963fSdilpreet /* 267500d0963fSdilpreet * The following functions ready a cautious request to go up to the nexus 267600d0963fSdilpreet * driver. It is up to the nexus driver to decide how to process the request. 267700d0963fSdilpreet * It may choose to call i_ddi_do_caut_get/put in this file, or do it 267800d0963fSdilpreet * differently. 267900d0963fSdilpreet */ 268000d0963fSdilpreet 268100d0963fSdilpreet static void 268200d0963fSdilpreet i_ddi_caut_getput_ctlops(ddi_acc_impl_t *hp, uint64_t host_addr, 268300d0963fSdilpreet uint64_t dev_addr, size_t size, size_t repcount, uint_t flags, 268400d0963fSdilpreet ddi_ctl_enum_t cmd) 268500d0963fSdilpreet { 268600d0963fSdilpreet peekpoke_ctlops_t cautacc_ctlops_arg; 268700d0963fSdilpreet 268800d0963fSdilpreet cautacc_ctlops_arg.size = size; 268900d0963fSdilpreet cautacc_ctlops_arg.dev_addr = dev_addr; 269000d0963fSdilpreet cautacc_ctlops_arg.host_addr = host_addr; 269100d0963fSdilpreet cautacc_ctlops_arg.handle = (ddi_acc_handle_t)hp; 269200d0963fSdilpreet cautacc_ctlops_arg.repcount = repcount; 269300d0963fSdilpreet cautacc_ctlops_arg.flags = flags; 269400d0963fSdilpreet 269500d0963fSdilpreet (void) ddi_ctlops(hp->ahi_common.ah_dip, hp->ahi_common.ah_dip, cmd, 269600d0963fSdilpreet &cautacc_ctlops_arg, NULL); 269700d0963fSdilpreet } 269800d0963fSdilpreet 269900d0963fSdilpreet uint8_t 270000d0963fSdilpreet i_ddi_caut_get8(ddi_acc_impl_t *hp, uint8_t *addr) 270100d0963fSdilpreet { 270200d0963fSdilpreet uint8_t value; 270300d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 270400d0963fSdilpreet sizeof (uint8_t), 1, 0, DDI_CTLOPS_PEEK); 270500d0963fSdilpreet 270600d0963fSdilpreet return (value); 270700d0963fSdilpreet } 270800d0963fSdilpreet 270900d0963fSdilpreet uint16_t 271000d0963fSdilpreet i_ddi_caut_get16(ddi_acc_impl_t *hp, uint16_t *addr) 271100d0963fSdilpreet { 271200d0963fSdilpreet uint16_t value; 271300d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 271400d0963fSdilpreet sizeof (uint16_t), 1, 0, DDI_CTLOPS_PEEK); 271500d0963fSdilpreet 271600d0963fSdilpreet return (value); 271700d0963fSdilpreet } 271800d0963fSdilpreet 271900d0963fSdilpreet uint32_t 272000d0963fSdilpreet i_ddi_caut_get32(ddi_acc_impl_t *hp, uint32_t *addr) 272100d0963fSdilpreet { 272200d0963fSdilpreet uint32_t value; 272300d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 272400d0963fSdilpreet sizeof (uint32_t), 1, 0, DDI_CTLOPS_PEEK); 272500d0963fSdilpreet 272600d0963fSdilpreet return (value); 272700d0963fSdilpreet } 272800d0963fSdilpreet 272900d0963fSdilpreet uint64_t 273000d0963fSdilpreet i_ddi_caut_get64(ddi_acc_impl_t *hp, uint64_t *addr) 273100d0963fSdilpreet { 273200d0963fSdilpreet uint64_t value; 273300d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 273400d0963fSdilpreet sizeof (uint64_t), 1, 0, DDI_CTLOPS_PEEK); 273500d0963fSdilpreet 273600d0963fSdilpreet return (value); 273700d0963fSdilpreet } 273800d0963fSdilpreet 273900d0963fSdilpreet void 274000d0963fSdilpreet i_ddi_caut_put8(ddi_acc_impl_t *hp, uint8_t *addr, uint8_t value) 274100d0963fSdilpreet { 274200d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 274300d0963fSdilpreet sizeof (uint8_t), 1, 0, DDI_CTLOPS_POKE); 274400d0963fSdilpreet } 274500d0963fSdilpreet 274600d0963fSdilpreet void 274700d0963fSdilpreet i_ddi_caut_put16(ddi_acc_impl_t *hp, uint16_t *addr, uint16_t value) 274800d0963fSdilpreet { 274900d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 275000d0963fSdilpreet sizeof (uint16_t), 1, 0, DDI_CTLOPS_POKE); 275100d0963fSdilpreet } 275200d0963fSdilpreet 275300d0963fSdilpreet void 275400d0963fSdilpreet i_ddi_caut_put32(ddi_acc_impl_t *hp, uint32_t *addr, uint32_t value) 275500d0963fSdilpreet { 275600d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 275700d0963fSdilpreet sizeof (uint32_t), 1, 0, DDI_CTLOPS_POKE); 275800d0963fSdilpreet } 275900d0963fSdilpreet 276000d0963fSdilpreet void 276100d0963fSdilpreet i_ddi_caut_put64(ddi_acc_impl_t *hp, uint64_t *addr, uint64_t value) 276200d0963fSdilpreet { 276300d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)&value, (uintptr_t)addr, 276400d0963fSdilpreet sizeof (uint64_t), 1, 0, DDI_CTLOPS_POKE); 276500d0963fSdilpreet } 276600d0963fSdilpreet 276700d0963fSdilpreet void 276800d0963fSdilpreet i_ddi_caut_rep_get8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr, 276900d0963fSdilpreet size_t repcount, uint_t flags) 277000d0963fSdilpreet { 277100d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 277200d0963fSdilpreet sizeof (uint8_t), repcount, flags, DDI_CTLOPS_PEEK); 277300d0963fSdilpreet } 277400d0963fSdilpreet 277500d0963fSdilpreet void 277600d0963fSdilpreet i_ddi_caut_rep_get16(ddi_acc_impl_t *hp, uint16_t *host_addr, 277700d0963fSdilpreet uint16_t *dev_addr, size_t repcount, uint_t flags) 277800d0963fSdilpreet { 277900d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 278000d0963fSdilpreet sizeof (uint16_t), repcount, flags, DDI_CTLOPS_PEEK); 278100d0963fSdilpreet } 278200d0963fSdilpreet 278300d0963fSdilpreet void 278400d0963fSdilpreet i_ddi_caut_rep_get32(ddi_acc_impl_t *hp, uint32_t *host_addr, 278500d0963fSdilpreet uint32_t *dev_addr, size_t repcount, uint_t flags) 278600d0963fSdilpreet { 278700d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 278800d0963fSdilpreet sizeof (uint32_t), repcount, flags, DDI_CTLOPS_PEEK); 278900d0963fSdilpreet } 279000d0963fSdilpreet 279100d0963fSdilpreet void 279200d0963fSdilpreet i_ddi_caut_rep_get64(ddi_acc_impl_t *hp, uint64_t *host_addr, 279300d0963fSdilpreet uint64_t *dev_addr, size_t repcount, uint_t flags) 279400d0963fSdilpreet { 279500d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 279600d0963fSdilpreet sizeof (uint64_t), repcount, flags, DDI_CTLOPS_PEEK); 279700d0963fSdilpreet } 279800d0963fSdilpreet 279900d0963fSdilpreet void 280000d0963fSdilpreet i_ddi_caut_rep_put8(ddi_acc_impl_t *hp, uint8_t *host_addr, uint8_t *dev_addr, 280100d0963fSdilpreet size_t repcount, uint_t flags) 280200d0963fSdilpreet { 280300d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 280400d0963fSdilpreet sizeof (uint8_t), repcount, flags, DDI_CTLOPS_POKE); 280500d0963fSdilpreet } 280600d0963fSdilpreet 280700d0963fSdilpreet void 280800d0963fSdilpreet i_ddi_caut_rep_put16(ddi_acc_impl_t *hp, uint16_t *host_addr, 280900d0963fSdilpreet uint16_t *dev_addr, size_t repcount, uint_t flags) 281000d0963fSdilpreet { 281100d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 281200d0963fSdilpreet sizeof (uint16_t), repcount, flags, DDI_CTLOPS_POKE); 281300d0963fSdilpreet } 281400d0963fSdilpreet 281500d0963fSdilpreet void 281600d0963fSdilpreet i_ddi_caut_rep_put32(ddi_acc_impl_t *hp, uint32_t *host_addr, 281700d0963fSdilpreet uint32_t *dev_addr, size_t repcount, uint_t flags) 281800d0963fSdilpreet { 281900d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 282000d0963fSdilpreet sizeof (uint32_t), repcount, flags, DDI_CTLOPS_POKE); 282100d0963fSdilpreet } 282200d0963fSdilpreet 282300d0963fSdilpreet void 282400d0963fSdilpreet i_ddi_caut_rep_put64(ddi_acc_impl_t *hp, uint64_t *host_addr, 282500d0963fSdilpreet uint64_t *dev_addr, size_t repcount, uint_t flags) 282600d0963fSdilpreet { 282700d0963fSdilpreet i_ddi_caut_getput_ctlops(hp, (uintptr_t)host_addr, (uintptr_t)dev_addr, 282800d0963fSdilpreet sizeof (uint64_t), repcount, flags, DDI_CTLOPS_POKE); 282900d0963fSdilpreet } 283036945f79Smrj 283136945f79Smrj boolean_t 283236945f79Smrj i_ddi_copybuf_required(ddi_dma_attr_t *attrp) 283336945f79Smrj { 283436945f79Smrj uint64_t hi_pa; 283536945f79Smrj 283636945f79Smrj hi_pa = ((uint64_t)physmax + 1ull) << PAGESHIFT; 283736945f79Smrj if (attrp->dma_attr_addr_hi < hi_pa) { 283836945f79Smrj return (B_TRUE); 283936945f79Smrj } 284036945f79Smrj 284136945f79Smrj return (B_FALSE); 284236945f79Smrj } 284336945f79Smrj 284436945f79Smrj size_t 284536945f79Smrj i_ddi_copybuf_size() 284636945f79Smrj { 284736945f79Smrj return (dma_max_copybuf_size); 284836945f79Smrj } 284936945f79Smrj 285036945f79Smrj /* 285136945f79Smrj * i_ddi_dma_max() 285236945f79Smrj * returns the maximum DMA size which can be performed in a single DMA 285336945f79Smrj * window taking into account the devices DMA contraints (attrp), the 285436945f79Smrj * maximum copy buffer size (if applicable), and the worse case buffer 285536945f79Smrj * fragmentation. 285636945f79Smrj */ 285736945f79Smrj /*ARGSUSED*/ 285836945f79Smrj uint32_t 285936945f79Smrj i_ddi_dma_max(dev_info_t *dip, ddi_dma_attr_t *attrp) 286036945f79Smrj { 286136945f79Smrj uint64_t maxxfer; 286236945f79Smrj 286336945f79Smrj 286436945f79Smrj /* 286536945f79Smrj * take the min of maxxfer and the the worse case fragementation 286636945f79Smrj * (e.g. every cookie <= 1 page) 286736945f79Smrj */ 286836945f79Smrj maxxfer = MIN(attrp->dma_attr_maxxfer, 286936945f79Smrj ((uint64_t)(attrp->dma_attr_sgllen - 1) << PAGESHIFT)); 287036945f79Smrj 287136945f79Smrj /* 287236945f79Smrj * If the DMA engine can't reach all off memory, we also need to take 287336945f79Smrj * the max size of the copybuf into consideration. 287436945f79Smrj */ 287536945f79Smrj if (i_ddi_copybuf_required(attrp)) { 287636945f79Smrj maxxfer = MIN(i_ddi_copybuf_size(), maxxfer); 287736945f79Smrj } 287836945f79Smrj 287936945f79Smrj /* 288036945f79Smrj * we only return a 32-bit value. Make sure it's not -1. Round to a 288136945f79Smrj * page so it won't be mistaken for an error value during debug. 288236945f79Smrj */ 288336945f79Smrj if (maxxfer >= 0xFFFFFFFF) { 288436945f79Smrj maxxfer = 0xFFFFF000; 288536945f79Smrj } 288636945f79Smrj 288736945f79Smrj /* 288836945f79Smrj * make sure the value we return is a whole multiple of the 288936945f79Smrj * granlarity. 289036945f79Smrj */ 289136945f79Smrj if (attrp->dma_attr_granular > 1) { 289236945f79Smrj maxxfer = maxxfer - (maxxfer % attrp->dma_attr_granular); 289336945f79Smrj } 289436945f79Smrj 289536945f79Smrj return ((uint32_t)maxxfer); 289636945f79Smrj } 2897a56d24eaSMark Johnson 2898fc256490SJason Beloro /*ARGSUSED*/ 2899fc256490SJason Beloro void 2900fc256490SJason Beloro translate_devid(dev_info_t *dip) 2901fc256490SJason Beloro { 2902fc256490SJason Beloro } 2903fc256490SJason Beloro 2904a56d24eaSMark Johnson pfn_t 2905a56d24eaSMark Johnson i_ddi_paddr_to_pfn(paddr_t paddr) 2906a56d24eaSMark Johnson { 2907a56d24eaSMark Johnson pfn_t pfn; 2908a56d24eaSMark Johnson 2909a56d24eaSMark Johnson #ifdef __xpv 2910a56d24eaSMark Johnson if (DOMAIN_IS_INITDOMAIN(xen_info)) { 2911a56d24eaSMark Johnson pfn = xen_assign_pfn(mmu_btop(paddr)); 2912a56d24eaSMark Johnson } else { 2913a56d24eaSMark Johnson pfn = mmu_btop(paddr); 2914a56d24eaSMark Johnson } 2915a56d24eaSMark Johnson #else 2916a56d24eaSMark Johnson pfn = mmu_btop(paddr); 2917a56d24eaSMark Johnson #endif 2918a56d24eaSMark Johnson 2919a56d24eaSMark Johnson return (pfn); 2920a56d24eaSMark Johnson } 2921