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 52580Sanish * Common Development and Distribution License (the "License"). 62580Sanish * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*7656SSherry.Moore@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate 270Sstevel@tonic-gate /* 280Sstevel@tonic-gate * PCI-IDE bus nexus driver 290Sstevel@tonic-gate */ 300Sstevel@tonic-gate 310Sstevel@tonic-gate #include <sys/types.h> 320Sstevel@tonic-gate #include <sys/cmn_err.h> 330Sstevel@tonic-gate #include <sys/conf.h> 340Sstevel@tonic-gate #include <sys/errno.h> 350Sstevel@tonic-gate #include <sys/debug.h> 360Sstevel@tonic-gate #include <sys/ddidmareq.h> 370Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 380Sstevel@tonic-gate #include <sys/dma_engine.h> 390Sstevel@tonic-gate #include <sys/modctl.h> 400Sstevel@tonic-gate #include <sys/ddi.h> 410Sstevel@tonic-gate #include <sys/sunddi.h> 42916Sschwartz #include <sys/mach_intr.h> 430Sstevel@tonic-gate #include <sys/kmem.h> 440Sstevel@tonic-gate #include <sys/pci.h> 450Sstevel@tonic-gate #include <sys/promif.h> 460Sstevel@tonic-gate #include <sys/pci_intr_lib.h> 470Sstevel@tonic-gate 480Sstevel@tonic-gate int pciide_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 495295Srandyf int pciide_detach(dev_info_t *dip, ddi_detach_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 */ 1575295Srandyf pciide_detach, /* detach */ 1580Sstevel@tonic-gate nodev, /* reset */ 1590Sstevel@tonic-gate (struct cb_ops *)0, /* driver operations */ 160*7656SSherry.Moore@Sun.COM &pciide_bus_ops, /* bus operations */ 161*7656SSherry.Moore@Sun.COM NULL, /* power */ 162*7656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */ 1630Sstevel@tonic-gate }; 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate /* 1660Sstevel@tonic-gate * Module linkage information for the kernel. 1670Sstevel@tonic-gate */ 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate static struct modldrv modldrv = { 1700Sstevel@tonic-gate &mod_driverops, /* Type of module. This is PCI-IDE bus driver */ 171*7656SSherry.Moore@Sun.COM "pciide nexus driver for 'PCI-IDE' 1.26", 1720Sstevel@tonic-gate &pciide_ops, /* driver ops */ 1730Sstevel@tonic-gate }; 1740Sstevel@tonic-gate 1750Sstevel@tonic-gate static struct modlinkage modlinkage = { 1760Sstevel@tonic-gate MODREV_1, 1770Sstevel@tonic-gate &modldrv, 1780Sstevel@tonic-gate NULL 1790Sstevel@tonic-gate }; 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate int 1830Sstevel@tonic-gate _init(void) 1840Sstevel@tonic-gate { 1850Sstevel@tonic-gate return (mod_install(&modlinkage)); 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate int 1890Sstevel@tonic-gate _fini(void) 1900Sstevel@tonic-gate { 1910Sstevel@tonic-gate return (mod_remove(&modlinkage)); 1920Sstevel@tonic-gate } 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate int 1950Sstevel@tonic-gate _info(struct modinfo *modinfop) 1960Sstevel@tonic-gate { 1970Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1980Sstevel@tonic-gate } 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate int 2010Sstevel@tonic-gate pciide_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 2020Sstevel@tonic-gate { 2030Sstevel@tonic-gate uint16_t cmdreg; 2040Sstevel@tonic-gate ddi_acc_handle_t conf_hdl = NULL; 2050Sstevel@tonic-gate int rc; 2060Sstevel@tonic-gate 2075295Srandyf switch (cmd) { 2085295Srandyf case DDI_ATTACH: 2090Sstevel@tonic-gate /* 2100Sstevel@tonic-gate * Make sure bus-mastering is enabled, even if 2110Sstevel@tonic-gate * BIOS didn't. 2120Sstevel@tonic-gate */ 213466Smrj 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 222466Smrj cmdreg = pci_config_get16(conf_hdl, PCI_CONF_COMM); 2230Sstevel@tonic-gate if ((cmdreg & PCI_COMM_ME) == 0) { 224466Smrj pci_config_put16(conf_hdl, PCI_CONF_COMM, 2250Sstevel@tonic-gate cmdreg | PCI_COMM_ME); 2260Sstevel@tonic-gate } 227466Smrj pci_config_teardown(&conf_hdl); 2280Sstevel@tonic-gate return (DDI_SUCCESS); 2295295Srandyf 2305295Srandyf case DDI_RESUME: 2315295Srandyf /* Restore our PCI configuration header */ 2325295Srandyf if (pci_restore_config_regs(dip) != DDI_SUCCESS) { 2335295Srandyf /* 2345295Srandyf * XXXX 2355295Srandyf * This is a pretty bad thing. However, for some 2365295Srandyf * reason it always happens. To further complicate 2375295Srandyf * things, it appears if we just ignore this, we 2385295Srandyf * properly resume. For now, all I want to do is 2395295Srandyf * to generate this message so that it doesn't get 2405295Srandyf * forgotten. 2415295Srandyf */ 2425295Srandyf cmn_err(CE_WARN, 2435295Srandyf "Couldn't restore PCI config regs for %s(%p)", 2445295Srandyf ddi_node_name(dip), (void *) dip); 2455295Srandyf } 2465295Srandyf #ifdef DEBUG 2475295Srandyf /* Bus mastering should still be enabled */ 2485295Srandyf if (pci_config_setup(dip, &conf_hdl) != DDI_SUCCESS) 2495295Srandyf return (DDI_FAILURE); 2505295Srandyf cmdreg = pci_config_get16(conf_hdl, PCI_CONF_COMM); 2515295Srandyf ASSERT((cmdreg & PCI_COMM_ME) != 0); 2525295Srandyf pci_config_teardown(&conf_hdl); 2535295Srandyf #endif 2545295Srandyf return (DDI_SUCCESS); 2550Sstevel@tonic-gate } 2565295Srandyf 2575295Srandyf return (DDI_FAILURE); 2580Sstevel@tonic-gate } 2590Sstevel@tonic-gate 2605295Srandyf /*ARGSUSED*/ 2615295Srandyf int 2625295Srandyf pciide_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 2635295Srandyf { 2645295Srandyf switch (cmd) { 2655295Srandyf case DDI_DETACH: 2665295Srandyf return (DDI_SUCCESS); 2675295Srandyf case DDI_SUSPEND: 2685295Srandyf /* Save our PCI configuration header */ 2695295Srandyf if (pci_save_config_regs(dip) != DDI_SUCCESS) { 2705295Srandyf /* Don't suspend if we cannot save config regs */ 2715295Srandyf return (DDI_FAILURE); 2725295Srandyf } 2735295Srandyf return (DDI_SUCCESS); 2745295Srandyf } 2755295Srandyf return (DDI_FAILURE); 2765295Srandyf } 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate /*ARGSUSED*/ 2790Sstevel@tonic-gate static int 2800Sstevel@tonic-gate pciide_ddi_ctlops(dev_info_t *dip, dev_info_t *rdip, ddi_ctl_enum_t ctlop, 2810Sstevel@tonic-gate void *arg, void *result) 2820Sstevel@tonic-gate { 283430Smrj dev_info_t *cdip; 284430Smrj int controller; 285430Smrj void *pdptr; 286430Smrj int rnumber; 287430Smrj off_t tmp; 288430Smrj int rc; 2890Sstevel@tonic-gate 2900Sstevel@tonic-gate PDBG(("pciide_bus_ctl\n")); 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate switch (ctlop) { 2930Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 294430Smrj cdip = (dev_info_t *)arg; 295430Smrj return (pciide_initchild(dip, cdip)); 2960Sstevel@tonic-gate 2970Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 298430Smrj cdip = (dev_info_t *)arg; 299430Smrj pdptr = ddi_get_parent_data(cdip); 300430Smrj ddi_set_parent_data(cdip, NULL); 301430Smrj ddi_set_name_addr(cdip, NULL); 302430Smrj kmem_free(pdptr, PCIIDE_PDSIZE); 303430Smrj return (DDI_SUCCESS); 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 3060Sstevel@tonic-gate *(int *)result = 3; 3070Sstevel@tonic-gate return (DDI_SUCCESS); 3080Sstevel@tonic-gate 3090Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 3100Sstevel@tonic-gate /* 3110Sstevel@tonic-gate * Adjust the rnumbers based on which controller instance 3120Sstevel@tonic-gate * is requested; adjust for the 2 tuples per controller. 3130Sstevel@tonic-gate */ 3140Sstevel@tonic-gate if (strcmp("0", ddi_get_name_addr(rdip)) == 0) 3150Sstevel@tonic-gate controller = 0; 3160Sstevel@tonic-gate else 3170Sstevel@tonic-gate controller = 1; 3180Sstevel@tonic-gate 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate switch (rnumber = *(int *)arg) { 3210Sstevel@tonic-gate case 0: 3220Sstevel@tonic-gate case 1: 3230Sstevel@tonic-gate rnumber += (2 * controller); 3240Sstevel@tonic-gate break; 3250Sstevel@tonic-gate case 2: 3260Sstevel@tonic-gate rnumber = 4; 3270Sstevel@tonic-gate break; 3280Sstevel@tonic-gate default: 3290Sstevel@tonic-gate PDBG(("pciide_ctlops invalid rnumber\n")); 3300Sstevel@tonic-gate return (DDI_FAILURE); 3310Sstevel@tonic-gate } 3320Sstevel@tonic-gate 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate if (PCIIDE_PRE26(dip)) { 3350Sstevel@tonic-gate int old_rnumber; 3360Sstevel@tonic-gate int new_rnumber; 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate old_rnumber = rnumber; 3390Sstevel@tonic-gate new_rnumber 3405295Srandyf = pciide_pre26_rnumber_map(dip, old_rnumber); 3410Sstevel@tonic-gate PDBG(("pciide rnumber old %d new %d\n", 3425295Srandyf old_rnumber, new_rnumber)); 3430Sstevel@tonic-gate rnumber = new_rnumber; 3440Sstevel@tonic-gate } 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * Add 1 to skip over the PCI config space tuple 3480Sstevel@tonic-gate */ 3490Sstevel@tonic-gate rnumber++; 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate /* 3520Sstevel@tonic-gate * If it's not tuple #2 pass the adjusted request to my parent 3530Sstevel@tonic-gate */ 3540Sstevel@tonic-gate if (*(int *)arg != 2) { 3550Sstevel@tonic-gate return (ddi_ctlops(dip, dip, ctlop, &rnumber, result)); 3560Sstevel@tonic-gate } 3570Sstevel@tonic-gate 3580Sstevel@tonic-gate /* 3590Sstevel@tonic-gate * Handle my child's reg-tuple #2 here by splitting my 16 byte 3600Sstevel@tonic-gate * reg-tuple #4 into two 8 byte ranges based on the 3610Sstevel@tonic-gate * the child's controller #. 3620Sstevel@tonic-gate */ 3630Sstevel@tonic-gate 3640Sstevel@tonic-gate tmp = 8; 3650Sstevel@tonic-gate rc = ddi_ctlops(dip, dip, ctlop, &rnumber, &tmp); 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate /* 3680Sstevel@tonic-gate * Allow for the possibility of less than 16 bytes by 3690Sstevel@tonic-gate * by checking what's actually returned for my reg-tuple #4. 3700Sstevel@tonic-gate */ 3710Sstevel@tonic-gate if (controller == 1) { 3720Sstevel@tonic-gate if (tmp < 8) 3730Sstevel@tonic-gate tmp = 0; 3740Sstevel@tonic-gate else 3750Sstevel@tonic-gate tmp -= 8; 3760Sstevel@tonic-gate } 3770Sstevel@tonic-gate if (tmp > 8) 3780Sstevel@tonic-gate tmp = 8; 3790Sstevel@tonic-gate *(off_t *)result = tmp; 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate return (rc); 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate default: 3840Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 3850Sstevel@tonic-gate } 3860Sstevel@tonic-gate } 3870Sstevel@tonic-gate 3880Sstevel@tonic-gate /* 3890Sstevel@tonic-gate * IEEE 1275 Working Group Proposal #414 says that the Primary 3900Sstevel@tonic-gate * controller is "ata@0" and the Secondary controller "ata@1". 3910Sstevel@tonic-gate * 3920Sstevel@tonic-gate * By the time we get here, boot Bootconf (2.6+) has created devinfo 3930Sstevel@tonic-gate * nodes with the appropriate "reg", "assigned-addresses" and "interrupts" 3940Sstevel@tonic-gate * properites on the pci-ide node and both ide child nodes. 3950Sstevel@tonic-gate * 3960Sstevel@tonic-gate * In compatibility mode the "reg" and "assigned-addresses" properties 3970Sstevel@tonic-gate * of the pci-ide node are set up like this: 3980Sstevel@tonic-gate * 3990Sstevel@tonic-gate * 1. PCI-IDE Nexus 4000Sstevel@tonic-gate * 4010Sstevel@tonic-gate * interrupts=0 4020Sstevel@tonic-gate * (addr-hi addr-mid addr-low size-hi size-low) 4030Sstevel@tonic-gate * reg= assigned-addresses=00000000.00000000.00000000.00000000.00000000 4040Sstevel@tonic-gate * 81000000.00000000.000001f0.00000000.00000008 4050Sstevel@tonic-gate * 81000000.00000000.000003f4.00000000.00000004 4060Sstevel@tonic-gate * 81000000.00000000,00000170.00000000.00000008 4070Sstevel@tonic-gate * 81000000.00000000,00000374.00000000.00000004 4080Sstevel@tonic-gate * 01000020.00000000,-[BAR4]-.00000000.00000010 4090Sstevel@tonic-gate * 4100Sstevel@tonic-gate * In native PCI mode the "reg" and "assigned-addresses" properties 4110Sstevel@tonic-gate * would be set up like this: 4120Sstevel@tonic-gate * 4130Sstevel@tonic-gate * 2. PCI-IDE Nexus 4140Sstevel@tonic-gate * 4150Sstevel@tonic-gate * interrupts=0 4160Sstevel@tonic-gate * reg= assigned-addresses=00000000.00000000.00000000.00000000.00000000 4170Sstevel@tonic-gate * 01000010.00000000.-[BAR0]-.00000000.00000008 4180Sstevel@tonic-gate * 01000014,00000000.-[BAR1]-.00000000.00000004 4190Sstevel@tonic-gate * 01000018.00000000.-[BAR2]-.00000000.00000008 4200Sstevel@tonic-gate * 0100001c.00000000.-[BAR3]-.00000000.00000004 4210Sstevel@tonic-gate * 01000020.00000000.-[BAR4]-.00000000.00000010 4220Sstevel@tonic-gate * 4230Sstevel@tonic-gate * 4240Sstevel@tonic-gate * In both modes the child nodes simply have the following: 4250Sstevel@tonic-gate * 4260Sstevel@tonic-gate * 2. primary controller (compatibility mode) 4270Sstevel@tonic-gate * 4280Sstevel@tonic-gate * interrupts=14 4290Sstevel@tonic-gate * reg=00000000 4300Sstevel@tonic-gate * 4310Sstevel@tonic-gate * 3. secondary controller 4320Sstevel@tonic-gate * 4330Sstevel@tonic-gate * interrupts=15 4340Sstevel@tonic-gate * reg=00000001 4350Sstevel@tonic-gate * 4360Sstevel@tonic-gate * The pciide_bus_map() function is responsible for turning requests 4370Sstevel@tonic-gate * to map primary or secondary controller rnumbers into mapping requests 4380Sstevel@tonic-gate * of the appropriate regspec on the pci-ide node. 4390Sstevel@tonic-gate * 4400Sstevel@tonic-gate */ 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate static int 4430Sstevel@tonic-gate pciide_initchild(dev_info_t *mydip, dev_info_t *cdip) 4440Sstevel@tonic-gate { 4450Sstevel@tonic-gate struct ddi_parent_private_data *pdptr; 4460Sstevel@tonic-gate struct intrspec *ispecp; 4470Sstevel@tonic-gate int vec; 4480Sstevel@tonic-gate int *rp; 4490Sstevel@tonic-gate uint_t proplen; 4500Sstevel@tonic-gate char name[80]; 4510Sstevel@tonic-gate int dev; 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate PDBG(("pciide_initchild\n")); 4540Sstevel@tonic-gate 4550Sstevel@tonic-gate /* 4560Sstevel@tonic-gate * Set the address portion of the node name based on 4570Sstevel@tonic-gate * the controller number (0 or 1) from the 'reg' property. 4580Sstevel@tonic-gate */ 4590Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 4600Sstevel@tonic-gate "reg", &rp, (uint_t *)&proplen) != DDI_PROP_SUCCESS) { 4610Sstevel@tonic-gate PDBG(("pciide_intchild prop error\n")); 4620Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 4630Sstevel@tonic-gate } 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate /* 4660Sstevel@tonic-gate * copy the controller number and 4670Sstevel@tonic-gate * free the memory allocated by ddi_prop_lookup_int_array 4680Sstevel@tonic-gate */ 4690Sstevel@tonic-gate dev = *rp; 4700Sstevel@tonic-gate ddi_prop_free(rp); 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate /* 4730Sstevel@tonic-gate * I only support two controllers per device, determine 4740Sstevel@tonic-gate * which this one is and set its unit address. 4750Sstevel@tonic-gate */ 4760Sstevel@tonic-gate if (dev > 1) { 4770Sstevel@tonic-gate PDBG(("pciide_initchild bad dev\n")); 4780Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 4790Sstevel@tonic-gate } 4800Sstevel@tonic-gate (void) sprintf(name, "%d", dev); 4810Sstevel@tonic-gate ddi_set_name_addr(cdip, name); 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate /* 4840Sstevel@tonic-gate * determine if this instance is running in native or compat mode 4850Sstevel@tonic-gate */ 4860Sstevel@tonic-gate pciide_compat_setup(mydip, cdip, dev); 4870Sstevel@tonic-gate 4880Sstevel@tonic-gate /* interrupts property is required */ 4890Sstevel@tonic-gate if (PCIIDE_NATIVE_MODE(cdip)) { 4900Sstevel@tonic-gate vec = 1; 4910Sstevel@tonic-gate } else { 4920Sstevel@tonic-gate /* 4930Sstevel@tonic-gate * In compatibility mode, dev 0 should always be 4940Sstevel@tonic-gate * IRQ 14 and dev 1 is IRQ 15. If for some reason 4950Sstevel@tonic-gate * this needs to be changed, do it via the interrupts 4960Sstevel@tonic-gate * property in the ata.conf file. 4970Sstevel@tonic-gate */ 4980Sstevel@tonic-gate vec = ddi_prop_get_int(DDI_DEV_T_ANY, cdip, DDI_PROP_DONTPASS, 4995295Srandyf "interrupts", -1); 5000Sstevel@tonic-gate if (vec == -1) { 5010Sstevel@tonic-gate /* setup compatibility mode interrupts */ 5020Sstevel@tonic-gate if (dev == 0) { 5030Sstevel@tonic-gate vec = 14; 5040Sstevel@tonic-gate } else if (dev == 1) { 5050Sstevel@tonic-gate vec = 15; 5060Sstevel@tonic-gate } else { 5070Sstevel@tonic-gate PDBG(("pciide_initchild bad intr\n")); 5080Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 5090Sstevel@tonic-gate } 5100Sstevel@tonic-gate } 5110Sstevel@tonic-gate } 5120Sstevel@tonic-gate 513430Smrj pdptr = kmem_zalloc(PCIIDE_PDSIZE, KM_SLEEP); 5140Sstevel@tonic-gate ispecp = (struct intrspec *)(pdptr + 1); 5150Sstevel@tonic-gate pdptr->par_nintr = 1; 5160Sstevel@tonic-gate pdptr->par_intr = ispecp; 5170Sstevel@tonic-gate ispecp->intrspec_vec = vec; 5180Sstevel@tonic-gate ddi_set_parent_data(cdip, pdptr); 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate PDBG(("pciide_initchild okay\n")); 5210Sstevel@tonic-gate return (DDI_SUCCESS); 5220Sstevel@tonic-gate } 5230Sstevel@tonic-gate 5240Sstevel@tonic-gate static int 5250Sstevel@tonic-gate pciide_bus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 5260Sstevel@tonic-gate off_t offset, off_t len, caddr_t *vaddrp) 5270Sstevel@tonic-gate { 5280Sstevel@tonic-gate dev_info_t *pdip; 5290Sstevel@tonic-gate int rnumber = mp->map_obj.rnumber; 5300Sstevel@tonic-gate int controller; 5310Sstevel@tonic-gate int rc; 5320Sstevel@tonic-gate 5330Sstevel@tonic-gate PDBG(("pciide_bus_map\n")); 5340Sstevel@tonic-gate 5350Sstevel@tonic-gate if (strcmp("0", ddi_get_name_addr(rdip)) == 0) 5360Sstevel@tonic-gate controller = 0; 5370Sstevel@tonic-gate else 5380Sstevel@tonic-gate controller = 1; 5390Sstevel@tonic-gate 5400Sstevel@tonic-gate /* 5410Sstevel@tonic-gate * Adjust the rnumbers based on which controller instance 5420Sstevel@tonic-gate * is being mapped; adjust for the 2 tuples per controller. 5430Sstevel@tonic-gate */ 5440Sstevel@tonic-gate 5450Sstevel@tonic-gate switch (rnumber) { 5460Sstevel@tonic-gate case 0: 5470Sstevel@tonic-gate case 1: 5480Sstevel@tonic-gate mp->map_obj.rnumber += (controller * 2); 5490Sstevel@tonic-gate break; 5500Sstevel@tonic-gate case 2: 5510Sstevel@tonic-gate /* 5520Sstevel@tonic-gate * split the 16 I/O ports into two 8 port ranges 5530Sstevel@tonic-gate */ 5540Sstevel@tonic-gate mp->map_obj.rnumber = 4; 5550Sstevel@tonic-gate if (offset + len > 8) { 5560Sstevel@tonic-gate PDBG(("pciide_bus_map offset\n")); 5570Sstevel@tonic-gate return (DDI_FAILURE); 5580Sstevel@tonic-gate } 5590Sstevel@tonic-gate if (len == 0) 5600Sstevel@tonic-gate len = 8 - offset; 5610Sstevel@tonic-gate offset += 8 * controller; 5620Sstevel@tonic-gate break; 5630Sstevel@tonic-gate default: 5640Sstevel@tonic-gate PDBG(("pciide_bus_map default\n")); 5650Sstevel@tonic-gate return (DDI_FAILURE); 5660Sstevel@tonic-gate } 5670Sstevel@tonic-gate 5680Sstevel@tonic-gate if (PCIIDE_PRE26(dip)) { 5690Sstevel@tonic-gate int old_rnumber; 5700Sstevel@tonic-gate int new_rnumber; 5710Sstevel@tonic-gate 5720Sstevel@tonic-gate old_rnumber = mp->map_obj.rnumber; 5730Sstevel@tonic-gate new_rnumber = pciide_pre26_rnumber_map(dip, old_rnumber); 5740Sstevel@tonic-gate PDBG(("pciide rnumber old %d new %d\n", 5755295Srandyf old_rnumber, new_rnumber)); 5760Sstevel@tonic-gate mp->map_obj.rnumber = new_rnumber; 5770Sstevel@tonic-gate } 5780Sstevel@tonic-gate 5790Sstevel@tonic-gate /* 5800Sstevel@tonic-gate * Add 1 to skip over the PCI config space tuple 5810Sstevel@tonic-gate */ 5820Sstevel@tonic-gate mp->map_obj.rnumber++; 5830Sstevel@tonic-gate 5840Sstevel@tonic-gate 5850Sstevel@tonic-gate /* 5860Sstevel@tonic-gate * pass the adjusted request to my parent 5870Sstevel@tonic-gate */ 5880Sstevel@tonic-gate pdip = ddi_get_parent(dip); 5890Sstevel@tonic-gate rc = ((*(DEVI(pdip)->devi_ops->devo_bus_ops->bus_map)) 5905295Srandyf (pdip, dip, mp, offset, len, vaddrp)); 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate PDBG(("pciide_bus_map %s\n", rc == DDI_SUCCESS ? "okay" : "!ok")); 5930Sstevel@tonic-gate 5940Sstevel@tonic-gate return (rc); 5950Sstevel@tonic-gate } 5960Sstevel@tonic-gate 5970Sstevel@tonic-gate 5980Sstevel@tonic-gate static struct intrspec * 5990Sstevel@tonic-gate pciide_get_ispec(dev_info_t *dip, dev_info_t *rdip, int inumber) 6000Sstevel@tonic-gate { 6010Sstevel@tonic-gate struct ddi_parent_private_data *ppdptr; 6020Sstevel@tonic-gate 6030Sstevel@tonic-gate PDBG(("pciide_get_ispec\n")); 6040Sstevel@tonic-gate 6050Sstevel@tonic-gate /* 6060Sstevel@tonic-gate * Native mode PCI-IDE controllers share the parent's 6070Sstevel@tonic-gate * PCI interrupt line. 6080Sstevel@tonic-gate * 6090Sstevel@tonic-gate * Compatibility mode PCI-IDE controllers have their 6100Sstevel@tonic-gate * own intrspec which specifies ISA IRQ 14 or 15. 6110Sstevel@tonic-gate * 6120Sstevel@tonic-gate */ 6130Sstevel@tonic-gate if (PCIIDE_NATIVE_MODE(rdip)) { 6140Sstevel@tonic-gate ddi_intrspec_t is; 6150Sstevel@tonic-gate 6160Sstevel@tonic-gate is = pci_intx_get_ispec(dip, dip, inumber); 6170Sstevel@tonic-gate PDBG(("pciide_get_ispec okay\n")); 6180Sstevel@tonic-gate return ((struct intrspec *)is); 6190Sstevel@tonic-gate } 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate /* Else compatibility mode, use the ISA IRQ */ 6220Sstevel@tonic-gate if ((ppdptr = ddi_get_parent_data(rdip)) == NULL) { 6230Sstevel@tonic-gate PDBG(("pciide_get_ispec null\n")); 6240Sstevel@tonic-gate return (NULL); 6250Sstevel@tonic-gate } 6260Sstevel@tonic-gate 6270Sstevel@tonic-gate /* validate the interrupt number */ 6280Sstevel@tonic-gate if (inumber >= ppdptr->par_nintr) { 6290Sstevel@tonic-gate PDBG(("pciide_get_inum\n")); 6300Sstevel@tonic-gate return (NULL); 6310Sstevel@tonic-gate } 6320Sstevel@tonic-gate 6330Sstevel@tonic-gate PDBG(("pciide_get_ispec ok\n")); 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate return ((struct intrspec *)&ppdptr->par_intr[inumber]); 6360Sstevel@tonic-gate } 6370Sstevel@tonic-gate 6380Sstevel@tonic-gate static int 6390Sstevel@tonic-gate pciide_get_pri(dev_info_t *dip, dev_info_t *rdip, 6400Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, int *pri) 6410Sstevel@tonic-gate { 6420Sstevel@tonic-gate struct intrspec *ispecp; 6430Sstevel@tonic-gate int *intpriorities; 6440Sstevel@tonic-gate uint_t num_intpriorities; 6450Sstevel@tonic-gate 6460Sstevel@tonic-gate PDBG(("pciide_get_pri\n")); 6470Sstevel@tonic-gate 6480Sstevel@tonic-gate if ((ispecp = pciide_get_ispec(dip, rdip, hdlp->ih_inum)) == NULL) { 6490Sstevel@tonic-gate PDBG(("pciide_get_pri null\n")); 6500Sstevel@tonic-gate return (DDI_FAILURE); 6510Sstevel@tonic-gate } 6520Sstevel@tonic-gate 6530Sstevel@tonic-gate if (PCIIDE_NATIVE_MODE(rdip)) { 6540Sstevel@tonic-gate *pri = ispecp->intrspec_pri; 6550Sstevel@tonic-gate PDBG(("pciide_get_pri ok\n")); 6560Sstevel@tonic-gate return (DDI_SUCCESS); 6570Sstevel@tonic-gate } 6580Sstevel@tonic-gate 6590Sstevel@tonic-gate /* check if the intrspec has been initialized */ 6600Sstevel@tonic-gate if (ispecp->intrspec_pri != 0) { 6610Sstevel@tonic-gate *pri = ispecp->intrspec_pri; 6620Sstevel@tonic-gate PDBG(("pciide_get_pri ok2\n")); 6630Sstevel@tonic-gate return (DDI_SUCCESS); 6640Sstevel@tonic-gate } 6650Sstevel@tonic-gate 6660Sstevel@tonic-gate /* Use a default of level 5 */ 6670Sstevel@tonic-gate ispecp->intrspec_pri = 5; 6680Sstevel@tonic-gate 6690Sstevel@tonic-gate /* 6700Sstevel@tonic-gate * If there's an interrupt-priorities property, use it to 6710Sstevel@tonic-gate * over-ride the default interrupt priority. 6720Sstevel@tonic-gate */ 6730Sstevel@tonic-gate if (ddi_prop_lookup_int_array(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS, 6740Sstevel@tonic-gate "interrupt-priorities", &intpriorities, &num_intpriorities) == 6750Sstevel@tonic-gate DDI_PROP_SUCCESS) { 6760Sstevel@tonic-gate if (hdlp->ih_inum < num_intpriorities) 6770Sstevel@tonic-gate ispecp->intrspec_pri = intpriorities[hdlp->ih_inum]; 6780Sstevel@tonic-gate ddi_prop_free(intpriorities); 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate *pri = ispecp->intrspec_pri; 6810Sstevel@tonic-gate 6820Sstevel@tonic-gate PDBG(("pciide_get_pri ok3\n")); 6830Sstevel@tonic-gate 6840Sstevel@tonic-gate return (DDI_SUCCESS); 6850Sstevel@tonic-gate } 6860Sstevel@tonic-gate 6870Sstevel@tonic-gate static int 6880Sstevel@tonic-gate pciide_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 6890Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 6900Sstevel@tonic-gate { 6910Sstevel@tonic-gate struct intrspec *ispecp; 6920Sstevel@tonic-gate int rc; 6930Sstevel@tonic-gate int pri = 0; 6940Sstevel@tonic-gate 6950Sstevel@tonic-gate PDBG(("pciide_intr_ops: dip %p rdip %p op %x hdlp %p\n", 6960Sstevel@tonic-gate (void *)dip, (void *)rdip, intr_op, (void *)hdlp)); 6970Sstevel@tonic-gate 6980Sstevel@tonic-gate switch (intr_op) { 6990Sstevel@tonic-gate case DDI_INTROP_SUPPORTED_TYPES: 7000Sstevel@tonic-gate *(int *)result = DDI_INTR_TYPE_FIXED; 7010Sstevel@tonic-gate break; 7020Sstevel@tonic-gate case DDI_INTROP_GETCAP: 7031290Sanish *(int *)result = DDI_INTR_FLAG_LEVEL; 7040Sstevel@tonic-gate break; 7050Sstevel@tonic-gate case DDI_INTROP_NINTRS: 7062580Sanish case DDI_INTROP_NAVAIL: 7072580Sanish *(int *)result = (!PCIIDE_NATIVE_MODE(rdip)) ? 7082580Sanish i_ddi_get_intx_nintrs(rdip) : 1; 7090Sstevel@tonic-gate break; 7100Sstevel@tonic-gate case DDI_INTROP_ALLOC: 7110Sstevel@tonic-gate if ((ispecp = pciide_get_ispec(dip, rdip, hdlp->ih_inum)) == 7120Sstevel@tonic-gate NULL) 7130Sstevel@tonic-gate return (DDI_FAILURE); 7140Sstevel@tonic-gate *(int *)result = hdlp->ih_scratch1; 7150Sstevel@tonic-gate break; 7160Sstevel@tonic-gate case DDI_INTROP_FREE: 7170Sstevel@tonic-gate break; 7180Sstevel@tonic-gate case DDI_INTROP_GETPRI: 7190Sstevel@tonic-gate if (pciide_get_pri(dip, rdip, hdlp, &pri) != DDI_SUCCESS) { 7200Sstevel@tonic-gate *(int *)result = 0; 7210Sstevel@tonic-gate return (DDI_FAILURE); 7220Sstevel@tonic-gate } 7230Sstevel@tonic-gate *(int *)result = pri; 7240Sstevel@tonic-gate break; 7250Sstevel@tonic-gate case DDI_INTROP_ADDISR: 7260Sstevel@tonic-gate if ((ispecp = pciide_get_ispec(dip, rdip, hdlp->ih_inum)) == 7270Sstevel@tonic-gate NULL) 7280Sstevel@tonic-gate return (DDI_FAILURE); 729916Sschwartz ((ihdl_plat_t *)hdlp->ih_private)->ip_ispecp = ispecp; 7300Sstevel@tonic-gate ispecp->intrspec_func = hdlp->ih_cb_func; 7310Sstevel@tonic-gate break; 7320Sstevel@tonic-gate case DDI_INTROP_REMISR: 7330Sstevel@tonic-gate if ((ispecp = pciide_get_ispec(dip, rdip, hdlp->ih_inum)) == 7340Sstevel@tonic-gate NULL) 7350Sstevel@tonic-gate return (DDI_FAILURE); 7360Sstevel@tonic-gate ispecp->intrspec_func = (uint_t (*)()) 0; 7370Sstevel@tonic-gate break; 7380Sstevel@tonic-gate case DDI_INTROP_ENABLE: 7390Sstevel@tonic-gate /* FALLTHRU */ 7400Sstevel@tonic-gate case DDI_INTROP_DISABLE: 7410Sstevel@tonic-gate if (PCIIDE_NATIVE_MODE(rdip)) { 7420Sstevel@tonic-gate rdip = dip; 7430Sstevel@tonic-gate dip = ddi_get_parent(dip); 7440Sstevel@tonic-gate } else { /* get ptr to the root node */ 7450Sstevel@tonic-gate dip = ddi_root_node(); 7460Sstevel@tonic-gate } 7470Sstevel@tonic-gate 7480Sstevel@tonic-gate rc = (*(DEVI(dip)->devi_ops->devo_bus_ops->bus_intr_op))(dip, 7490Sstevel@tonic-gate rdip, intr_op, hdlp, result); 7500Sstevel@tonic-gate 7510Sstevel@tonic-gate #ifdef DEBUG 7520Sstevel@tonic-gate if (intr_op == DDI_INTROP_ENABLE) { 7530Sstevel@tonic-gate PDBG(("pciide_enable rc=%d", rc)); 7540Sstevel@tonic-gate } else 7550Sstevel@tonic-gate PDBG(("pciide_disable rc=%d", rc)); 7560Sstevel@tonic-gate #endif /* DEBUG */ 7570Sstevel@tonic-gate return (rc); 7580Sstevel@tonic-gate default: 7590Sstevel@tonic-gate return (DDI_FAILURE); 7600Sstevel@tonic-gate } 7610Sstevel@tonic-gate 7620Sstevel@tonic-gate return (DDI_SUCCESS); 7630Sstevel@tonic-gate } 7640Sstevel@tonic-gate 7650Sstevel@tonic-gate /* 7660Sstevel@tonic-gate * This is one of the places where controller specific setup needs to be 7670Sstevel@tonic-gate * considered. 7680Sstevel@tonic-gate * At this point the controller was already pre-qualified as a known and 7690Sstevel@tonic-gate * supported pciide controller. 7700Sstevel@tonic-gate * Some controllers do not provide PCI_MASS_IDE sub-class code and IDE 7710Sstevel@tonic-gate * programming interface code but rather PCI_MASS_OTHER sub-class code 7720Sstevel@tonic-gate * without any additional data. 7730Sstevel@tonic-gate * For those controllers IDE programming interface cannot be extracted 7740Sstevel@tonic-gate * from PCI class - we assume that they are pci-native type and we fix 7750Sstevel@tonic-gate * the programming interface used by other functions. 7760Sstevel@tonic-gate * The programming interface byte is set to indicate pci-native mode 7770Sstevel@tonic-gate * for both controllers and the Bus Master DMA capabilitiy of the controller. 7780Sstevel@tonic-gate */ 7790Sstevel@tonic-gate static void 7800Sstevel@tonic-gate pciide_compat_setup(dev_info_t *mydip, dev_info_t *cdip, int dev) 7810Sstevel@tonic-gate { 7820Sstevel@tonic-gate int class_code; 7830Sstevel@tonic-gate int rc = DDI_PROP_SUCCESS; 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate class_code = ddi_prop_get_int(DDI_DEV_T_ANY, mydip, 7860Sstevel@tonic-gate DDI_PROP_DONTPASS, "class-code", 0); 7870Sstevel@tonic-gate 7880Sstevel@tonic-gate if (((class_code & 0x00FF00) >> 8) == PCI_MASS_IDE) { 7890Sstevel@tonic-gate /* 7900Sstevel@tonic-gate * Controller provides PCI_MASS_IDE sub-class code first 7910Sstevel@tonic-gate * (implied IDE programming interface) 7920Sstevel@tonic-gate */ 7930Sstevel@tonic-gate if ((dev == 0 && !(class_code & PCI_IDE_IF_NATIVE_PRI)) || 7940Sstevel@tonic-gate (dev == 1 && !(class_code & PCI_IDE_IF_NATIVE_SEC))) { 7950Sstevel@tonic-gate rc = ddi_prop_update_int(DDI_DEV_T_NONE, cdip, 7965295Srandyf "compatibility-mode", 1); 7970Sstevel@tonic-gate if (rc != DDI_PROP_SUCCESS) 7980Sstevel@tonic-gate cmn_err(CE_WARN, 7990Sstevel@tonic-gate "pciide prop error %d compat-mode", rc); 8000Sstevel@tonic-gate } 8010Sstevel@tonic-gate } else { 8020Sstevel@tonic-gate /* 8030Sstevel@tonic-gate * Pci-ide controllers not providing PCI_MASS_IDE sub-class are 8040Sstevel@tonic-gate * assumed to be of pci-native type and bus master DMA capable. 8050Sstevel@tonic-gate * Programming interface part of the class-code property is 8060Sstevel@tonic-gate * fixed here. 8070Sstevel@tonic-gate */ 8080Sstevel@tonic-gate class_code &= 0x00ffff00; 8090Sstevel@tonic-gate class_code |= PCI_IDE_IF_BM_CAP_MASK | 8105295Srandyf PCI_IDE_IF_NATIVE_PRI | PCI_IDE_IF_NATIVE_SEC; 8110Sstevel@tonic-gate rc = ddi_prop_update_int(DDI_DEV_T_NONE, mydip, 8125295Srandyf "class-code", class_code); 8130Sstevel@tonic-gate if (rc != DDI_PROP_SUCCESS) 8140Sstevel@tonic-gate cmn_err(CE_WARN, 8150Sstevel@tonic-gate "pciide prop error %d class-code", rc); 8160Sstevel@tonic-gate } 8170Sstevel@tonic-gate } 8180Sstevel@tonic-gate 8190Sstevel@tonic-gate 8200Sstevel@tonic-gate static int 8210Sstevel@tonic-gate pciide_pre26_rnumber_map(dev_info_t *mydip, int rnumber) 8220Sstevel@tonic-gate { 8230Sstevel@tonic-gate int pri_native; 8240Sstevel@tonic-gate int sec_native; 8250Sstevel@tonic-gate int class_code; 8260Sstevel@tonic-gate 8270Sstevel@tonic-gate class_code = ddi_prop_get_int(DDI_DEV_T_ANY, mydip, DDI_PROP_DONTPASS, 8285295Srandyf "class-code", 0); 8290Sstevel@tonic-gate 8300Sstevel@tonic-gate pri_native = (class_code & PCI_IDE_IF_NATIVE_PRI) ? TRUE : FALSE; 8310Sstevel@tonic-gate sec_native = (class_code & PCI_IDE_IF_NATIVE_SEC) ? TRUE : FALSE; 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate return (pciide_map_rnumber(rnumber, pri_native, sec_native)); 8340Sstevel@tonic-gate 8350Sstevel@tonic-gate } 8360Sstevel@tonic-gate 8370Sstevel@tonic-gate /* 8380Sstevel@tonic-gate * The canonical order of the reg property tuples for the 8390Sstevel@tonic-gate * Base Address Registers is supposed to be: 8400Sstevel@tonic-gate * 8410Sstevel@tonic-gate * primary controller (BAR 0) 8420Sstevel@tonic-gate * primary controller (BAR 1) 8430Sstevel@tonic-gate * secondary controller (BAR 2) 8440Sstevel@tonic-gate * secondary controller (BAR 3) 8450Sstevel@tonic-gate * bus mastering regs (BAR 4) 8460Sstevel@tonic-gate * 8470Sstevel@tonic-gate * For 2.6, bootconf has been fixed to always generate the 8480Sstevel@tonic-gate * reg property (and assigned-addresses property) tuples 8490Sstevel@tonic-gate * in the above order. 8500Sstevel@tonic-gate * 8510Sstevel@tonic-gate * But in releases prior to 2.6 the order varies depending 8520Sstevel@tonic-gate * on whether compatibility or native mode is being used for 8530Sstevel@tonic-gate * each controller. There ends up being four possible 8540Sstevel@tonic-gate * orders: 8550Sstevel@tonic-gate * 8560Sstevel@tonic-gate * BM, P0, P1, S0, S1 primary compatible, secondary compatible 8570Sstevel@tonic-gate * S0, S1, BM, P0, P1 primary compatible, secondary native 8580Sstevel@tonic-gate * P0, P1, BM, S0, S1 primary native, secondary compatible 8590Sstevel@tonic-gate * P0, P1, S0, S1, BM primary native, secondary native 8600Sstevel@tonic-gate * 8610Sstevel@tonic-gate * where: Px is the primary tuples, Sx the secondary tuples, and 8620Sstevel@tonic-gate * B the Bus Master tuple. 8630Sstevel@tonic-gate * 8640Sstevel@tonic-gate * Here's the results for each of the four states: 8650Sstevel@tonic-gate * 8660Sstevel@tonic-gate * 0, 1, 2, 3, 4 8670Sstevel@tonic-gate * 8680Sstevel@tonic-gate * CC 1, 2, 3, 4, 0 8690Sstevel@tonic-gate * CN 3, 4, 0, 1, 2 8700Sstevel@tonic-gate * NC 0, 1, 3, 4, 2 8710Sstevel@tonic-gate * NN 0, 1, 2, 3, 4 8720Sstevel@tonic-gate * 8730Sstevel@tonic-gate * C = compatible(!native) == 0 8740Sstevel@tonic-gate * N = native == 1 8750Sstevel@tonic-gate * 8760Sstevel@tonic-gate * Here's the transformation matrix: 8770Sstevel@tonic-gate */ 8780Sstevel@tonic-gate 8790Sstevel@tonic-gate static int pciide_transform[2][2][5] = { 8800Sstevel@tonic-gate /* P S */ 8810Sstevel@tonic-gate /* [C][C] */ +1, +1, +1, +1, -4, 8820Sstevel@tonic-gate /* [C][N] */ +3, +3, -2, -2, -2, 8830Sstevel@tonic-gate /* [N][C] */ +0, +0, +1, +1, -2, 8840Sstevel@tonic-gate /* [N][N] */ +0, +0, +0, +0, +0 8850Sstevel@tonic-gate }; 8860Sstevel@tonic-gate 8870Sstevel@tonic-gate 8880Sstevel@tonic-gate static int 8890Sstevel@tonic-gate pciide_map_rnumber(int rnumber, int pri_native, int sec_native) 8900Sstevel@tonic-gate { 8910Sstevel@tonic-gate /* transform flags into indexes */ 8920Sstevel@tonic-gate pri_native = pri_native ? 1 : 0; 8930Sstevel@tonic-gate sec_native = sec_native ? 1 : 0; 8940Sstevel@tonic-gate 8950Sstevel@tonic-gate rnumber += pciide_transform[pri_native][sec_native][rnumber]; 8960Sstevel@tonic-gate return (rnumber); 8970Sstevel@tonic-gate } 898