uppc.c revision 0f2cfdbb2dd724b1f649ce31d87b7964153dc0bc
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#define PSMI_1_5
#include <sys/machlock.h>
#include <sys/smp_impldefs.h>
#include <sys/psm_common.h>
#include <sys/archsystm.h>
#define NSEC_IN_SEC 1000000000
/*
* Local Function Prototypes
*/
static void uppc_softinit(void);
static void uppc_picinit();
static int uppc_clkinit(int);
static int uppc_get_clockirq(int ipl);
static int uppc_probe(void);
static int uppc_init_acpi(void);
static void uppc_setspl(int);
static int uppc_intr_enter(int, int *);
static void uppc_intr_exit(int, int);
static hrtime_t uppc_gethrtime();
/*
* Global Data
*/
static struct standard_pic pics0;
int uppc_enable_acpi = 0;
/*
* For interrupt link devices, if uppc_unconditional_srs is set, an irq resource
* will be assigned (via _SRS). If it is not set, use the current
* irq setting (via _CRS), but only if that irq is in the set of possible
* irqs (returned by _PRS) for the device.
*/
int uppc_unconditional_srs = 1;
/*
* For interrupt link devices, if uppc_prefer_crs is set when we are
* assigning an IRQ resource to a device, prefer the current IRQ setting
* over other possible irq settings under same conditions.
*/
int uppc_prefer_crs = 1;
int uppc_verbose = 0;
/* flag definitions for uppc_verbose */
#define UPPC_VERBOSE_IRQ_FLAG 0x00000001
#define UPPC_VERBOSE_POWEROFF_FLAG 0x00000002
#define UPPC_VERBOSE_POWEROFF_PAUSE_FLAG 0x00000004
#define UPPC_VERBOSE_IRQ(fmt) \
if (uppc_verbose & UPPC_VERBOSE_IRQ_FLAG) \
#define UPPC_VERBOSE_POWEROFF(fmt) \
if (uppc_verbose & UPPC_VERBOSE_POWEROFF_FLAG) \
/*
* Contains SCI irqno from FADT after initialization
*/
static int uppc_sci = -1;
/*
* Local Static Data
*/
static lock_t uppc_gethrtime_lock;
static hrtime_t uppc_lasthrtime;
#ifdef UPPC_DEBUG
#define DENT 0x0001
static int uppc_debug = 0;
#endif
uppc_probe, /* psm_probe */
uppc_softinit, /* psm_init */
uppc_picinit, /* psm_picinit */
uppc_intr_enter, /* psm_intr_enter */
uppc_intr_exit, /* psm_intr_exit */
uppc_setspl, /* psm_setspl */
uppc_addspl, /* psm_addspl */
uppc_delspl, /* psm_delspl */
(int (*)(int))NULL, /* psm_softlvl_to_irq */
(void (*)(int))NULL, /* psm_set_softintr */
uppc_clkinit, /* psm_clkinit */
uppc_get_clockirq, /* psm_get_clockirq */
(void (*)(void))NULL, /* psm_hrtimeinit */
uppc_gethrtime, /* psm_gethrtime */
uppc_get_next_processorid, /* psm_get_next_processorid */
(int (*)(void))NULL, /* psm_post_cpu_start */
uppc_shutdown, /* psm_shutdown */
(int (*)(int, int))NULL, /* psm_get_ipivect */
uppc_translate_irq, /* psm_translate_irq */
(void (*)(int, char *))NULL, /* psm_notify_error */
(void (*)(void))NULL, /* psm_timer_enable */
(void (*)(void))NULL, /* psm_timer_disable */
uppc_preshutdown, /* psm_preshutdown */
(int (*)(dev_info_t *, ddi_intr_handle_impl_t *,
};
PSM_INFO_VER01_5, /* version */
PSM_OWN_SYS_DEFAULT, /* ownership */
"uppc", /* machine name */
"UniProcessor PC", /* machine descriptions */
};
/*
* Configuration Data
*/
/*
* This is the loadable module wrapper.
*/
static void *uppc_hdlp;
int
_init(void)
{
}
int
_fini(void)
{
}
int
{
}
/*
* Autoconfiguration Routines
*/
static int
uppc_probe(void)
{
return (PSM_SUCCESS);
}
static void
uppc_softinit(void)
{
struct standard_pic *pp;
int i;
if (uppc_use_acpi && uppc_init_acpi()) {
for (i = 0; i <= MAX_ISA_IRQ; i++)
uppc_irq_shared_table[i] = 0;
uppc_enable_acpi = 1;
}
/*
* initialize the ipl mask
*/
/* enable slave lines on master */
}
}
/*ARGSUSED*/
static int
uppc_clkinit(int hertz)
{
if (hertz == 0)
return (0); /* One shot mode not supported */
/*
* program timer 0
*/
return (NSEC_IN_SEC / hertz);
}
static void
{
picsetup();
/*
* If a valid SCI is present, manually addspl()
* since we're not set-up early enough in boot
* to do it "conventionally" (via add_avintr)
*/
if (uppc_sci >= 0)
}
/*ARGSUSED3*/
static int
{
struct standard_pic *pp;
int i;
int startidx;
if (irqno <= MAX_ISA_IRQ)
return (0);
if (irqno > 7) {
} else {
}
/*
* mask intr same or above ipl
* level MAXIPL has all intr off as init. default
*/
break;
}
/*
* unmask intr below ipl
*/
break;
}
return (0);
}
static int
{
struct standard_pic *pp;
int i;
if (irqno <= MAX_ISA_IRQ)
/*
* skip if we are not deleting the last handler
* and the ipl is higher than minimum
*/
return (0);
if (irqno > 7) {
i = 0;
} else {
i = 1;
}
/*
* check any handlers left for this irqno
*/
if (max_ipl != PSM_INVALID_IPL) {
/*
* unmasks all levels below the lowest priority
*/
for (; i >= 0; i -= 2) {
break;
}
} else {
/*
* set mask to all levels
*/
break;
}
}
return (0);
}
static processorid_t
{
if (cpu_id == -1)
return (0);
return (-1);
}
/*ARGSUSED*/
static int
uppc_get_clockirq(int ipl)
{
return (CLOCK_VECTOR);
}
static int
uppc_init_acpi(void)
{
int verboseflags = 0;
int sci;
/*
* Process SCI configuration here; this may return
* an error if acpi-user-options has specified
* legacy mode (use ACPI without ACPI mode or SCI)
*/
sci = -1;
/*
* Initialize sub-system - if error is returns, ACPI is not
* used.
*/
if (acpica_init() != AE_OK)
return (0);
/*
* via ELCR based on return value from get_sci; this
* as recommended by Intel ACPI CA team.
*/
if (sci >= 0) {
}
/*
* Remember SCI for later use
*/
return (0);
}
return (1);
}
static void
{
}
static void
{
/*
* Return if passed a command other than A_SHUTDOWN or
* if we're not using ACPI.
*/
return;
/* switch system back into Legacy Mode */
(void) AcpiDisable();
if (fcn != AD_POWEROFF)
return;
(void) acpi_poweroff();
}
static int
{
int status;
intr_flagp)) == ACPI_PSM_SUCCESS) {
"from cache for device %s, instance #%d\n", *pci_irqp,
return (status);
}
" acpi_translate_pci_irq failed for device %s, instance"
return (status);
}
if (status != ACPI_PSM_SUCCESS) {
}
}
if (status == ACPI_PSM_SUCCESS) {
intr_flagp, &acpipsmlnk);
"new irq %d for device %s, instance #%d\n",
}
return (status);
}
/*
* Configures the irq for the interrupt link device identified by
* acpipsmlnkp.
*
* Gets the current and the list of possible irq settings for the
* device. If uppc_unconditional_srs is not set, and the current
* resource setting is in the list of possible irq settings,
* current irq resource setting is passed to the caller.
*
* Otherwise, picks an irq number from the list of possible irq
* settings, and sets the irq of the device to this value.
* If prefer_crs is set, among a set of irq numbers in the list that have
* the least number of devices sharing the interrupt, we pick current irq
* resource setting if it is a member of this set.
*
* Passes the irq number in the value pointed to by pci_irqp, and
* polarity and sensitivity in the structure pointed to by dipintrflagp
* to the caller.
*
* Note that if setting the irq resource failed, but successfuly obtained
* the current irq resource settings, passes the current irq resources
* and considers it a success.
*
* Returns:
* ACPI_PSM_SUCCESS on success.
*
* ACPI_PSM_FAILURE if an error occured during the configuration or
* if a suitable irq was not found for this device, or if setting the
* irq resource and obtaining the current resource fails.
*
*/
static int
{
int cur_irq = -1;
== ACPI_PSM_FAILURE) {
"or assign IRQ for device %s, instance #%d: The system was "
"unable to get the list of potential IRQs from ACPI.",
return (ACPI_PSM_FAILURE);
}
(cur_irq > 0)) {
== ACPI_PSM_SUCCESS) {
return (ACPI_PSM_SUCCESS);
}
"current irq %d for device %s, instance #%d in ACPI's "
"list of possible irqs for this device. Picking one from "
ddi_get_instance(dip)));
}
min_share = 255;
while (irqlistent != NULL) {
if ((irq > MAX_ISA_IRQ) ||
(irq == 0))
continue;
if (uppc_reserved_irqlist[irq])
continue;
if (uppc_irq_shared_table[irq] == 0) {
chosen_irq = irq;
foundnow = 1;
done = 1;
break;
}
}
foundnow = 1;
}
}
/* If we found an IRQ in the inner loop, save the details */
/*
* Copy the acpi_prs_private_t and flags from this
* irq list entry, since we found an irq from this
* entry.
*/
}
if (done)
break;
/* Load the next entry in the irqlist */
}
if (chosen_irq != -1)
irq = chosen_irq;
else if (share_irq != -1)
else {
"suitable irq from the list of possible irqs for device "
"%s, instance #%d in ACPI's list of possible\n",
return (ACPI_PSM_FAILURE);
}
/*
* setting irq was successful, check to make sure CRS
* reflects that. If CRS does not agree with what we
* set, return the irq that was set.
*/
dipintr_flagp) == ACPI_PSM_SUCCESS) {
"IRQ resource set (irqno %d) for device %s "
"instance #%d, differs from current "
"setting irqno %d",
}
/*
* return the irq that was set, and not what CRS reports,
* since CRS has been seen to be bogus on some systems
*/
} else {
"failed for device %s instance #%d",
if (cur_irq == -1)
return (ACPI_PSM_FAILURE);
}
return (ACPI_PSM_SUCCESS);
}
/*ARGSUSED*/
static int
{
char dev_type[16];
" dip = NULL\n", irqno));
return (irqno);
}
if (!uppc_enable_acpi) {
return (irqno);
}
&dev_len) != DDI_PROP_SUCCESS) {
"device %s instance %d no device_type\n", irqno,
return (irqno);
}
/* pci device */
return (irqno);
return (irqno);
"%d old irq %d device %s, instance %d\n", pci_irq,
/*
* Make sure pci_irq is within range.
* Otherwise, fall through and return irqno.
*/
if (pci_irq <= MAX_ISA_IRQ) {
/*
* Update the device's ILINE byte,
* in case uppc_acpi_translate_pci_irq
* has choosen a different pci_irq
* than the BIOS has configured.
* Some chipsets use the value in
* ILINE to control interrupt routing,
* in conflict with the PCI spec.
*/
}
return (pci_irq);
}
}
/* FALLTHRU to common case - returning irqno */
} else {
/* non-PCI; assumes ISA-style edge-triggered */
"irqno %d device %s instance %d\n", irqno,
}
return (irqno);
}
/*
* uppc_intr_enter() raises the ipl to the level of the current interrupt,
* and sends EOI to the pics.
* If interrupt is 7 or 15 and not spurious interrupt, send specific EOI
* else send non-specific EOI
* uppc_intr_enter() returns the new priority level,
* or -1 for spurious interrupt
*/
static int
{
int newipl;
int intno;
/*
* During wait_till_seen() periods when interrupt vector is being
* removed in remove_av(), the removed hardware interrupt could
* trigger and got here with newipl 0. It has to send EOI
* as usual but no need to call setspl and returns -1 like spurious.
*/
if (newipl)
if (intno >= 8) {
}
} else { /* int was 7 or 15 */
if (intno != 7)
return (-1); /* Spurious int */
} else {
if (newipl)
if (intno != 7) {
} else {
}
}
}
if (newipl)
return (newipl);
else
return (-1); /* not real spurious int */
}
/*
* uppc_intr_exit() restores the old interrupt
* priority level after processing an interrupt.
* It is called with interrupts disabled, and does not enable interrupts.
*/
/* ARGSUSED */
static void
{
}
/*
* uppc_setspl() loads new interrupt masks into the pics
* based on input ipl.
*/
/* ARGSUSED */
static void
uppc_setspl(int ipl)
{
struct standard_pic *pp;
return;
/*
* program new slave pic mask
*/
}
/*
* program new master pic mask
*/
}
/*
* read master to allow pics to settle
*/
}
/*
* uppc_gethrtime() returns high resolution timer value
*/
static hrtime_t
{
unsigned int ctr0;
temp = hrtime_base;
/*
* read counter 0
*/
if (temp != hrtime_base)
goto retry;
if (timeval < uppc_lasthrtime)
return (timeval);
}