/*
* 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 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#define PSMI_1_7
#include <sys/machlock.h>
#include <sys/smp_impldefs.h>
#include <sys/psm_common.h>
#include <sys/archsystm.h>
#include <sys/mach_intr.h>
#include <sys/hypervisor.h>
#include <sys/evtchn_impl.h>
/*
* Global Data
*/
int xen_uppc_enable_acpi = 0;
/*
* For interrupt link devices, if xen_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.
*/
/*
* For interrupt link devices, if xen_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 xen_uppc_verbose = 0;
/* flag definitions for xen_uppc_verbose */
/*
* Contains SCI irqno from FADT after initialization
*/
/*
* Local support routines
*/
static int
xen_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
*/
xen_uppc_sci = sci;
return (0);
}
return (1);
}
/*
* Autoconfiguration Routines
*/
static int
xen_uppc_probe(void)
{
return (PSM_SUCCESS);
}
static void
xen_uppc_softinit(void)
{
int i;
/* LINTED logical expression always true: op "||" */
if (DOMAIN_IS_INITDOMAIN(xen_info)) {
if (xen_uppc_use_acpi && xen_uppc_init_acpi()) {
for (i = 0; i <= MAX_ISA_IRQ; i++)
xen_uppc_irq_shared_table[i] = 0;
xen_uppc_enable_acpi = 1;
}
}
}
/*ARGSUSED*/
static int
{
extern int dosynctodr;
/*
* domU cannot set the TOD hardware, fault the TOD clock now to
* indicate that and turn off attempts to sync TOD hardware
* with the hires timer.
*/
if (!DOMAIN_IS_INITDOMAIN(xen_info)) {
(void) tod_fault(TOD_RDONLY, 0);
dosynctodr = 0;
}
/*
* The hypervisor provides a timer based on the local APIC timer.
* The interface supports requests of nanosecond resolution.
* A common frequency of the apic clock is 100 Mhz which
* gives a resolution of 10 nsec per tick. What we would really like
* is a way to get the ns per tick value from xen.
* XXPV - This is an assumption that needs checking and may change
*/
return (XEN_NSEC_PER_TICK);
}
static void
{
int irqno;
if (DOMAIN_IS_INITDOMAIN(xen_info)) {
#if 0
/* hypervisor initializes the 8259, don't mess with it */
picsetup(); /* initialise the 8259 */
#endif
/*
* We never called xen_uppc_addspl() when the SCI
* interrupt was added because that happened before the
* PSM module was loaded. Fix that up here by doing
* any missed operations (e.g. bind to CPU)
*/
if ((irqno = xen_uppc_sci) >= 0) {
}
}
}
/*ARGSUSED*/
static int
{
/*
* We are called at splhi() so we can't call anything that might end
* up trying to context switch.
*/
CPUSET_ADD(cpus, 0);
} else {
/*
*/
CPUSET_ADD(cpus, 0);
}
return (ret);
}
/*ARGSUSED*/
static int
{
if (max_ipl == PSM_INVALID_IPL) {
/*
*/
(void) ec_block_irq(irqno);
} else {
/*
* If still in use reset priority
*/
}
} else {
(void) ec_block_irq(irqno);
}
return (err);
}
static processorid_t
{
if (id == -1)
return (0);
return (-1);
}
/*ARGSUSED*/
static int
{
if (xen_clock_irq != -1)
return (xen_clock_irq);
return (xen_clock_irq);
}
/*ARGSUSED*/
static void
{
switch (cmd) {
case A_SHUTDOWN:
switch (fcn) {
case AD_BOOT:
case AD_IBOOT:
(void) HYPERVISOR_shutdown(SHUTDOWN_reboot);
break;
case AD_POWEROFF:
/* fall through if domU or if poweroff fails */
if (DOMAIN_IS_INITDOMAIN(xen_info))
if (xen_uppc_enable_acpi)
(void) acpi_poweroff();
/* FALLTHRU */
case AD_HALT:
default:
(void) HYPERVISOR_shutdown(SHUTDOWN_poweroff);
break;
}
break;
case A_REBOOT:
(void) HYPERVISOR_shutdown(SHUTDOWN_reboot);
break;
default:
return;
}
}
/*
* This function will reprogram the timer.
*
* When in oneshot mode the argument is the absolute time in future at which to
* generate the interrupt.
*
* When in periodic mode, the argument is the interval at which the
* interrupts should be generated. There is no need to support the periodic
* mode timer change at this time.
*
* Note that we must be careful to convert from hrtime to Xen system time (see
* xpv_timestamp.c).
*/
static void
{
flags = intr_clear();
/*
* We should be called from high PIL context (CBE_HIGH_PIL),
* so kpreempt is disabled.
*/
now = xpv_gethrtime();
xen_time = xpv_getsystime();
/*
* requested to generate an interrupt in the past
* generate an interrupt as soon as possible
*/
} else
if (HYPERVISOR_set_timer_op(timer_new) != 0)
panic("can't set hypervisor timer?");
}
/*
* This function will enable timer interrupts.
*/
static void
xen_uppc_timer_enable(void)
{
}
/*
* This function will disable timer interrupts on the current cpu.
*/
static void
xen_uppc_timer_disable(void)
{
(void) ec_block_irq(xen_clock_irq);
/*
* If the clock irq is pending on this cpu then we need to
* clear the pending interrupt.
*/
}
/*
* 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 xen_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
{
== 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);
}
dipintr_flagp) == ACPI_PSM_SUCCESS) &&
(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 (xen_uppc_reserved_irqlist[irq])
continue;
if (xen_uppc_irq_shared_table[irq] == 0) {
chosen_irq = irq;
foundnow = 1;
if (!(xen_uppc_prefer_crs) ||
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);
}
ddi_get_instance(dip)));
/*
* 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);
}
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);
}
/*ARGSUSED*/
static int
{
" dip = NULL\n", irqno));
return (irqno);
}
if (!xen_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);
"new irq %d old irq %d device %s, instance %d\n",
ddi_get_instance(dip)));
/*
* 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);
}
/*
* xen_uppc_intr_enter() acks the event that triggered the interrupt and
* returns the new priority level,
*/
/*ARGSUSED*/
static int
{
int newipl;
if (newipl == 0) {
/*
* (newipl == 0) means we have no service routines for this
* vector. We will treat this as a spurious interrupt.
* We have cleared the pending bit already, clear the event
* mask and return a spurious interrupt. This case can happen
* when an interrupt delivery is racing with the removal of
* of the service routine for that interrupt.
*/
/*
* (newipl <= cpu->cpu_pri) means that we must be trying to
* service a vector that was shared with a higher priority
* isr. The higher priority handler has been removed and
* we need to service this int. We can't return a lower
* priority than current cpu priority. Just synthesize a
* priority to return that should be acceptable.
*/
}
return (newipl);
}
static void xen_uppc_setspl(int);
/*
* xen_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
{
}
psm_intr_exit_fn(void)
{
return (xen_uppc_intr_exit);
}
/*
* Check if new ipl level allows delivery of previously unserviced events
*/
static void
{
/*
* If new ipl level will enable any pending interrupts, setup so the
* upcoming sti will cause us to get an upcall.
*/
if (pending) {
int i;
}
}
/*
* The rest of the file is just generic psm module boilerplate
*/
xen_uppc_probe, /* psm_probe */
xen_uppc_softinit, /* psm_init */
xen_uppc_picinit, /* psm_picinit */
xen_uppc_intr_enter, /* psm_intr_enter */
xen_uppc_intr_exit, /* psm_intr_exit */
xen_uppc_setspl, /* psm_setspl */
xen_uppc_addspl, /* psm_addspl */
xen_uppc_delspl, /* psm_delspl */
(int (*)(int))NULL, /* psm_softlvl_to_irq */
(void (*)(int))NULL, /* psm_set_softintr */
xen_uppc_clkinit, /* psm_clkinit */
xen_uppc_get_clockirq, /* psm_get_clockirq */
(void (*)(void))NULL, /* psm_hrtimeinit */
xpv_gethrtime, /* psm_gethrtime */
xen_uppc_get_next_processorid, /* psm_get_next_processorid */
(int (*)(void))NULL, /* psm_post_cpu_start */
xen_uppc_shutdown, /* psm_shutdown */
(int (*)(int, int))NULL, /* psm_get_ipivect */
xen_uppc_translate_irq, /* psm_translate_irq */
(void (*)(int, char *))NULL, /* psm_notify_error */
xen_uppc_timer_reprogram, /* psm_timer_reprogram */
xen_uppc_timer_enable, /* psm_timer_enable */
xen_uppc_timer_disable, /* psm_timer_disable */
(void (*)(int, int))NULL, /* psm_preshutdown */
(int (*)(dev_info_t *, ddi_intr_handle_impl_t *,
};
PSM_INFO_VER01_5, /* version */
PSM_OWN_SYS_DEFAULT, /* ownership */
&xen_uppc_ops, /* operation */
"xVM_uppc", /* machine name */
"UniProcessor PC" /* machine descriptions */
};
static void *xen_uppc_hdlp;
int
_init(void)
{
}
int
_fini(void)
{
}
int
{
}