/*
* 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 2014 Garrett D'Amore <garrett@damore.org>
* Copyright (c) 2012 Gary Mills
*/
/*
* ISA bus nexus driver
*/
#include <sys/autoconf.h>
#include <sys/ddidmareq.h>
#include <sys/ddi_impldefs.h>
#include <sys/ddi_subrdefs.h>
#include <sys/dma_engine.h>
#include <sys/mach_intr.h>
#include <sys/boot_console.h>
#if defined(__xpv)
#include <sys/hypervisor.h>
#include <sys/evtchn_impl.h>
extern int console_hypervisor_dev_type(int *);
#endif
extern int pseudo_isa;
extern int isa_resource_setup(void);
psm_intr_op_t, int *);
static void isa_enumerate(int);
static void enumerate_BIOS_serial(dev_info_t *);
static void isa_create_ranges_prop(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_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.
*/
static int isa_extra_count = 0;
/* Register definitions for COM1 to COM4. */
{1, 0x3f8, 0x8},
{1, 0x2f8, 0x8},
{1, 0x3e8, 0x8},
{1, 0x2e8, 0x8}
};
/* Serial port interrupt vectors for COM1 to COM4. */
/* Bitfield indicating which interrupts are overridden by eeprom config */
/*
* Local data
*/
(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
NULL,
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 */
};
&modldrv,
};
int
_init(void)
{
int err;
char *tty_irq;
int i;
return (err);
/* Check if any tty irqs are overridden by eeprom config */
for (i = 0; i < num_BIOS_serial; i++) {
== DDI_PROP_SUCCESS) {
long data;
asy_intr_override |= 1<<i;
}
}
}
return (0);
}
int
_fini(void)
{
int err;
return (err);
return (0);
}
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);
}
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.
*/
return (DDI_ME_REGSPEC_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_GETATTR:
return (DDI_SUCCESS);
case DDI_DMA_E_1STPTY:
{
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
if (arg == 0) {
} else {
}
}
default:
/*
* We pass to rootnex, but it turns out that rootnex will just
* return failure, as we don't use ddi_dma_mctl() except
* for DMA engine (ISA) and DVMA (SPARC). Arguably we could
* just return an error direclty here, instead.
*/
}
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
{
return (0);
}
/*
* free the memory allocated by ddi_getlongprop().
*/
if (pnpisa)
return (1);
else
return (0);
}
/*ARGSUSED*/
static int
{
int rn;
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:
return (DDI_SUCCESS);
/*
* 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 defined(__xpv)
#endif
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:
case DDI_INTROP_FREE:
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);
#if defined(__xpv)
/*
* if the hypervisor is using an isa serial port for the
* console, make sure we don't try to use that interrupt as
* it will cause us to panic when xen_bind_pirq() fails.
*/
return (DDI_FAILURE);
#endif
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);
}
/*
* Allocate interrupt vector for FIXED (legacy) type.
*/
static int
void *result)
{
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 (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);
}
/*
* Free up interrupt vector for FIXED (legacy) type.
*/
static int
{
int ret;
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.
*/
return (DDI_FAILURE);
} else {
/*
* No APIX module; fall back to the old scheme where
* the interrupt vector was already freed during
* ddi_disable_intr() call.
*/
ret = DDI_SUCCESS;
}
return (ret);
}
static void
{
vendor[3] = 0;
}
/*
* Name a child
*/
static int
{
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
*/
}
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
{
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 */
0x778, 0x4};
}
(void) ndi_devi_bind_driver(usedrdip, 0);
}
/*
* Return non-zero if UART device exists.
*/
static int
{
}
static void
{
int circ, i;
{1, 0x60, 0x1},
{1, 0x64, 0x1}
};
char *acpi_prop;
#if defined(__xpv)
#endif
return;
}
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 < min_BIOS_serial; i++) {
if (!uart_exists(addr))
continue;
#if defined(__xpv)
continue;
#endif
"compatible", "PNP0500");
/* This should be gotten from master file: */
"model", "Standard PC COM port");
"interrupts", asy_intrs[i]);
(void) ndi_devi_bind_driver(xdip, 0);
/* Adjusting isa_extra here causes a kernel dump later. */
}
/* 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 base I/O addresses 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;
#if defined(__xpv)
#endif
/*
* Scan the base I/O addresses of the first four serial ports.
*/
for (i = 0; i < num_BIOS_serial; i++) {
/* 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 (found) {
if (asy_intr_override & 1<<i) {
(void) ndi_prop_update_int(
"interrupts", asy_intrs[i]);
}
break;
}
}
/* If not found, then add it */
"compatible", "PNP0500");
/* This should be gotten from master file: */
"model", "Standard PC COM port");
"interrupts", asy_intrs[i]);
(void) ndi_devi_bind_driver(xdip, 0);
sizeof (struct regspec));
}
}
/*
* An asy node may have been attached via ACPI enumeration, or
* directly from this file. 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.
*/
#if defined(__xpv)
i = 0;
continue;
if (ret != DDI_SUCCESS) {
"could not remove asy%d node", i);
}
" to hypervisor", i);
}
i++;
}
#endif
}
/*
* Some machine comes with an illegal parallel port size of 3
* bytes in ACPI, even parallel port mode is ECP.
*/
static void
{
char *name;
continue; /* skip non parallel */
continue;
for (i = 0; i < nreg; i++) {
continue;
}
}
}