/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved.
*/
/*
* PCI-IDE bus nexus driver
*/
#include <sys/ddidmareq.h>
#include <sys/ddi_impldefs.h>
#include <sys/dma_engine.h>
#include <sys/mach_intr.h>
#include <sys/pci_intr_lib.h>
"compatibility-mode"))
sizeof (struct intrspec))
#ifdef DEBUG
static int pci_ide_debug = 0;
if (pci_ide_debug) { \
prom_printf fmt; \
}
#else
#endif
#ifndef TRUE
#endif
#ifndef FALSE
#define FALSE 0
#endif
/*
* bus_ops functions
*/
void *result);
int inum);
/*
* Local Functions
*/
int dev);
int sec_native);
ddi_intr_handle_impl_t *, void *);
psm_intr_op_t, int *);
/*
* Config information
*/
0,
0,
0,
0,
0, /* (*bus_get_eventcookie)(); */
0, /* (*bus_add_eventcall)(); */
0, /* (*bus_remove_eventcall)(); */
0, /* (*bus_post_event)(); */
0,
0,
0,
0,
0,
0,
0,
0,
};
DEVO_REV, /* devo_rev, */
0, /* refcnt */
ddi_no_info, /* info */
nulldev, /* identify */
nulldev, /* probe */
pciide_attach, /* attach */
pciide_detach, /* detach */
nodev, /* reset */
(struct cb_ops *)0, /* driver operations */
&pciide_bus_ops, /* bus operations */
NULL, /* power */
ddi_quiesce_not_needed, /* quiesce */
};
/*
* Module linkage information for the kernel.
*/
&mod_driverops, /* Type of module. This is PCI-IDE bus driver */
"pciide nexus driver for 'PCI-IDE' 1.26",
&pciide_ops, /* driver ops */
};
&modldrv,
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
int
{
}
int
{
int rc;
switch (cmd) {
case DDI_ATTACH:
/*
* Make sure bus-mastering is enabled, even if
* BIOS didn't.
*/
/*
* In case of error, return SUCCESS. This is because
* bus-mastering could be already enabled by BIOS.
*/
if (rc != DDI_SUCCESS)
return (DDI_SUCCESS);
if ((cmdreg & PCI_COMM_ME) == 0) {
cmdreg | PCI_COMM_ME);
}
return (DDI_SUCCESS);
case DDI_RESUME:
/* Restore our PCI configuration header */
/*
* XXXX
* This is a pretty bad thing. However, for some
* reason it always happens. To further complicate
* things, it appears if we just ignore this, we
* properly resume. For now, all I want to do is
* to generate this message so that it doesn't get
* forgotten.
*/
"Couldn't restore PCI config regs for %s(%p)",
}
#ifdef DEBUG
/* Bus mastering should still be enabled */
return (DDI_FAILURE);
#endif
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
/*ARGSUSED*/
int
{
switch (cmd) {
case DDI_DETACH:
return (DDI_SUCCESS);
case DDI_SUSPEND:
/* Save our PCI configuration header */
/* Don't suspend if we cannot save config regs */
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
/*ARGSUSED*/
static int
{
int controller;
void *pdptr;
int rnumber;
int rc;
PDBG(("pciide_bus_ctl\n"));
switch (ctlop) {
case DDI_CTLOPS_INITCHILD:
case DDI_CTLOPS_UNINITCHILD:
return (DDI_SUCCESS);
case DDI_CTLOPS_NREGS:
*(int *)result = 3;
return (DDI_SUCCESS);
case DDI_CTLOPS_REGSIZE:
/*
* Adjust the rnumbers based on which controller instance
* is requested; adjust for the 2 tuples per controller.
*/
controller = 0;
else
controller = 1;
case 0:
case 1:
break;
case 2:
rnumber = 4;
break;
default:
PDBG(("pciide_ctlops invalid rnumber\n"));
return (DDI_FAILURE);
}
if (PCIIDE_PRE26(dip)) {
int old_rnumber;
int new_rnumber;
PDBG(("pciide rnumber old %d new %d\n",
}
/*
* Add 1 to skip over the PCI config space tuple
*/
rnumber++;
/*
* If it's not tuple #2 pass the adjusted request to my parent
*/
if (*(int *)arg != 2) {
}
/*
* Handle my child's reg-tuple #2 here by splitting my 16 byte
* reg-tuple #4 into two 8 byte ranges based on the
* the child's controller #.
*/
tmp = 8;
/*
* Allow for the possibility of less than 16 bytes by
* by checking what's actually returned for my reg-tuple #4.
*/
if (controller == 1) {
if (tmp < 8)
tmp = 0;
else
tmp -= 8;
}
if (tmp > 8)
tmp = 8;
return (rc);
case DDI_CTLOPS_ATTACH:
case DDI_CTLOPS_DETACH:
/*
*/
return (DDI_SUCCESS);
default:
}
}
/*
* IEEE 1275 Working Group Proposal #414 says that the Primary
* controller is "ata@0" and the Secondary controller "ata@1".
*
* By the time we get here, boot Bootconf (2.6+) has created devinfo
* nodes with the appropriate "reg", "assigned-addresses" and "interrupts"
* properites on the pci-ide node and both ide child nodes.
*
* In compatibility mode the "reg" and "assigned-addresses" properties
* of the pci-ide node are set up like this:
*
* 1. PCI-IDE Nexus
*
* interrupts=0
* (addr-hi addr-mid addr-low size-hi size-low)
* reg= assigned-addresses=00000000.00000000.00000000.00000000.00000000
* 81000000.00000000.000001f0.00000000.00000008
* 81000000.00000000.000003f4.00000000.00000004
* 81000000.00000000,00000170.00000000.00000008
* 81000000.00000000,00000374.00000000.00000004
* 01000020.00000000,-[BAR4]-.00000000.00000010
*
* In native PCI mode the "reg" and "assigned-addresses" properties
* would be set up like this:
*
* 2. PCI-IDE Nexus
*
* interrupts=0
* reg= assigned-addresses=00000000.00000000.00000000.00000000.00000000
* 01000010.00000000.-[BAR0]-.00000000.00000008
* 01000014,00000000.-[BAR1]-.00000000.00000004
* 01000018.00000000.-[BAR2]-.00000000.00000008
* 0100001c.00000000.-[BAR3]-.00000000.00000004
* 01000020.00000000.-[BAR4]-.00000000.00000010
*
*
* In both modes the child nodes simply have the following:
*
* 2. primary controller (compatibility mode)
*
* interrupts=14
* reg=00000000
*
* 3. secondary controller
*
* interrupts=15
* reg=00000001
*
* The pciide_bus_map() function is responsible for turning requests
* to map primary or secondary controller rnumbers into mapping requests
* of the appropriate regspec on the pci-ide node.
*
*/
static int
{
int vec;
int *rp;
int dev;
PDBG(("pciide_initchild\n"));
/*
* Set the address portion of the node name based on
* the controller number (0 or 1) from the 'reg' property.
*/
PDBG(("pciide_intchild prop error\n"));
return (DDI_NOT_WELL_FORMED);
}
/*
* copy the controller number and
* free the memory allocated by ddi_prop_lookup_int_array
*/
/*
* I only support two controllers per device, determine
* which this one is and set its unit address.
*/
if (dev > 1) {
PDBG(("pciide_initchild bad dev\n"));
return (DDI_NOT_WELL_FORMED);
}
/*
* determine if this instance is running in native or compat mode
*/
/* interrupts property is required */
if (PCIIDE_NATIVE_MODE(cdip)) {
vec = 1;
} else {
/*
* In compatibility mode, dev 0 should always be
* IRQ 14 and dev 1 is IRQ 15. If for some reason
* this needs to be changed, do it via the interrupts
* property in the ata.conf file.
*/
"interrupts", -1);
if (vec == -1) {
/* setup compatibility mode interrupts */
if (dev == 0) {
vec = 14;
} else if (dev == 1) {
vec = 15;
} else {
PDBG(("pciide_initchild bad intr\n"));
return (DDI_NOT_WELL_FORMED);
}
}
}
PDBG(("pciide_initchild okay\n"));
return (DDI_SUCCESS);
}
static int
{
int controller;
int rc;
PDBG(("pciide_bus_map\n"));
controller = 0;
else
controller = 1;
/*
* Adjust the rnumbers based on which controller instance
* is being mapped; adjust for the 2 tuples per controller.
*/
switch (rnumber) {
case 0:
case 1:
break;
case 2:
/*
* split the 16 I/O ports into two 8 port ranges
*/
PDBG(("pciide_bus_map offset\n"));
return (DDI_FAILURE);
}
if (len == 0)
break;
default:
PDBG(("pciide_bus_map default\n"));
return (DDI_FAILURE);
}
if (PCIIDE_PRE26(dip)) {
int old_rnumber;
int new_rnumber;
PDBG(("pciide rnumber old %d new %d\n",
}
/*
* Add 1 to skip over the PCI config space tuple
*/
/*
* pass the adjusted request to my parent
*/
return (rc);
}
static struct intrspec *
{
PDBG(("pciide_get_ispec\n"));
/*
* Native mode PCI-IDE controllers share the parent's
* PCI interrupt line.
*
* Compatibility mode PCI-IDE controllers have their
* own intrspec which specifies ISA IRQ 14 or 15.
*
*/
if (PCIIDE_NATIVE_MODE(rdip)) {
PDBG(("pciide_get_ispec okay\n"));
}
/* Else compatibility mode, use the ISA IRQ */
PDBG(("pciide_get_ispec null\n"));
return (NULL);
}
/* validate the interrupt number */
PDBG(("pciide_get_inum\n"));
return (NULL);
}
PDBG(("pciide_get_ispec ok\n"));
}
static int
{
int *intpriorities;
PDBG(("pciide_get_pri\n"));
PDBG(("pciide_get_pri null\n"));
return (DDI_FAILURE);
}
if (PCIIDE_NATIVE_MODE(rdip)) {
PDBG(("pciide_get_pri ok\n"));
return (DDI_SUCCESS);
}
/* check if the intrspec has been initialized */
if (ispecp->intrspec_pri != 0) {
PDBG(("pciide_get_pri ok2\n"));
return (DDI_SUCCESS);
}
/* Use a default of level 5 */
/*
* If there's an interrupt-priorities property, use it to
* over-ride the default interrupt priority.
*/
}
PDBG(("pciide_get_pri ok3\n"));
return (DDI_SUCCESS);
}
static int
{
int rc;
int pri = 0;
PDBG(("pciide_intr_ops: dip %p rdip %p op %x hdlp %p\n",
switch (intr_op) {
*(int *)result = DDI_INTR_TYPE_FIXED;
break;
case DDI_INTROP_GETCAP:
*(int *)result = DDI_INTR_FLAG_LEVEL;
break;
case DDI_INTROP_NINTRS:
case DDI_INTROP_NAVAIL:
break;
case DDI_INTROP_ALLOC:
case DDI_INTROP_FREE:
case DDI_INTROP_GETPRI:
*(int *)result = 0;
return (DDI_FAILURE);
}
break;
case DDI_INTROP_ADDISR:
NULL)
return (DDI_FAILURE);
break;
case DDI_INTROP_REMISR:
NULL)
return (DDI_FAILURE);
break;
case DDI_INTROP_ENABLE:
/* FALLTHRU */
case DDI_INTROP_DISABLE:
if (PCIIDE_NATIVE_MODE(rdip)) {
} else { /* get ptr to the root node */
dip = ddi_root_node();
}
#ifdef DEBUG
if (intr_op == DDI_INTROP_ENABLE) {
} else
#endif /* DEBUG */
return (rc);
default:
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
int
{
int ret;
int free_phdl = 0;
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
return (DDI_FAILURE);
/*
* If the PSM module is "APIX" then pass the request for it
* to allocate the vector now.
*/
free_phdl = 1;
}
if (PCIIDE_NATIVE_MODE(rdip)) {
} else { /* get ptr to the root node */
dip = ddi_root_node();
}
if (free_phdl) { /* free up the phdl structure */
free_phdl = 0;
}
} else {
/*
* No APIX module; fall back to the old scheme where the
* interrupt vector is allocated during ddi_enable_intr() call.
*/
ret = DDI_SUCCESS;
}
return (ret);
}
int
{
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
/*
* If the PSM module is "APIX" then pass the request for it
* to free up the vector now.
*/
NULL)
return (DDI_FAILURE);
if (PCIIDE_NATIVE_MODE(rdip)) {
} else { /* get ptr to the root node */
dip = ddi_root_node();
}
}
/*
* No APIX module; fall back to the old scheme where
* the interrupt vector was already freed during
* ddi_disable_intr() call.
*/
return (DDI_SUCCESS);
}
/*
* This is one of the places where controller specific setup needs to be
* considered.
* At this point the controller was already pre-qualified as a known and
* supported pciide controller.
* Some controllers do not provide PCI_MASS_IDE sub-class code and IDE
* programming interface code but rather PCI_MASS_OTHER sub-class code
* without any additional data.
* For those controllers IDE programming interface cannot be extracted
* from PCI class - we assume that they are pci-native type and we fix
* the programming interface used by other functions.
* The programming interface byte is set to indicate pci-native mode
* for both controllers and the Bus Master DMA capabilitiy of the controller.
*/
static void
{
int class_code;
DDI_PROP_DONTPASS, "class-code", 0);
/*
* Controller provides PCI_MASS_IDE sub-class code first
* (implied IDE programming interface)
*/
"compatibility-mode", 1);
if (rc != DDI_PROP_SUCCESS)
"pciide prop error %d compat-mode", rc);
}
} else {
/*
* Pci-ide controllers not providing PCI_MASS_IDE sub-class are
* assumed to be of pci-native type and bus master DMA capable.
* Programming interface part of the class-code property is
* fixed here.
*/
class_code &= 0x00ffff00;
"class-code", class_code);
if (rc != DDI_PROP_SUCCESS)
"pciide prop error %d class-code", rc);
}
}
static int
{
int pri_native;
int sec_native;
int class_code;
"class-code", 0);
}
/*
* The canonical order of the reg property tuples for the
* Base Address Registers is supposed to be:
*
* primary controller (BAR 0)
* primary controller (BAR 1)
* secondary controller (BAR 2)
* secondary controller (BAR 3)
* bus mastering regs (BAR 4)
*
* For 2.6, bootconf has been fixed to always generate the
* reg property (and assigned-addresses property) tuples
* in the above order.
*
* But in releases prior to 2.6 the order varies depending
* on whether compatibility or native mode is being used for
* each controller. There ends up being four possible
* orders:
*
* BM, P0, P1, S0, S1 primary compatible, secondary compatible
* S0, S1, BM, P0, P1 primary compatible, secondary native
* P0, P1, BM, S0, S1 primary native, secondary compatible
* P0, P1, S0, S1, BM primary native, secondary native
*
* where: Px is the primary tuples, Sx the secondary tuples, and
* B the Bus Master tuple.
*
* Here's the results for each of the four states:
*
* 0, 1, 2, 3, 4
*
* CC 1, 2, 3, 4, 0
* CN 3, 4, 0, 1, 2
* NC 0, 1, 3, 4, 2
* NN 0, 1, 2, 3, 4
*
* C = compatible(!native) == 0
* N = native == 1
*
* Here's the transformation matrix:
*/
/* P S */
/* [C][C] */ +1, +1, +1, +1, -4,
/* [C][N] */ +3, +3, -2, -2, -2,
/* [N][C] */ +0, +0, +1, +1, -2,
/* [N][N] */ +0, +0, +0, +0, +0
};
static int
{
/* transform flags into indexes */
return (rnumber);
}