isa.c revision 2273e7c709f1df61ff7132f9095307e2cedd865b
/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* ISA bus nexus driver
*/
#include <sys/autoconf.h>
#include <sys/ddidmareq.h>
#include <sys/ddi_impldefs.h>
#include <sys/dma_engine.h>
#include <sys/mach_intr.h>
#if defined(__xpv)
#include <sys/hypervisor.h>
#include <sys/evtchn_impl.h>
#endif
extern int pseudo_isa;
extern int isa_resource_setup(void);
psm_intr_op_t, int *);
static char USED_RESOURCES[] = "used-resources";
static void isa_alloc_nodes(dev_info_t *);
static void enumerate_BIOS_serial(dev_info_t *);
static void isa_postattach(dev_info_t *);
/*
* The following typedef is used to represent an entry in the "ranges"
* property of a pci-isa bridge device node.
*/
typedef struct {
} pib_ranges_t;
typedef struct {
#define ISA_ADDR_MEM 0 /* memory adress space */
#define BIOS_DATA_AREA 0x400
/*
* #define ISA_DEBUG 1
*/
/*
* For serial ports not enumerated by ACPI, and parallel ports with
* illegal size. Typically, a system can have as many as 4 serial
* ports and 3 parallel ports.
*/
#define MAX_EXTRA_RESOURCE 7
static int isa_extra_count = 0;
/*
* Local data
*/
static ddi_dma_lim_t ISA_dma_limits = {
0, /* address low */
0x00ffffff, /* address high */
0, /* counter max */
1, /* burstsize */
DMA_UNIT_8, /* minimum xfer */
0, /* dma speed */
0x0000ffff, /* address register */
0x0000ffff, /* counter register */
1, /* sector size */
};
static ddi_dma_attr_t ISA_dma_attr = {
(unsigned long long)0,
(unsigned long long)0x00ffffff,
0x0000ffff,
1,
1,
1,
(unsigned long long)0xffffffff,
(unsigned long long)0x0000ffff,
1,
1,
0
};
/*
* Config information
*/
static int
static int
static int
static int
static int
struct bus_ops isa_bus_ops = {
NULL,
NULL,
NULL,
NULL, /* (*bus_get_eventcookie)(); */
NULL, /* (*bus_add_eventcall)(); */
NULL, /* (*bus_remove_eventcall)(); */
NULL, /* (*bus_post_event)(); */
NULL, /* (*bus_intr_ctl)(); */
NULL, /* (*bus_config)(); */
NULL, /* (*bus_unconfig)(); */
NULL, /* (*bus_fm_init)(); */
NULL, /* (*bus_fm_fini)(); */
NULL, /* (*bus_fm_access_enter)(); */
NULL, /* (*bus_fm_access_exit)(); */
NULL, /* (*bus_power)(); */
isa_intr_ops /* (*bus_intr_op)(); */
};
/*
* Internal isa ctlops support routines
*/
DEVO_REV, /* devo_rev, */
0, /* refcnt */
ddi_no_info, /* info */
nulldev, /* identify */
nulldev, /* probe */
isa_attach, /* attach */
nulldev, /* detach */
nodev, /* reset */
(struct cb_ops *)0, /* driver operations */
&isa_bus_ops, /* bus operations */
NULL, /* power */
ddi_quiesce_not_needed, /* quiesce */
};
/*
* Module linkage information for the kernel.
*/
&mod_driverops, /* Type of module. This is ISA bus driver */
"isa nexus driver for 'ISA'",
&isa_ops, /* driver ops */
};
static struct modlinkage modlinkage = {
&modldrv,
};
int
_init(void)
{
return (mod_install(&modlinkage));
}
int
_fini(void)
{
return (mod_remove(&modlinkage));
}
int
{
}
static int
{
int rval;
#if defined(__xpv)
/*
* don't allow isa to attach in domU. this can happen if someone sets
* the console wrong, etc. ISA devices assume the H/W is there and
* will cause the domU to panic.
*/
if (!DOMAIN_IS_INITDOMAIN(xen_info)) {
return (DDI_FAILURE);
}
#endif
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
/*
* Enumerate children -- invoking ACPICA
* This is normally in bus_config(), but we need this
* to happen earlier to boot.
*/
}
return (rval);
}
(rng_p)->parent_mid = 0; \
static uint_t
{
ptype |= PCI_REG_REL_M;
size /= USED_CELL_SIZE;
/* merge ranges record if applicable */
else {
rng_p++;
}
}
}
void
{
int i;
size /= USED_CELL_SIZE;
}
static void
{
ddi_get_name(dip));
return;
}
return;
}
return;
}
KM_SLEEP);
if (nio != 0) {
}
if (nmem != 0) {
}
if (!pseudo_isa)
}
/*ARGSUSED*/
static int
{
ddi_get_name(dip));
return (DDI_ME_REGSPEC_RANGE);
}
/* Check for correct space */
continue;
/* Detect whether request entirely fits within a range */
continue;
continue;
pci_reg_p->pci_phys_mid = 0;
pci_reg_p->pci_size_hi = 0;
break;
}
if (i < nrange)
return (DDI_SUCCESS);
/*
* Check extra resource range specially for serial and parallel
* devices, which are treated differently from all other ISA
* devices. On some machines, serial ports are not enumerated
* by ACPI but by BIOS, with io base addresses noted in legacy
* BIOS data area. Parallel port on some machines comes with
* illegal size.
*/
goto out_of_range;
for (i = 0; i < isa_extra_count; i++) {
continue;
continue;
pci_reg_p->pci_phys_mid = 0;
pci_reg_p->pci_size_hi = 0;
break;
}
if (i < isa_extra_count)
return (DDI_SUCCESS);
return (DDI_ME_REGSPEC_RANGE);
}
static int
{
int error;
if (pseudo_isa)
/*
* First, if given an rnumber, convert it to a regspec...
*/
return (DDI_ME_RNUMBER_RANGE);
/*
* Convert the given ddi_map_req_t from rnumber to regspec...
*/
}
/*
* Adjust offset and length correspnding to called values...
* XXX: A non-zero length means override the one in the regspec.
* XXX: (Regardless of what's in the parent's range)
*/
if (len != 0)
return (error);
/*
* Call my parents bus_map function with modified values...
*/
}
static int
{
}
static int
{
int rval;
switch (request) {
case DDI_DMA_E_PROG:
case DDI_DMA_E_ACQUIRE:
case DDI_DMA_E_FREE:
case DDI_DMA_E_STOP:
return (DDI_SUCCESS);
case DDI_DMA_E_ENABLE:
return (DDI_SUCCESS);
case DDI_DMA_E_DISABLE:
return (DDI_SUCCESS);
case DDI_DMA_E_GETCNT:
return (DDI_SUCCESS);
case DDI_DMA_E_SWSETUP:
case DDI_DMA_E_SWSTART:
return (DDI_SUCCESS);
case DDI_DMA_E_GETLIM:
return (DDI_SUCCESS);
case DDI_DMA_E_GETATTR:
return (DDI_SUCCESS);
case DDI_DMA_E_1STPTY:
{
struct ddi_dmae_req req1stpty =
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (arg == 0) {
} else {
}
}
case DDI_DMA_IOPB_ALLOC: /* get contiguous DMA-able memory */
case DDI_DMA_SMEM_ALLOC:
if (!offp) {
}
/*FALLTHROUGH*/
default:
}
return (rval);
}
/*
* Check if driver should be treated as an old pre 2.6 driver
*/
static int
{
extern int ignore_hardware_nodes; /* force flag from ddi_impl.c */
if (ndi_dev_is_persistent_node(dip)) {
return (1);
"ignore-hardware-nodes", -1) != -1)
return (1);
}
return (0);
}
typedef struct {
} isa_regs_t;
/*
* Return non-zero if device in tree is a PnP isa device
*/
static int
{
if (ndi_dev_is_persistent_node(dip) == 0)
return (0);
return (0);
}
/*
* free the memory allocated by ddi_getlongprop().
*/
if (pnpisa)
return (1);
else
return (0);
}
/*ARGSUSED*/
static int
{
int rn;
struct ddi_parent_private_data *pdp;
switch (ctlop) {
case DDI_CTLOPS_REPORTDEV:
if (rdip == (dev_info_t *)0)
return (DDI_FAILURE);
return (DDI_SUCCESS);
case DDI_CTLOPS_INITCHILD:
/*
* older drivers aren't expecting the "standard" device
* node format used by the hardware nodes. these drivers
* only expect their own properties set in their driver.conf
* files. so they tell us not to call them with hardware
* nodes by setting the property "ignore-hardware-nodes".
*/
return (DDI_NOT_WELL_FORMED);
}
case DDI_CTLOPS_UNINITCHILD:
return (DDI_SUCCESS);
case DDI_CTLOPS_SIDDEV:
/*
* All ISA devices need to do confirming probes
* unless they are PnP ISA.
*/
return (DDI_SUCCESS);
else
return (DDI_FAILURE);
case DDI_CTLOPS_REGSIZE:
case DDI_CTLOPS_NREGS:
if (rdip == (dev_info_t *)0)
return (DDI_FAILURE);
return (DDI_FAILURE);
if (ctlop == DDI_CTLOPS_NREGS) {
} else {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
case DDI_CTLOPS_ATTACH:
case DDI_CTLOPS_DETACH:
case DDI_CTLOPS_PEEK:
case DDI_CTLOPS_POKE:
return (DDI_FAILURE);
default:
}
}
static struct intrspec *
{
/* Validate the interrupt number */
return (NULL);
/* Get the interrupt structure pointer and return that */
}
static int
{
if (pseudo_isa)
/* Process the interrupt operation */
switch (intr_op) {
case DDI_INTROP_GETCAP:
/* First check with pcplusmp */
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
*(int *)result = 0;
return (DDI_FAILURE);
}
break;
case DDI_INTROP_SETCAP:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
return (DDI_FAILURE);
break;
case DDI_INTROP_ALLOC:
return (DDI_FAILURE);
break;
case DDI_INTROP_FREE:
break;
case DDI_INTROP_GETPRI:
return (DDI_FAILURE);
break;
case DDI_INTROP_SETPRI:
/* Validate the interrupt priority passed to us */
if (*(int *)result > LOCK_LEVEL)
return (DDI_FAILURE);
/* Ensure that PSM is all initialized and ispec is ok */
if ((psm_intr_ops == NULL) ||
return (DDI_FAILURE);
/* update the ispec with the new priority */
break;
case DDI_INTROP_ADDISR:
return (DDI_FAILURE);
break;
case DDI_INTROP_REMISR:
return (DDI_FAILURE);
return (DDI_FAILURE);
break;
case DDI_INTROP_ENABLE:
return (DDI_FAILURE);
/* Call psmi to translate irq with the dip */
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
/* Add the interrupt handler */
return (DDI_FAILURE);
break;
case DDI_INTROP_DISABLE:
return (DDI_FAILURE);
/* Call psm_ops() to translate irq with the dip */
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
/* Remove the interrupt handler */
break;
case DDI_INTROP_SETMASK:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
return (DDI_FAILURE);
break;
case DDI_INTROP_CLRMASK:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
return (DDI_FAILURE);
break;
case DDI_INTROP_GETPENDING:
if (psm_intr_ops == NULL)
return (DDI_FAILURE);
result)) {
*(int *)result = 0;
return (DDI_FAILURE);
}
break;
case DDI_INTROP_NAVAIL:
case DDI_INTROP_NINTRS:
if (*(int *)result == 0) {
return (DDI_FAILURE);
}
break;
break;
default:
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
static void
{
vendor[3] = 0;
}
/*
* Name a child
*/
static int
{
char vendor[8];
int device;
int func;
int bustype;
int proplen;
int pnpisa = 0;
/*
* older drivers aren't expecting the "standard" device
* node format used by the hardware nodes. these drivers
* only expect their own properties set in their driver.conf
* files. so they tell us not to call them with hardware
* nodes by setting the property "ignore-hardware-nodes".
*/
if (old_driver(child))
return (DDI_FAILURE);
/*
* Fill in parent-private data
*/
struct ddi_parent_private_data *pdptr;
}
if (ndi_dev_is_persistent_node(child) == 0) {
/*
* For .conf nodes, generate name from parent private data
*/
name[0] = '\0';
if (sparc_pd_getnreg(child) > 0) {
}
return (DDI_SUCCESS);
}
/*
* For hw nodes, look up "reg" property
*/
return (DDI_FAILURE);
}
/*
* extract the device identifications
*/
if (pnpisa) {
if (func != 0)
else
} else {
}
/*
* free the memory allocated by ddi_getlongprop().
*/
return (DDI_SUCCESS);
}
static int
{
char name[80];
return (DDI_FAILURE);
if (ndi_dev_is_persistent_node(child) != 0)
return (DDI_SUCCESS);
/*
* This is a .conf node, try merge properties onto a
* hw node with the same name.
*/
/*
* Return failure to remove node
*/
return (DDI_FAILURE);
}
/*
* Cannot merge node, permit pseudo children
*/
return (DDI_SUCCESS);
}
/*
* called when ACPI enumeration is not used
*/
static void
add_known_used_resources(void)
{
/* needs to be in increasing order */
int dma[] = {0x2};
0x778, 0x4};
}
(void) ndi_devi_bind_driver(usedrdip, 0);
}
static void
{
static int alloced = 0;
int circ, i;
/* hard coded isa stuff */
{1, 0x3f8, 0x8},
{1, 0x2f8, 0x8}
};
struct regspec i8042_regs[] = {
{1, 0x60, 0x1},
{1, 0x64, 0x1}
};
char *acpi_prop;
if (alloced)
return;
if (alloced) { /* just in case we are multi-threaded */
return;
}
alloced = 1;
}
if (acpi_enum) {
if (acpi_isa_device_enum(isa_dip)) {
if (isa_resource_setup() != NDI_SUCCESS) {
"resource setup failed");
}
/* serial ports? */
/* adjust parallel port size */
return;
}
}
/* serial ports */
for (i = 0; i < 2; i++) {
#if defined(__xpv)
/*
* the hypervisor may be reserving the serial ports for console
* available.
*/
if (ec_probe_pirq(asy_intrs[i]) == 0)
continue; /* in use */
#endif
"interrupts", asy_intrs[i]);
(void) ndi_devi_bind_driver(xdip, 0);
}
/* i8042 node */
"unit-address", "1,60");
(void) ndi_devi_bind_driver(xdip, 0);
}
/*
* On some machines, serial port 2 isn't listed in the ACPI table.
* This function goes through the BIOS data area and makes sure all
* the serial ports there are in the dev_info tree. If any are missing,
* this function will add them.
*/
static void
{
int i;
int found;
int ret;
int tmpregs_len;
static struct regspec tmp_asy_regs[] = {
{1, 0x3f8, 0x8},
};
/*
* The first four 2-byte quantities of the BIOS data area contain
* the base I/O addresses of the first four serial ports.
*/
for (i = 0; i < num_BIOS_serial; i++) {
if (bios_data[i] == 0) {
/* no COM[i]: port */
continue;
}
/* Look for it in the dev_info tree */
found = 0;
/* skip non asy */
continue;
}
/* Match by addr */
(uint_t *)&tmpregs_len);
if (ret != DDI_PROP_SUCCESS) {
/* error */
continue;
}
found = 1;
/*
* Free the memory allocated by
* ddi_prop_lookup_int_array().
*/
}
/* If not found, then add it */
if (!found) {
"compatible", "PNP0500");
/* This should be gotten from master file: */
"model", "Standard PC COM port");
"interrupts", default_asy_intrs[i]);
(void) ndi_devi_bind_driver(xdip, 0);
sizeof (struct regspec));
}
}
#if defined(__xpv)
/*
* Check each serial port to see if it is in use by the hypervisor.
* If it is in use, then remove the node from the device tree.
*/
i = 0;
int asy_intr;
/* skip non asy */
continue;
}
/*
* Check if the hypervisor is using the serial port by probing
* the irq and if it is using it remove the node
* from the device tree
*/
if (asy_intr == -1) {
/* error */
continue;
}
if (ec_probe_pirq(asy_intr)) {
continue;
}
if (ret != DDI_SUCCESS)
"could not remove asy%d node", i);
else
" to hypervisor", i);
i++;
}
#endif /* __xpv */
}
/*
* Some machine comes with an illegal parallel port size of 3
* bytes in ACPI, even parallel port mode is ECP.
*/
#define DEFAULT_PRT_SIZE 8
static void
{
char *name;
continue; /* skip non parallel */
continue;
for (i = 0; i < nreg; i++) {
continue;
}
}
}