10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * PCI-IDE bus nexus driver 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #include <sys/types.h> 340Sstevel@tonic-gate #include <sys/cmn_err.h> 350Sstevel@tonic-gate #include <sys/conf.h> 360Sstevel@tonic-gate #include <sys/errno.h> 370Sstevel@tonic-gate #include <sys/debug.h> 380Sstevel@tonic-gate #include <sys/ddidmareq.h> 390Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 400Sstevel@tonic-gate #include <sys/dma_engine.h> 410Sstevel@tonic-gate #include <sys/modctl.h> 420Sstevel@tonic-gate #include <sys/ddi.h> 430Sstevel@tonic-gate #include <sys/sunddi.h> 440Sstevel@tonic-gate #include <sys/kmem.h> 450Sstevel@tonic-gate #include <sys/pci.h> 460Sstevel@tonic-gate #include <sys/promif.h> 470Sstevel@tonic-gate #include <sys/pci_intr_lib.h> 480Sstevel@tonic-gate 490Sstevel@tonic-gate int pciide_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 500Sstevel@tonic-gate 510Sstevel@tonic-gate #define PCIIDE_NATIVE_MODE(dip) \ 520Sstevel@tonic-gate (!ddi_prop_exists(DDI_DEV_T_ANY, (dip), DDI_PROP_DONTPASS, \ 530Sstevel@tonic-gate "compatibility-mode")) 540Sstevel@tonic-gate 550Sstevel@tonic-gate #define PCIIDE_PRE26(dip) \ 560Sstevel@tonic-gate ddi_prop_exists(DDI_DEV_T_ANY, (dip), 0, "ignore-hardware-nodes") 570Sstevel@tonic-gate 580Sstevel@tonic-gate #define PCI_IDE_IF_BM_CAP_MASK 0x80 590Sstevel@tonic-gate 60430Smrj #define PCIIDE_PDSIZE (sizeof (struct ddi_parent_private_data) + \ 61430Smrj sizeof (struct intrspec)) 62430Smrj 630Sstevel@tonic-gate #ifdef DEBUG 640Sstevel@tonic-gate static int pci_ide_debug = 0; 650Sstevel@tonic-gate #define PDBG(fmt) \ 660Sstevel@tonic-gate if (pci_ide_debug) { \ 670Sstevel@tonic-gate prom_printf fmt; \ 680Sstevel@tonic-gate } 690Sstevel@tonic-gate #else 700Sstevel@tonic-gate #define PDBG(fmt) 710Sstevel@tonic-gate #endif 720Sstevel@tonic-gate 730Sstevel@tonic-gate #ifndef TRUE 740Sstevel@tonic-gate #define TRUE 1 750Sstevel@tonic-gate #endif 760Sstevel@tonic-gate #ifndef FALSE 770Sstevel@tonic-gate #define FALSE 0 780Sstevel@tonic-gate #endif 790Sstevel@tonic-gate 800Sstevel@tonic-gate /* 810Sstevel@tonic-gate * bus_ops functions 820Sstevel@tonic-gate */ 830Sstevel@tonic-gate 840Sstevel@tonic-gate static int pciide_bus_map(dev_info_t *dip, dev_info_t *rdip, 850Sstevel@tonic-gate ddi_map_req_t *mp, off_t offset, off_t len, 860Sstevel@tonic-gate caddr_t *vaddrp); 870Sstevel@tonic-gate 880Sstevel@tonic-gate static int pciide_ddi_ctlops(dev_info_t *dip, dev_info_t *rdip, 890Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, 900Sstevel@tonic-gate void *result); 910Sstevel@tonic-gate 920Sstevel@tonic-gate static int pciide_get_pri(dev_info_t *dip, dev_info_t *rdip, 930Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, int *pri); 940Sstevel@tonic-gate 950Sstevel@tonic-gate static int pciide_intr_ops(dev_info_t *dip, dev_info_t *rdip, 960Sstevel@tonic-gate ddi_intr_op_t intr_op, 970Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result); 980Sstevel@tonic-gate 990Sstevel@tonic-gate static struct intrspec *pciide_get_ispec(dev_info_t *dip, dev_info_t *rdip, 1000Sstevel@tonic-gate int inum); 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate /* 1030Sstevel@tonic-gate * Local Functions 1040Sstevel@tonic-gate */ 1050Sstevel@tonic-gate static int pciide_initchild(dev_info_t *mydip, dev_info_t *cdip); 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate static void pciide_compat_setup(dev_info_t *mydip, dev_info_t *cdip, 1080Sstevel@tonic-gate int dev); 1090Sstevel@tonic-gate static int pciide_pre26_rnumber_map(dev_info_t *mydip, int rnumber); 1100Sstevel@tonic-gate static int pciide_map_rnumber(int canonical_rnumber, int pri_native, 1110Sstevel@tonic-gate int sec_native); 1120Sstevel@tonic-gate 1130Sstevel@tonic-gate 1140Sstevel@tonic-gate /* 1150Sstevel@tonic-gate * Config information 1160Sstevel@tonic-gate */ 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate struct bus_ops pciide_bus_ops = { 1190Sstevel@tonic-gate BUSO_REV, 1200Sstevel@tonic-gate pciide_bus_map, 1210Sstevel@tonic-gate 0, 1220Sstevel@tonic-gate 0, 1230Sstevel@tonic-gate 0, 1240Sstevel@tonic-gate i_ddi_map_fault, 1250Sstevel@tonic-gate ddi_dma_map, 1260Sstevel@tonic-gate ddi_dma_allochdl, 1270Sstevel@tonic-gate ddi_dma_freehdl, 1280Sstevel@tonic-gate ddi_dma_bindhdl, 1290Sstevel@tonic-gate ddi_dma_unbindhdl, 1300Sstevel@tonic-gate ddi_dma_flush, 1310Sstevel@tonic-gate ddi_dma_win, 1320Sstevel@tonic-gate ddi_dma_mctl, 1330Sstevel@tonic-gate pciide_ddi_ctlops, 1340Sstevel@tonic-gate ddi_bus_prop_op, 1350Sstevel@tonic-gate 0, /* (*bus_get_eventcookie)(); */ 1360Sstevel@tonic-gate 0, /* (*bus_add_eventcall)(); */ 1370Sstevel@tonic-gate 0, /* (*bus_remove_eventcall)(); */ 1380Sstevel@tonic-gate 0, /* (*bus_post_event)(); */ 1390Sstevel@tonic-gate 0, 1400Sstevel@tonic-gate 0, 1410Sstevel@tonic-gate 0, 1420Sstevel@tonic-gate 0, 1430Sstevel@tonic-gate 0, 1440Sstevel@tonic-gate 0, 1450Sstevel@tonic-gate 0, 1460Sstevel@tonic-gate 0, 1470Sstevel@tonic-gate pciide_intr_ops 1480Sstevel@tonic-gate }; 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate struct dev_ops pciide_ops = { 1510Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 1520Sstevel@tonic-gate 0, /* refcnt */ 1530Sstevel@tonic-gate ddi_no_info, /* info */ 1540Sstevel@tonic-gate nulldev, /* identify */ 1550Sstevel@tonic-gate nulldev, /* probe */ 1560Sstevel@tonic-gate pciide_attach, /* attach */ 1570Sstevel@tonic-gate nodev, /* detach */ 1580Sstevel@tonic-gate nodev, /* reset */ 1590Sstevel@tonic-gate (struct cb_ops *)0, /* driver operations */ 1600Sstevel@tonic-gate &pciide_bus_ops /* bus operations */ 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate }; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate /* 1650Sstevel@tonic-gate * Module linkage information for the kernel. 1660Sstevel@tonic-gate */ 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate static struct modldrv modldrv = { 1690Sstevel@tonic-gate &mod_driverops, /* Type of module. This is PCI-IDE bus driver */ 1700Sstevel@tonic-gate "pciide nexus driver for 'PCI-IDE' %I%", 1710Sstevel@tonic-gate &pciide_ops, /* driver ops */ 1720Sstevel@tonic-gate }; 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate static struct modlinkage modlinkage = { 1750Sstevel@tonic-gate MODREV_1, 1760Sstevel@tonic-gate &modldrv, 1770Sstevel@tonic-gate NULL 1780Sstevel@tonic-gate }; 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate int 1820Sstevel@tonic-gate _init(void) 1830Sstevel@tonic-gate { 1840Sstevel@tonic-gate return (mod_install(&modlinkage)); 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate int 1880Sstevel@tonic-gate _fini(void) 1890Sstevel@tonic-gate { 1900Sstevel@tonic-gate return (mod_remove(&modlinkage)); 1910Sstevel@tonic-gate } 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate int 1940Sstevel@tonic-gate _info(struct modinfo *modinfop) 1950Sstevel@tonic-gate { 1960Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1970Sstevel@tonic-gate } 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate int 2000Sstevel@tonic-gate pciide_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 2010Sstevel@tonic-gate { 2020Sstevel@tonic-gate uint16_t cmdreg; 2030Sstevel@tonic-gate ddi_acc_handle_t conf_hdl = NULL; 2040Sstevel@tonic-gate int rc; 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate if (cmd == DDI_ATTACH) { 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate /* 2100Sstevel@tonic-gate * Make sure bus-mastering is enabled, even if 2110Sstevel@tonic-gate * BIOS didn't. 2120Sstevel@tonic-gate */ 213*466Smrj rc = pci_config_setup(dip, &conf_hdl); 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate /* 2160Sstevel@tonic-gate * In case of error, return SUCCESS. This is because 2170Sstevel@tonic-gate * bus-mastering could be already enabled by BIOS. 2180Sstevel@tonic-gate */ 2190Sstevel@tonic-gate if (rc != DDI_SUCCESS) 2200Sstevel@tonic-gate return (DDI_SUCCESS); 2210Sstevel@tonic-gate 222*466Smrj cmdreg = pci_config_get16(conf_hdl, PCI_CONF_COMM); 2230Sstevel@tonic-gate if ((cmdreg & PCI_COMM_ME) == 0) { 224*466Smrj pci_config_put16(conf_hdl, PCI_CONF_COMM, 2250Sstevel@tonic-gate cmdreg | PCI_COMM_ME); 2260Sstevel@tonic-gate } 227*466Smrj pci_config_teardown(&conf_hdl); 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate return (DDI_SUCCESS); 2300Sstevel@tonic-gate } else { 2310Sstevel@tonic-gate return (DDI_FAILURE); 2320Sstevel@tonic-gate } 2330Sstevel@tonic-gate } 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate 2360Sstevel@tonic-gate /*ARGSUSED*/ 2370Sstevel@tonic-gate static int 2380Sstevel@tonic-gate pciide_ddi_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_ctl_enum_t ctlop, 2390Sstevel@tonic-gate void *arg, void *result) 2400Sstevel@tonic-gate { 241430Smrj dev_info_t *cdip; 242430Smrj int controller; 243430Smrj void *pdptr; 244430Smrj int rnumber; 245430Smrj off_t tmp; 246430Smrj int rc; 2470Sstevel@tonic-gate 2480Sstevel@tonic-gate PDBG(("pciide_bus_ctl\n")); 2490Sstevel@tonic-gate 2500Sstevel@tonic-gate switch (ctlop) { 2510Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 252430Smrj cdip = (dev_info_t *)arg; 253430Smrj return (pciide_initchild(dip, cdip)); 2540Sstevel@tonic-gate 2550Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 256430Smrj cdip = (dev_info_t *)arg; 257430Smrj pdptr = ddi_get_parent_data(cdip); 258430Smrj ddi_set_parent_data(cdip, NULL); 259430Smrj ddi_set_name_addr(cdip, NULL); 260430Smrj kmem_free(pdptr, PCIIDE_PDSIZE); 261430Smrj return (DDI_SUCCESS); 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 2640Sstevel@tonic-gate *(int *)result = 3; 2650Sstevel@tonic-gate return (DDI_SUCCESS); 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 2680Sstevel@tonic-gate /* 2690Sstevel@tonic-gate * Adjust the rnumbers based on which controller instance 2700Sstevel@tonic-gate * is requested; adjust for the 2 tuples per controller. 2710Sstevel@tonic-gate */ 2720Sstevel@tonic-gate if (strcmp("0", ddi_get_name_addr(rdip)) == 0) 2730Sstevel@tonic-gate controller = 0; 2740Sstevel@tonic-gate else 2750Sstevel@tonic-gate controller = 1; 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate switch (rnumber = *(int *)arg) { 2790Sstevel@tonic-gate case 0: 2800Sstevel@tonic-gate case 1: 2810Sstevel@tonic-gate rnumber += (2 * controller); 2820Sstevel@tonic-gate break; 2830Sstevel@tonic-gate case 2: 2840Sstevel@tonic-gate rnumber = 4; 2850Sstevel@tonic-gate break; 2860Sstevel@tonic-gate default: 2870Sstevel@tonic-gate PDBG(("pciide_ctlops invalid rnumber\n")); 2880Sstevel@tonic-gate return (DDI_FAILURE); 2890Sstevel@tonic-gate } 2900Sstevel@tonic-gate 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate if (PCIIDE_PRE26(dip)) { 2930Sstevel@tonic-gate int old_rnumber; 2940Sstevel@tonic-gate int new_rnumber; 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate old_rnumber = rnumber; 2970Sstevel@tonic-gate new_rnumber 2980Sstevel@tonic-gate = pciide_pre26_rnumber_map(dip, old_rnumber); 2990Sstevel@tonic-gate PDBG(("pciide rnumber old %d new %d\n", 3000Sstevel@tonic-gate old_rnumber, new_rnumber)); 3010Sstevel@tonic-gate rnumber = new_rnumber; 3020Sstevel@tonic-gate } 3030Sstevel@tonic-gate 3040Sstevel@tonic-gate /* 3050Sstevel@tonic-gate * Add 1 to skip over the PCI config space tuple 3060Sstevel@tonic-gate */ 3070Sstevel@tonic-gate rnumber++; 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate /* 3100Sstevel@tonic-gate * If it's not tuple #2 pass the adjusted request to my parent 3110Sstevel@tonic-gate */ 3120Sstevel@tonic-gate if (*(int *)arg != 2) { 3130Sstevel@tonic-gate return (ddi_ctlops(dip, dip, ctlop, &rnumber, result)); 3140Sstevel@tonic-gate } 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate /* 3170Sstevel@tonic-gate * Handle my child's reg-tuple #2 here by splitting my 16 byte 3180Sstevel@tonic-gate * reg-tuple #4 into two 8 byte ranges based on the 3190Sstevel@tonic-gate * the child's controller #. 3200Sstevel@tonic-gate */ 3210Sstevel@tonic-gate 3220Sstevel@tonic-gate tmp = 8; 3230Sstevel@tonic-gate rc = ddi_ctlops(dip, dip, ctlop, &rnumber, &tmp); 3240Sstevel@tonic-gate 3250Sstevel@tonic-gate /* 3260Sstevel@tonic-gate * Allow for the possibility of less than 16 bytes by 3270Sstevel@tonic-gate * by checking what's actually returned for my reg-tuple #4. 3280Sstevel@tonic-gate */ 3290Sstevel@tonic-gate if (controller == 1) { 3300Sstevel@tonic-gate if (tmp < 8) 3310Sstevel@tonic-gate tmp = 0; 3320Sstevel@tonic-gate else 3330Sstevel@tonic-gate tmp -= 8; 3340Sstevel@tonic-gate } 3350Sstevel@tonic-gate if (tmp > 8) 3360Sstevel@tonic-gate tmp = 8; 3370Sstevel@tonic-gate *(off_t *)result = tmp; 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate return (rc); 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate default: 3420Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * IEEE 1275 Working Group Proposal #414 says that the Primary 3480Sstevel@tonic-gate * controller is "ata@0" and the Secondary controller "ata@1". 3490Sstevel@tonic-gate * 3500Sstevel@tonic-gate * By the time we get here, boot Bootconf (2.6+) has created devinfo 3510Sstevel@tonic-gate * nodes with the appropriate "reg", "assigned-addresses" and "interrupts" 3520Sstevel@tonic-gate * properites on the pci-ide node and both ide child nodes. 3530Sstevel@tonic-gate * 3540Sstevel@tonic-gate * In compatibility mode the "reg" and "assigned-addresses" properties 3550Sstevel@tonic-gate * of the pci-ide node are set up like this: 3560Sstevel@tonic-gate * 3570Sstevel@tonic-gate * 1. PCI-IDE Nexus 3580Sstevel@tonic-gate * 3590Sstevel@tonic-gate * interrupts=0 3600Sstevel@tonic-gate * (addr-hi addr-mid addr-low size-hi size-low) 3610Sstevel@tonic-gate * reg= assigned-addresses=00000000.00000000.00000000.00000000.00000000 3620Sstevel@tonic-gate * 81000000.00000000.000001f0.00000000.00000008 3630Sstevel@tonic-gate * 81000000.00000000.000003f4.00000000.00000004 3640Sstevel@tonic-gate * 81000000.00000000,00000170.00000000.00000008 3650Sstevel@tonic-gate * 81000000.00000000,00000374.00000000.00000004 3660Sstevel@tonic-gate * 01000020.00000000,-[BAR4]-.00000000.00000010 3670Sstevel@tonic-gate * 3680Sstevel@tonic-gate * In native PCI mode the "reg" and "assigned-addresses" properties 3690Sstevel@tonic-gate * would be set up like this: 3700Sstevel@tonic-gate * 3710Sstevel@tonic-gate * 2. PCI-IDE Nexus 3720Sstevel@tonic-gate * 3730Sstevel@tonic-gate * interrupts=0 3740Sstevel@tonic-gate * reg= assigned-addresses=00000000.00000000.00000000.00000000.00000000 3750Sstevel@tonic-gate * 01000010.00000000.-[BAR0]-.00000000.00000008 3760Sstevel@tonic-gate * 01000014,00000000.-[BAR1]-.00000000.00000004 3770Sstevel@tonic-gate * 01000018.00000000.-[BAR2]-.00000000.00000008 3780Sstevel@tonic-gate * 0100001c.00000000.-[BAR3]-.00000000.00000004 3790Sstevel@tonic-gate * 01000020.00000000.-[BAR4]-.00000000.00000010 3800Sstevel@tonic-gate * 3810Sstevel@tonic-gate * 3820Sstevel@tonic-gate * In both modes the child nodes simply have the following: 3830Sstevel@tonic-gate * 3840Sstevel@tonic-gate * 2. primary controller (compatibility mode) 3850Sstevel@tonic-gate * 3860Sstevel@tonic-gate * interrupts=14 3870Sstevel@tonic-gate * reg=00000000 3880Sstevel@tonic-gate * 3890Sstevel@tonic-gate * 3. secondary controller 3900Sstevel@tonic-gate * 3910Sstevel@tonic-gate * interrupts=15 3920Sstevel@tonic-gate * reg=00000001 3930Sstevel@tonic-gate * 3940Sstevel@tonic-gate * The pciide_bus_map() function is responsible for turning requests 3950Sstevel@tonic-gate * to map primary or secondary controller rnumbers into mapping requests 3960Sstevel@tonic-gate * of the appropriate regspec on the pci-ide node. 3970Sstevel@tonic-gate * 3980Sstevel@tonic-gate */ 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate static int 4010Sstevel@tonic-gate pciide_initchild(dev_info_t *mydip, dev_info_t *cdip) 4020Sstevel@tonic-gate { 4030Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 4040Sstevel@tonic-gate struct intrspec *ispecp; 4050Sstevel@tonic-gate int vec; 4060Sstevel@tonic-gate int *rp; 4070Sstevel@tonic-gate uint_t proplen; 4080Sstevel@tonic-gate char name[80]; 4090Sstevel@tonic-gate int dev; 4100Sstevel@tonic-gate 4110Sstevel@tonic-gate PDBG(("pciide_initchild\n")); 4120Sstevel@tonic-gate 4130Sstevel@tonic-gate /* 4140Sstevel@tonic-gate * Set the address portion of the node name based on 4150Sstevel@tonic-gate * the controller number (0 or 1) from the 'reg' property. 4160Sstevel@tonic-gate */ 4170Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 4180Sstevel@tonic-gate "reg", &rp, (uint_t *)&proplen) != DDI_PROP_SUCCESS) { 4190Sstevel@tonic-gate PDBG(("pciide_intchild prop error\n")); 4200Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 4210Sstevel@tonic-gate } 4220Sstevel@tonic-gate 4230Sstevel@tonic-gate /* 4240Sstevel@tonic-gate * copy the controller number and 4250Sstevel@tonic-gate * free the memory allocated by ddi_prop_lookup_int_array 4260Sstevel@tonic-gate */ 4270Sstevel@tonic-gate dev = *rp; 4280Sstevel@tonic-gate ddi_prop_free(rp); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate /* 4310Sstevel@tonic-gate * I only support two controllers per device, determine 4320Sstevel@tonic-gate * which this one is and set its unit address. 4330Sstevel@tonic-gate */ 4340Sstevel@tonic-gate if (dev > 1) { 4350Sstevel@tonic-gate PDBG(("pciide_initchild bad dev\n")); 4360Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 4370Sstevel@tonic-gate } 4380Sstevel@tonic-gate (void) sprintf(name, "%d", dev); 4390Sstevel@tonic-gate ddi_set_name_addr(cdip, name); 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate /* 4420Sstevel@tonic-gate * determine if this instance is running in native or compat mode 4430Sstevel@tonic-gate */ 4440Sstevel@tonic-gate pciide_compat_setup(mydip, cdip, dev); 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate /* interrupts property is required */ 4470Sstevel@tonic-gate if (PCIIDE_NATIVE_MODE(cdip)) { 4480Sstevel@tonic-gate vec = 1; 4490Sstevel@tonic-gate } else { 4500Sstevel@tonic-gate /* 4510Sstevel@tonic-gate * In compatibility mode, dev 0 should always be 4520Sstevel@tonic-gate * IRQ 14 and dev 1 is IRQ 15. If for some reason 4530Sstevel@tonic-gate * this needs to be changed, do it via the interrupts 4540Sstevel@tonic-gate * property in the ata.conf file. 4550Sstevel@tonic-gate */ 4560Sstevel@tonic-gate vec = ddi_prop_get_int(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 4570Sstevel@tonic-gate "interrupts", -1); 4580Sstevel@tonic-gate if (vec == -1) { 4590Sstevel@tonic-gate /* setup compatibility mode interrupts */ 4600Sstevel@tonic-gate if (dev == 0) { 4610Sstevel@tonic-gate vec = 14; 4620Sstevel@tonic-gate } else if (dev == 1) { 4630Sstevel@tonic-gate vec = 15; 4640Sstevel@tonic-gate } else { 4650Sstevel@tonic-gate PDBG(("pciide_initchild bad intr\n")); 4660Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 4670Sstevel@tonic-gate } 4680Sstevel@tonic-gate } 4690Sstevel@tonic-gate } 4700Sstevel@tonic-gate 471430Smrj pdptr = kmem_zalloc(PCIIDE_PDSIZE, KM_SLEEP); 4720Sstevel@tonic-gate ispecp = (struct intrspec *)(pdptr + 1); 4730Sstevel@tonic-gate pdptr->par_nintr = 1; 4740Sstevel@tonic-gate pdptr->par_intr = ispecp; 4750Sstevel@tonic-gate ispecp->intrspec_vec = vec; 4760Sstevel@tonic-gate ddi_set_parent_data(cdip, pdptr); 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate PDBG(("pciide_initchild okay\n")); 4790Sstevel@tonic-gate return (DDI_SUCCESS); 4800Sstevel@tonic-gate } 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate static int 4830Sstevel@tonic-gate pciide_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 4840Sstevel@tonic-gate off_t offset, off_t len, caddr_t *vaddrp) 4850Sstevel@tonic-gate { 4860Sstevel@tonic-gate dev_info_t *pdip; 4870Sstevel@tonic-gate int rnumber = mp->map_obj.rnumber; 4880Sstevel@tonic-gate int controller; 4890Sstevel@tonic-gate int rc; 4900Sstevel@tonic-gate 4910Sstevel@tonic-gate PDBG(("pciide_bus_map\n")); 4920Sstevel@tonic-gate 4930Sstevel@tonic-gate if (strcmp("0", ddi_get_name_addr(rdip)) == 0) 4940Sstevel@tonic-gate controller = 0; 4950Sstevel@tonic-gate else 4960Sstevel@tonic-gate controller = 1; 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate /* 4990Sstevel@tonic-gate * Adjust the rnumbers based on which controller instance 5000Sstevel@tonic-gate * is being mapped; adjust for the 2 tuples per controller. 5010Sstevel@tonic-gate */ 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate switch (rnumber) { 5040Sstevel@tonic-gate case 0: 5050Sstevel@tonic-gate case 1: 5060Sstevel@tonic-gate mp->map_obj.rnumber += (controller * 2); 5070Sstevel@tonic-gate break; 5080Sstevel@tonic-gate case 2: 5090Sstevel@tonic-gate /* 5100Sstevel@tonic-gate * split the 16 I/O ports into two 8 port ranges 5110Sstevel@tonic-gate */ 5120Sstevel@tonic-gate mp->map_obj.rnumber = 4; 5130Sstevel@tonic-gate if (offset + len > 8) { 5140Sstevel@tonic-gate PDBG(("pciide_bus_map offset\n")); 5150Sstevel@tonic-gate return (DDI_FAILURE); 5160Sstevel@tonic-gate } 5170Sstevel@tonic-gate if (len == 0) 5180Sstevel@tonic-gate len = 8 - offset; 5190Sstevel@tonic-gate offset += 8 * controller; 5200Sstevel@tonic-gate break; 5210Sstevel@tonic-gate default: 5220Sstevel@tonic-gate PDBG(("pciide_bus_map default\n")); 5230Sstevel@tonic-gate return (DDI_FAILURE); 5240Sstevel@tonic-gate } 5250Sstevel@tonic-gate 5260Sstevel@tonic-gate if (PCIIDE_PRE26(dip)) { 5270Sstevel@tonic-gate int old_rnumber; 5280Sstevel@tonic-gate int new_rnumber; 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate old_rnumber = mp->map_obj.rnumber; 5310Sstevel@tonic-gate new_rnumber = pciide_pre26_rnumber_map(dip, old_rnumber); 5320Sstevel@tonic-gate PDBG(("pciide rnumber old %d new %d\n", 5330Sstevel@tonic-gate old_rnumber, new_rnumber)); 5340Sstevel@tonic-gate mp->map_obj.rnumber = new_rnumber; 5350Sstevel@tonic-gate } 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate /* 5380Sstevel@tonic-gate * Add 1 to skip over the PCI config space tuple 5390Sstevel@tonic-gate */ 5400Sstevel@tonic-gate mp->map_obj.rnumber++; 5410Sstevel@tonic-gate 5420Sstevel@tonic-gate 5430Sstevel@tonic-gate /* 5440Sstevel@tonic-gate * pass the adjusted request to my parent 5450Sstevel@tonic-gate */ 5460Sstevel@tonic-gate pdip = ddi_get_parent(dip); 5470Sstevel@tonic-gate rc = ((*(DEVI(pdip)->devi_ops->devo_bus_ops->bus_map)) 5480Sstevel@tonic-gate (pdip, dip, mp, offset, len, vaddrp)); 5490Sstevel@tonic-gate 5500Sstevel@tonic-gate PDBG(("pciide_bus_map %s\n", rc == DDI_SUCCESS ? "okay" : "!ok")); 5510Sstevel@tonic-gate 5520Sstevel@tonic-gate return (rc); 5530Sstevel@tonic-gate } 5540Sstevel@tonic-gate 5550Sstevel@tonic-gate 5560Sstevel@tonic-gate static struct intrspec * 5570Sstevel@tonic-gate pciide_get_ispec(dev_info_t *dip, dev_info_t *rdip, int inumber) 5580Sstevel@tonic-gate { 5590Sstevel@tonic-gate struct ddi_parent_private_data *ppdptr; 5600Sstevel@tonic-gate 5610Sstevel@tonic-gate PDBG(("pciide_get_ispec\n")); 5620Sstevel@tonic-gate 5630Sstevel@tonic-gate /* 5640Sstevel@tonic-gate * Native mode PCI-IDE controllers share the parent's 5650Sstevel@tonic-gate * PCI interrupt line. 5660Sstevel@tonic-gate * 5670Sstevel@tonic-gate * Compatibility mode PCI-IDE controllers have their 5680Sstevel@tonic-gate * own intrspec which specifies ISA IRQ 14 or 15. 5690Sstevel@tonic-gate * 5700Sstevel@tonic-gate */ 5710Sstevel@tonic-gate if (PCIIDE_NATIVE_MODE(rdip)) { 5720Sstevel@tonic-gate ddi_intrspec_t is; 5730Sstevel@tonic-gate 5740Sstevel@tonic-gate is = pci_intx_get_ispec(dip, dip, inumber); 5750Sstevel@tonic-gate PDBG(("pciide_get_ispec okay\n")); 5760Sstevel@tonic-gate return ((struct intrspec *)is); 5770Sstevel@tonic-gate } 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate /* Else compatibility mode, use the ISA IRQ */ 5800Sstevel@tonic-gate if ((ppdptr = ddi_get_parent_data(rdip)) == NULL) { 5810Sstevel@tonic-gate PDBG(("pciide_get_ispec null\n")); 5820Sstevel@tonic-gate return (NULL); 5830Sstevel@tonic-gate } 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate /* validate the interrupt number */ 5860Sstevel@tonic-gate if (inumber >= ppdptr->par_nintr) { 5870Sstevel@tonic-gate PDBG(("pciide_get_inum\n")); 5880Sstevel@tonic-gate return (NULL); 5890Sstevel@tonic-gate } 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate PDBG(("pciide_get_ispec ok\n")); 5920Sstevel@tonic-gate 5930Sstevel@tonic-gate return ((struct intrspec *)&ppdptr->par_intr[inumber]); 5940Sstevel@tonic-gate } 5950Sstevel@tonic-gate 5960Sstevel@tonic-gate static int 5970Sstevel@tonic-gate pciide_get_pri(dev_info_t *dip, dev_info_t *rdip, 5980Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, int *pri) 5990Sstevel@tonic-gate { 6000Sstevel@tonic-gate struct intrspec *ispecp; 6010Sstevel@tonic-gate int *intpriorities; 6020Sstevel@tonic-gate uint_t num_intpriorities; 6030Sstevel@tonic-gate 6040Sstevel@tonic-gate PDBG(("pciide_get_pri\n")); 6050Sstevel@tonic-gate 6060Sstevel@tonic-gate if ((ispecp = pciide_get_ispec(dip, rdip, hdlp->ih_inum)) == NULL) { 6070Sstevel@tonic-gate PDBG(("pciide_get_pri null\n")); 6080Sstevel@tonic-gate return (DDI_FAILURE); 6090Sstevel@tonic-gate } 6100Sstevel@tonic-gate 6110Sstevel@tonic-gate if (PCIIDE_NATIVE_MODE(rdip)) { 6120Sstevel@tonic-gate *pri = ispecp->intrspec_pri; 6130Sstevel@tonic-gate PDBG(("pciide_get_pri ok\n")); 6140Sstevel@tonic-gate return (DDI_SUCCESS); 6150Sstevel@tonic-gate } 6160Sstevel@tonic-gate 6170Sstevel@tonic-gate /* check if the intrspec has been initialized */ 6180Sstevel@tonic-gate if (ispecp->intrspec_pri != 0) { 6190Sstevel@tonic-gate *pri = ispecp->intrspec_pri; 6200Sstevel@tonic-gate PDBG(("pciide_get_pri ok2\n")); 6210Sstevel@tonic-gate return (DDI_SUCCESS); 6220Sstevel@tonic-gate } 6230Sstevel@tonic-gate 6240Sstevel@tonic-gate /* Use a default of level 5 */ 6250Sstevel@tonic-gate ispecp->intrspec_pri = 5; 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate /* 6280Sstevel@tonic-gate * If there's an interrupt-priorities property, use it to 6290Sstevel@tonic-gate * over-ride the default interrupt priority. 6300Sstevel@tonic-gate */ 6310Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS, 6320Sstevel@tonic-gate "interrupt-priorities", &intpriorities, &num_intpriorities) == 6330Sstevel@tonic-gate DDI_PROP_SUCCESS) { 6340Sstevel@tonic-gate if (hdlp->ih_inum < num_intpriorities) 6350Sstevel@tonic-gate ispecp->intrspec_pri = intpriorities[hdlp->ih_inum]; 6360Sstevel@tonic-gate ddi_prop_free(intpriorities); 6370Sstevel@tonic-gate } 6380Sstevel@tonic-gate *pri = ispecp->intrspec_pri; 6390Sstevel@tonic-gate 6400Sstevel@tonic-gate PDBG(("pciide_get_pri ok3\n")); 6410Sstevel@tonic-gate 6420Sstevel@tonic-gate return (DDI_SUCCESS); 6430Sstevel@tonic-gate } 6440Sstevel@tonic-gate 6450Sstevel@tonic-gate static int 6460Sstevel@tonic-gate pciide_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 6470Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 6480Sstevel@tonic-gate { 6490Sstevel@tonic-gate struct ddi_parent_private_data *ppdptr; 6500Sstevel@tonic-gate struct intrspec *ispecp; 6510Sstevel@tonic-gate int rc; 6520Sstevel@tonic-gate int pri = 0; 6530Sstevel@tonic-gate 6540Sstevel@tonic-gate PDBG(("pciide_intr_ops: dip %p rdip %p op %x hdlp %p\n", 6550Sstevel@tonic-gate (void *)dip, (void *)rdip, intr_op, (void *)hdlp)); 6560Sstevel@tonic-gate 6570Sstevel@tonic-gate switch (intr_op) { 6580Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES: 6590Sstevel@tonic-gate *(int *)result = DDI_INTR_TYPE_FIXED; 6600Sstevel@tonic-gate break; 6610Sstevel@tonic-gate case DDI_INTROP_GETCAP: 6620Sstevel@tonic-gate if (i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result) 6630Sstevel@tonic-gate == DDI_FAILURE) 6640Sstevel@tonic-gate *(int *)result = 0; 6650Sstevel@tonic-gate break; 6660Sstevel@tonic-gate case DDI_INTROP_NINTRS: 6670Sstevel@tonic-gate if (!PCIIDE_NATIVE_MODE(rdip)) { 6680Sstevel@tonic-gate if ((ppdptr = ddi_get_parent_data(rdip)) == NULL) { 6690Sstevel@tonic-gate *(int *)result = 0; 6700Sstevel@tonic-gate return (DDI_FAILURE); 6710Sstevel@tonic-gate } 6720Sstevel@tonic-gate *(int *)result = ppdptr->par_nintr; 6730Sstevel@tonic-gate } else 6740Sstevel@tonic-gate *(int *)result = 1; 6750Sstevel@tonic-gate break; 6760Sstevel@tonic-gate case DDI_INTROP_ALLOC: 6770Sstevel@tonic-gate if ((ispecp = pciide_get_ispec(dip, rdip, hdlp->ih_inum)) == 6780Sstevel@tonic-gate NULL) 6790Sstevel@tonic-gate return (DDI_FAILURE); 6800Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 6810Sstevel@tonic-gate hdlp->ih_private = (void *)ispecp; 6820Sstevel@tonic-gate break; 6830Sstevel@tonic-gate case DDI_INTROP_FREE: 6840Sstevel@tonic-gate hdlp->ih_private = NULL; 6850Sstevel@tonic-gate break; 6860Sstevel@tonic-gate case DDI_INTROP_GETPRI: 6870Sstevel@tonic-gate if (pciide_get_pri(dip, rdip, hdlp, &pri) != DDI_SUCCESS) { 6880Sstevel@tonic-gate *(int *)result = 0; 6890Sstevel@tonic-gate return (DDI_FAILURE); 6900Sstevel@tonic-gate } 6910Sstevel@tonic-gate *(int *)result = pri; 6920Sstevel@tonic-gate break; 6930Sstevel@tonic-gate case DDI_INTROP_ADDISR: 6940Sstevel@tonic-gate if ((ispecp = pciide_get_ispec(dip, rdip, hdlp->ih_inum)) == 6950Sstevel@tonic-gate NULL) 6960Sstevel@tonic-gate return (DDI_FAILURE); 6970Sstevel@tonic-gate hdlp->ih_private = (void *)ispecp; 6980Sstevel@tonic-gate ispecp->intrspec_func = hdlp->ih_cb_func; 6990Sstevel@tonic-gate break; 7000Sstevel@tonic-gate case DDI_INTROP_REMISR: 7010Sstevel@tonic-gate if ((ispecp = pciide_get_ispec(dip, rdip, hdlp->ih_inum)) == 7020Sstevel@tonic-gate NULL) 7030Sstevel@tonic-gate return (DDI_FAILURE); 7040Sstevel@tonic-gate ispecp->intrspec_func = (uint_t (*)()) 0; 7050Sstevel@tonic-gate break; 7060Sstevel@tonic-gate case DDI_INTROP_ENABLE: 7070Sstevel@tonic-gate /* FALLTHRU */ 7080Sstevel@tonic-gate case DDI_INTROP_DISABLE: 7090Sstevel@tonic-gate if (PCIIDE_NATIVE_MODE(rdip)) { 7100Sstevel@tonic-gate rdip = dip; 7110Sstevel@tonic-gate dip = ddi_get_parent(dip); 7120Sstevel@tonic-gate } else { /* get ptr to the root node */ 7130Sstevel@tonic-gate dip = ddi_root_node(); 7140Sstevel@tonic-gate } 7150Sstevel@tonic-gate 7160Sstevel@tonic-gate rc = (*(DEVI(dip)->devi_ops->devo_bus_ops->bus_intr_op))(dip, 7170Sstevel@tonic-gate rdip, intr_op, hdlp, result); 7180Sstevel@tonic-gate 7190Sstevel@tonic-gate #ifdef DEBUG 7200Sstevel@tonic-gate if (intr_op == DDI_INTROP_ENABLE) { 7210Sstevel@tonic-gate PDBG(("pciide_enable rc=%d", rc)); 7220Sstevel@tonic-gate } else 7230Sstevel@tonic-gate PDBG(("pciide_disable rc=%d", rc)); 7240Sstevel@tonic-gate #endif /* DEBUG */ 7250Sstevel@tonic-gate return (rc); 7260Sstevel@tonic-gate case DDI_INTROP_NAVAIL: 7270Sstevel@tonic-gate *(int *)result = 1; 7280Sstevel@tonic-gate break; 7290Sstevel@tonic-gate default: 7300Sstevel@tonic-gate return (DDI_FAILURE); 7310Sstevel@tonic-gate } 7320Sstevel@tonic-gate 7330Sstevel@tonic-gate return (DDI_SUCCESS); 7340Sstevel@tonic-gate } 7350Sstevel@tonic-gate 7360Sstevel@tonic-gate /* 7370Sstevel@tonic-gate * This is one of the places where controller specific setup needs to be 7380Sstevel@tonic-gate * considered. 7390Sstevel@tonic-gate * At this point the controller was already pre-qualified as a known and 7400Sstevel@tonic-gate * supported pciide controller. 7410Sstevel@tonic-gate * Some controllers do not provide PCI_MASS_IDE sub-class code and IDE 7420Sstevel@tonic-gate * programming interface code but rather PCI_MASS_OTHER sub-class code 7430Sstevel@tonic-gate * without any additional data. 7440Sstevel@tonic-gate * For those controllers IDE programming interface cannot be extracted 7450Sstevel@tonic-gate * from PCI class - we assume that they are pci-native type and we fix 7460Sstevel@tonic-gate * the programming interface used by other functions. 7470Sstevel@tonic-gate * The programming interface byte is set to indicate pci-native mode 7480Sstevel@tonic-gate * for both controllers and the Bus Master DMA capabilitiy of the controller. 7490Sstevel@tonic-gate */ 7500Sstevel@tonic-gate static void 7510Sstevel@tonic-gate pciide_compat_setup(dev_info_t *mydip, dev_info_t *cdip, int dev) 7520Sstevel@tonic-gate { 7530Sstevel@tonic-gate int class_code; 7540Sstevel@tonic-gate int rc = DDI_PROP_SUCCESS; 7550Sstevel@tonic-gate 7560Sstevel@tonic-gate class_code = ddi_prop_get_int(DDI_DEV_T_ANY, mydip, 7570Sstevel@tonic-gate DDI_PROP_DONTPASS, "class-code", 0); 7580Sstevel@tonic-gate 7590Sstevel@tonic-gate if (((class_code & 0x00FF00) >> 8) == PCI_MASS_IDE) { 7600Sstevel@tonic-gate /* 7610Sstevel@tonic-gate * Controller provides PCI_MASS_IDE sub-class code first 7620Sstevel@tonic-gate * (implied IDE programming interface) 7630Sstevel@tonic-gate */ 7640Sstevel@tonic-gate if ((dev == 0 && !(class_code & PCI_IDE_IF_NATIVE_PRI)) || 7650Sstevel@tonic-gate (dev == 1 && !(class_code & PCI_IDE_IF_NATIVE_SEC))) { 7660Sstevel@tonic-gate rc = ddi_prop_update_int(DDI_DEV_T_NONE, cdip, 7670Sstevel@tonic-gate "compatibility-mode", 1); 7680Sstevel@tonic-gate if (rc != DDI_PROP_SUCCESS) 7690Sstevel@tonic-gate cmn_err(CE_WARN, 7700Sstevel@tonic-gate "pciide prop error %d compat-mode", rc); 7710Sstevel@tonic-gate } 7720Sstevel@tonic-gate } else { 7730Sstevel@tonic-gate /* 7740Sstevel@tonic-gate * Pci-ide controllers not providing PCI_MASS_IDE sub-class are 7750Sstevel@tonic-gate * assumed to be of pci-native type and bus master DMA capable. 7760Sstevel@tonic-gate * Programming interface part of the class-code property is 7770Sstevel@tonic-gate * fixed here. 7780Sstevel@tonic-gate */ 7790Sstevel@tonic-gate class_code &= 0x00ffff00; 7800Sstevel@tonic-gate class_code |= PCI_IDE_IF_BM_CAP_MASK | 7810Sstevel@tonic-gate PCI_IDE_IF_NATIVE_PRI | PCI_IDE_IF_NATIVE_SEC; 7820Sstevel@tonic-gate rc = ddi_prop_update_int(DDI_DEV_T_NONE, mydip, 7830Sstevel@tonic-gate "class-code", class_code); 7840Sstevel@tonic-gate if (rc != DDI_PROP_SUCCESS) 7850Sstevel@tonic-gate cmn_err(CE_WARN, 7860Sstevel@tonic-gate "pciide prop error %d class-code", rc); 7870Sstevel@tonic-gate } 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate 7910Sstevel@tonic-gate static int 7920Sstevel@tonic-gate pciide_pre26_rnumber_map(dev_info_t *mydip, int rnumber) 7930Sstevel@tonic-gate { 7940Sstevel@tonic-gate int pri_native; 7950Sstevel@tonic-gate int sec_native; 7960Sstevel@tonic-gate int class_code; 7970Sstevel@tonic-gate 7980Sstevel@tonic-gate class_code = ddi_prop_get_int(DDI_DEV_T_ANY, mydip, DDI_PROP_DONTPASS, 7990Sstevel@tonic-gate "class-code", 0); 8000Sstevel@tonic-gate 8010Sstevel@tonic-gate pri_native = (class_code & PCI_IDE_IF_NATIVE_PRI) ? TRUE : FALSE; 8020Sstevel@tonic-gate sec_native = (class_code & PCI_IDE_IF_NATIVE_SEC) ? TRUE : FALSE; 8030Sstevel@tonic-gate 8040Sstevel@tonic-gate return (pciide_map_rnumber(rnumber, pri_native, sec_native)); 8050Sstevel@tonic-gate 8060Sstevel@tonic-gate } 8070Sstevel@tonic-gate 8080Sstevel@tonic-gate /* 8090Sstevel@tonic-gate * The canonical order of the reg property tuples for the 8100Sstevel@tonic-gate * Base Address Registers is supposed to be: 8110Sstevel@tonic-gate * 8120Sstevel@tonic-gate * primary controller (BAR 0) 8130Sstevel@tonic-gate * primary controller (BAR 1) 8140Sstevel@tonic-gate * secondary controller (BAR 2) 8150Sstevel@tonic-gate * secondary controller (BAR 3) 8160Sstevel@tonic-gate * bus mastering regs (BAR 4) 8170Sstevel@tonic-gate * 8180Sstevel@tonic-gate * For 2.6, bootconf has been fixed to always generate the 8190Sstevel@tonic-gate * reg property (and assigned-addresses property) tuples 8200Sstevel@tonic-gate * in the above order. 8210Sstevel@tonic-gate * 8220Sstevel@tonic-gate * But in releases prior to 2.6 the order varies depending 8230Sstevel@tonic-gate * on whether compatibility or native mode is being used for 8240Sstevel@tonic-gate * each controller. There ends up being four possible 8250Sstevel@tonic-gate * orders: 8260Sstevel@tonic-gate * 8270Sstevel@tonic-gate * BM, P0, P1, S0, S1 primary compatible, secondary compatible 8280Sstevel@tonic-gate * S0, S1, BM, P0, P1 primary compatible, secondary native 8290Sstevel@tonic-gate * P0, P1, BM, S0, S1 primary native, secondary compatible 8300Sstevel@tonic-gate * P0, P1, S0, S1, BM primary native, secondary native 8310Sstevel@tonic-gate * 8320Sstevel@tonic-gate * where: Px is the primary tuples, Sx the secondary tuples, and 8330Sstevel@tonic-gate * B the Bus Master tuple. 8340Sstevel@tonic-gate * 8350Sstevel@tonic-gate * Here's the results for each of the four states: 8360Sstevel@tonic-gate * 8370Sstevel@tonic-gate * 0, 1, 2, 3, 4 8380Sstevel@tonic-gate * 8390Sstevel@tonic-gate * CC 1, 2, 3, 4, 0 8400Sstevel@tonic-gate * CN 3, 4, 0, 1, 2 8410Sstevel@tonic-gate * NC 0, 1, 3, 4, 2 8420Sstevel@tonic-gate * NN 0, 1, 2, 3, 4 8430Sstevel@tonic-gate * 8440Sstevel@tonic-gate * C = compatible(!native) == 0 8450Sstevel@tonic-gate * N = native == 1 8460Sstevel@tonic-gate * 8470Sstevel@tonic-gate * Here's the transformation matrix: 8480Sstevel@tonic-gate */ 8490Sstevel@tonic-gate 8500Sstevel@tonic-gate static int pciide_transform[2][2][5] = { 8510Sstevel@tonic-gate /* P S */ 8520Sstevel@tonic-gate /* [C][C] */ +1, +1, +1, +1, -4, 8530Sstevel@tonic-gate /* [C][N] */ +3, +3, -2, -2, -2, 8540Sstevel@tonic-gate /* [N][C] */ +0, +0, +1, +1, -2, 8550Sstevel@tonic-gate /* [N][N] */ +0, +0, +0, +0, +0 8560Sstevel@tonic-gate }; 8570Sstevel@tonic-gate 8580Sstevel@tonic-gate 8590Sstevel@tonic-gate static int 8600Sstevel@tonic-gate pciide_map_rnumber(int rnumber, int pri_native, int sec_native) 8610Sstevel@tonic-gate { 8620Sstevel@tonic-gate /* transform flags into indexes */ 8630Sstevel@tonic-gate pri_native = pri_native ? 1 : 0; 8640Sstevel@tonic-gate sec_native = sec_native ? 1 : 0; 8650Sstevel@tonic-gate 8660Sstevel@tonic-gate rnumber += pciide_transform[pri_native][sec_native][rnumber]; 8670Sstevel@tonic-gate return (rnumber); 8680Sstevel@tonic-gate } 869