/*
* 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.
*/
#include <sys/ddi_impldefs.h>
#include <sys/sysmacros.h>
#include <sys/autoconf.h>
#include <sys/machsystm.h>
#include <vm/seg_kmem.h>
#include <vm/hat_sfmmu.h>
#include <sys/promimpl.h>
#include <sys/prom_plat.h>
#include <sys/nexusdebug.h>
#include <sys/ddi_subrdefs.h>
#include <sys/ddi_implfuncs.h>
#ifndef TRUE
#endif
#ifndef FALSE
#define FALSE (0)
#endif
/*
* Function to register and deregister callbacks, for sunfire only.
*/
/*
* This table represents the FHC interrupt priorities. They range from
* 1-15, and have been modeled after the sun4d interrupts. The mondo
* number anded with 0x7 is used to index into this table. This was
* done to save table space.
*/
static int fhc_int_priorities[] = {
PIL_15, /* System interrupt priority */
PIL_12, /* zs interrupt priority */
PIL_15, /* TOD interrupt priority */
PIL_15 /* Fan Fail priority */
};
static void fhc_cpu_shutdown_self(void);
static void os_completes_shutdown(void);
/*
* or by boot -h so that the calibration tables are not used. This
* is useful for checking thermistors whose output seems to be incorrect.
*/
static int dont_calibrate = 0;
/* Only one processor should powerdown the system. */
static int powerdown_started = 0;
/* Let user disable overtemp powerdown. */
/*
* The following tables correspond to the degress Celcius for each count
* value possible from the 8-bit A/C convertors on each type of system
* board for the UltraSPARC Server systems. To access a temperature,
* just index into the correct table using the count from the A/D convertor
* register, and that is the correct temperature in degress Celsius. These
* values can be negative.
*/
static short cpu_table[] = {
-16, -14, -12, -10, -8, -6, -4, -2, /* 0-7 */
1, 4, 6, 8, 10, 12, 13, 15, /* 8-15 */
16, 18, 19, 20, 22, 23, 24, 25, /* 16-23 */
26, 27, 28, 29, 30, 31, 32, 33, /* 24-31 */
34, 35, 35, 36, 37, 38, 39, 39, /* 32-39 */
40, 41, 41, 42, 43, 44, 44, 45, /* 40-47 */
46, 46, 47, 47, 48, 49, 49, 50, /* 48-55 */
51, 51, 52, 53, 53, 54, 54, 55, /* 56-63 */
55, 56, 56, 57, 57, 58, 58, 59, /* 64-71 */
60, 60, 61, 61, 62, 62, 63, 63, /* 72-79 */
64, 64, 65, 65, 66, 66, 67, 67, /* 80-87 */
68, 68, 69, 69, 70, 70, 71, 71, /* 88-95 */
72, 72, 73, 73, 74, 74, 75, 75, /* 96-103 */
76, 76, 77, 77, 78, 78, 79, 79, /* 104-111 */
80, 80, 81, 81, 82, 82, 83, 83, /* 112-119 */
84, 84, 85, 85, 86, 86, 87, 87, /* 120-127 */
88, 88, 89, 89, 90, 90, 91, 91, /* 128-135 */
92, 92, 93, 93, 94, 94, 95, 95, /* 136-143 */
96, 96, 97, 98, 98, 99, 99, 100, /* 144-151 */
100, 101, 101, 102, 103, 103, 104, 104, /* 152-159 */
105, 106, 106, 107, 107, 108, 109, 109, /* 160-167 */
110, /* 168 */
};
static short cpu2_table[] = {
-17, -16, -15, -14, -13, -12, -11, -10, /* 0-7 */
-9, -8, -7, -6, -5, -4, -3, -2, /* 8-15 */
-1, 0, 1, 2, 3, 4, 5, 6, /* 16-23 */
7, 8, 9, 10, 11, 12, 13, 13, /* 24-31 */
14, 15, 16, 16, 17, 18, 18, 19, /* 32-39 */
20, 20, 21, 22, 22, 23, 24, 24, /* 40-47 */
25, 25, 26, 26, 27, 27, 28, 28, /* 48-55 */
29, 30, 30, 31, 31, 32, 32, 33, /* 56-63 */
33, 34, 34, 35, 35, 36, 36, 37, /* 64-71 */
37, 37, 38, 38, 39, 39, 40, 40, /* 72-79 */
41, 41, 42, 42, 43, 43, 43, 44, /* 80-87 */
44, 45, 45, 46, 46, 46, 47, 47, /* 88-95 */
48, 48, 49, 49, 50, 50, 50, 51, /* 96-103 */
51, 52, 52, 53, 53, 53, 54, 54, /* 104-111 */
55, 55, 56, 56, 56, 57, 57, 58, /* 112-119 */
58, 59, 59, 59, 60, 60, 61, 61, /* 120-127 */
62, 62, 63, 63, 63, 64, 64, 65, /* 128-135 */
65, 66, 66, 67, 67, 68, 68, 68, /* 136-143 */
69, 69, 70, 70, 71, 71, 72, 72, /* 144-151 */
73, 73, 74, 74, 75, 75, 76, 76, /* 152-159 */
77, 77, 78, 78, 79, 79, 80, 80, /* 160-167 */
81, 81, 82, 83, 83, 84, 84, 85, /* 168-175 */
85, 86, 87, 87, 88, 88, 89, 90, /* 176-183 */
90, 91, 92, 92, 93, 94, 94, 95, /* 184-191 */
96, 96, 97, 98, 99, 99, 100, 101, /* 192-199 */
102, 103, 103, 104, 105, 106, 107, 108, /* 200-207 */
109, 110, /* 208-209 */
};
static short io_table[] = {
0, 0, 0, 0, 0, 0, 0, 0, /* 0-7 */
0, 0, 0, 0, 0, 0, 0, 0, /* 8-15 */
0, 0, 0, 0, 0, 0, 0, 0, /* 16-23 */
0, 0, 0, 0, 0, 0, 0, 0, /* 24-31 */
0, 0, 0, 0, 0, 0, 0, 0, /* 32-39 */
0, 3, 7, 10, 13, 15, 17, 19, /* 40-47 */
21, 23, 25, 27, 28, 30, 31, 32, /* 48-55 */
34, 35, 36, 37, 38, 39, 41, 42, /* 56-63 */
43, 44, 45, 46, 46, 47, 48, 49, /* 64-71 */
50, 51, 52, 53, 53, 54, 55, 56, /* 72-79 */
57, 57, 58, 59, 60, 60, 61, 62, /* 80-87 */
62, 63, 64, 64, 65, 66, 66, 67, /* 88-95 */
68, 68, 69, 70, 70, 71, 72, 72, /* 96-103 */
73, 73, 74, 75, 75, 76, 77, 77, /* 104-111 */
78, 78, 79, 80, 80, 81, 81, 82, /* 112-119 */
};
static short clock_table[] = {
0, 0, 0, 0, 0, 0, 0, 0, /* 0-7 */
0, 0, 0, 0, 1, 2, 4, 5, /* 8-15 */
7, 8, 10, 11, 12, 13, 14, 15, /* 16-23 */
17, 18, 19, 20, 21, 22, 23, 24, /* 24-31 */
24, 25, 26, 27, 28, 29, 29, 30, /* 32-39 */
31, 32, 32, 33, 34, 35, 35, 36, /* 40-47 */
37, 38, 38, 39, 40, 40, 41, 42, /* 48-55 */
42, 43, 44, 44, 45, 46, 46, 47, /* 56-63 */
48, 48, 49, 50, 50, 51, 52, 52, /* 64-71 */
53, 54, 54, 55, 56, 57, 57, 58, /* 72-79 */
59, 59, 60, 60, 61, 62, 63, 63, /* 80-87 */
64, 65, 65, 66, 67, 68, 68, 69, /* 88-95 */
70, 70, 71, 72, 73, 74, 74, 75, /* 96-103 */
76, 77, 78, 78, 79, 80, 81, 82, /* 104-111 */
};
/*
* System temperature limits.
*
* The following variables are the warning and danger limits for the
* different types of system boards. The limits are different because
* the various boards reach different nominal temperatures because
* of the different components that they contain.
*
* The warning limit is the temperature at which the user is warned.
* The danger limit is the temperature at which the system is shutdown.
* to offline and power down processors on a board in an attempt to
* bring the board back into the nominal temperature range before
* shutting down the system.
*
*/
/*
* This variable tells us if we are in a heat chamber. It is set
* early on in boot, after we check the OBP 'mfg-mode' property in
* the options node.
*/
/*
* The fhc memloc structure is protected under the bdlist lock
*/
/*
* Driver global fault list mutex and list head pointer. The list is
* protected by the mutex and contains a record of all known faults.
* Faults can be inherited from the PROM or detected by the kernel.
*/
static int ft_nfaults = 0;
/*
* Table of all known fault strings. This table is indexed by the fault
* type. Do not change the ordering of the table without redefining the
* fault type enum list on fhc.h.
*/
char *ft_str_table[] = {
"Core Power Supply", /* FT_CORE_PS */
"Overtemp", /* FT_OVERTEMP */
"AC Power", /* FT_AC_PWR */
"Peripheral Power Supply", /* FT_PPS */
"System 3.3 Volt Power", /* FT_CLK_33 */
"System 5.0 Volt Power", /* FT_CLK_50 */
"Peripheral 5.0 Volt Power", /* FT_V5_P */
"Peripheral 12 Volt Power", /* FT_V12_P */
"Auxiliary 5.0 Volt Power", /* FT_V5_AUX */
"Peripheral 5.0 Volt Precharge", /* FT_V5_P_PCH */
"Peripheral 12 Volt Precharge", /* FT_V12_P_PCH */
"System 3.3 Volt Precharge", /* FT_V3_PCH */
"System 5.0 Volt Precharge", /* FT_V5_PCH */
"Peripheral Power Supply Fans", /* FT_PPS_FAN */
"Rack Exhaust Fan", /* FT_RACK_EXH */
"Disk Drive Fan", /* FT_DSK_FAN */
"AC Box Fan", /* FT_AC_FAN */
"Key Switch Fan", /* FT_KEYSW_FAN */
"Minimum Power", /* FT_INSUFFICIENT_POWER */
"PROM detected", /* FT_PROM */
"Hot Plug Support System", /* FT_HOT_PLUG */
"TOD" /* FT_TODFAULT */
};
/*
* Function prototypes
*/
void *, void *);
static void
static int
static void fhc_add_kstats(struct fhc_soft_state *);
static int fhc_kstat_update(kstat_t *, int);
static int check_for_chamber(void);
static int ft_ks_snapshot(struct kstat *, void *, int);
static int ft_ks_update(struct kstat *, int);
static int check_central(int board);
/*
* board type and A/D convertor output passed in and real temperature
* is returned.
*/
/* Routine to determine if there are CPUs on this board. */
static int cpu_on_board(int);
static void build_bd_display_str(char *, enum board_type, int);
/* Interrupt distribution callback function. */
static void fhc_intrdist(void *);
/* CPU power control */
extern void halt(char *);
/*
* Configuration data structures
*/
ddi_bus_map, /* map */
0, /* get_intrspec */
0, /* add_intrspec */
0, /* remove_intrspec */
i_ddi_map_fault, /* map_fault */
ddi_no_dma_map, /* dma_map */
ddi_dma_mctl, /* dma_ctl */
fhc_ctlops, /* ctl */
ddi_bus_prop_op, /* prop_op */
0, /* (*bus_get_eventcookie)(); */
0, /* (*bus_add_eventcall)(); */
0, /* (*bus_remove_eventcall)(); */
0, /* (*bus_post_event)(); */
0, /* (*bus_intr_control)(); */
0, /* (*bus_config)(); */
0, /* (*bus_unconfig)(); */
0, /* (*bus_fm_init)(); */
0, /* (*bus_fm_fini)(); */
0, /* (*bus_fm_access_enter)(); */
0, /* (*bus_fm_access_exit)(); */
0, /* (*bus_power)(); */
fhc_intr_ops /* (*bus_intr_op)(); */
};
nulldev, /* open */
nulldev, /* close */
nulldev, /* strategy */
nulldev, /* print */
nulldev, /* dump */
nulldev, /* read */
nulldev, /* write */
nulldev, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* cb_prop_op */
0, /* streamtab */
CB_REV, /* rev */
nodev, /* cb_aread */
nodev /* cb_awrite */
};
DEVO_REV, /* rev */
0, /* refcnt */
ddi_no_info, /* getinfo */
nulldev, /* identify */
nulldev, /* probe */
fhc_attach, /* attach */
fhc_detach, /* detach */
nulldev, /* reset */
&fhc_cb_ops, /* cb_ops */
&fhc_bus_ops, /* bus_ops */
nulldev, /* power */
ddi_quiesce_not_needed, /* quiesce */
};
/*
* Driver globals
* TODO - We need to investigate what locking needs to be done here.
*/
extern struct mod_ops mod_driverops;
&mod_driverops, /* Type of module. This one is a driver */
"FHC Nexus", /* Name of module. */
&fhc_ops, /* driver ops */
};
MODREV_1, /* rev */
(void *)&modldrv,
};
/*
* These are the module initialization routines.
*/
int
_init(void)
{
int error;
sizeof (struct fhc_soft_state), 1)) != 0)
return (error);
return (mod_install(&modlinkage));
}
int
_fini(void)
{
int error;
return (error);
return (0);
}
int
{
}
/*
* Reset the interrupt mapping registers.
* This function resets the values during DDI_RESUME.
*
* NOTE: This function will not work for a full CPR cycle
* and is currently designed to handle the RESUME after a connect.
*
* Note about the PROM handling of moving CENTRAL to another board:
* The PROM moves the IGN identity (igr register) from the
* original CENTRAL to the new one. This means that we do not
* duplicate the fhc_attach code that sets it to (board number * 2).
* We rely on only using FHC interrupts from one board only
* (the UART and SYS interrupts) so that the values of the other IGNs
* are irrelevant. The benefit of this approach is that we don't
* have to have to tear down and rebuild the interrupt records
* for UART and SYS. It is also why we don't try to change the
* board number in the fhc instance for the clock board.
*/
static void
{
int i;
int cent;
if (softsp->is_central) {
#ifdef lint
#endif
/* We must now re-issue any pending interrupts. */
for (i = 0; i < FHC_MAX_INO; i++) {
tmp_reg =
#ifdef lint
#endif
}
}
}
return;
}
/* Loop through all 4 FHC interrupt mapping registers */
for (i = 0; i < FHC_MAX_INO; i++) {
if (i == FHC_SYS_INO &&
"found lost system interrupt, resetting..");
/*
* ensure atomic write with this read.
*/
#ifdef lint
#endif
}
/*
* The mapping registers on the board with the "central" bit
* set should not be touched as it has been taken care by POST.
*/
if (cent)
continue;
/*
* ensure atomic write with this read.
*/
#ifdef lint
#endif
}
}
static int
{
/*
* This is the value of AC configuration and status reg
* in the Local Devices space. We access it as a physical
* address.
*/
if (cs_value & AC_CENTRAL)
return (TRUE);
else
return (FALSE);
}
static int
{
int instance;
switch (cmd) {
case DDI_ATTACH:
break;
case DDI_RESUME:
/* IGR, NOT_BRD_PRES handled by prom */
/* reset interrupt mapping registers */
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
return (DDI_FAILURE);
/* Set the dip in the soft state */
goto bad;
return (DDI_SUCCESS);
bad:
return (DDI_FAILURE);
}
static int
{
int board;
int instance;
/* get the instance of this devi */
/* get the soft state pointer for this device node */
switch (cmd) {
case DDI_SUSPEND:
return (DDI_SUCCESS);
case DDI_DETACH:
/* grab the lock on the board list */
if (fhc_bd_detachable(board) &&
break;
else
/* FALLTHROUGH */
default:
return (DDI_FAILURE);
}
/* Remove the interrupt redistribution callback. */
/* remove the soft state pointer from the board list */
/* clear inherited faults from the PROM. */
/* remove the kstat for this board */
/* destroy the mutexes in this soft state structure */
/* unmap all the register sets */
/* release the board list lock now */
/* free the soft state structure */
return (DDI_SUCCESS);
}
static enum board_type
{
int proplen;
char *board_type;
if (softsp->is_central)
type = CLOCK_BOARD;
&proplen) == DDI_PROP_SUCCESS) {
/* match the board-type string */
== 0) {
type = IO_PCI_BOARD;
} else {
}
} else
/*
* if the board type is indeterminate, it must be determined.
*/
if (type == UNKNOWN_BOARD) {
/*
* Use the UPA64 bits from the FHC.
* This is not the best solution since we
* cannot fully type the IO boards.
*/
if (cpu_on_board(board))
else
}
return (type);
}
static void
{
}
}
0, 0);
}
0, 0);
}
0, 0);
}
0, 0);
}
}
static int
{
int i;
int board;
/*
* Map in the FHC registers. Specifying length and offset of
* zero maps in the entire OBP register set.
*/
/* map in register set 0 */
goto bad;
}
/*
* Fill in the virtual addresses of the registers in the
* fhc_soft_state structure.
*/
/* map in register set 1 */
goto bad;
}
/*
* map in register set 2
* XXX this can never be used as an interrupt generator
* (hardware queue overflow in fhc)
*/
0, 0)) {
goto bad;
}
/* map in register set 3 */
0, 0)) {
goto bad;
}
/* map in register set 4 */
0, 0)) {
goto bad;
}
/* map in register set 5 */
0, 0)) {
goto bad;
}
/* Loop over all intr sets and setup the VAs for the ISMR */
/* TODO - Make sure we are calculating the ISMR correctly. */
for (i = 0; i < FHC_MAX_INO; i++) {
/* Now clear the state machines to idle */
}
/*
* It is OK to not have a OBP_BOARDNUM property. This happens for
* the board which is a child of central. However this FHC
* still needs a proper Interrupt Group Number programmed
* into the Interrupt Group register, because the other
* instance of FHC, which is not under central, will properly
* program the IGR. The numbers from the two settings of the
* IGR need to be the same. One driver cannot wait for the
* other to program the IGR, because there is no guarantee
* which instance of FHC will get attached first.
*/
/*
* Now determine the board number by reading the
* hardware register.
*/
}
/*
* If this fhc holds JTAG master line, and is not the central fhc,
* (this avoids two JTAG master nodes) then initialize the
* mutex and set the flag in the structure.
*/
NULL);
} else {
}
/* Initialize the mutex guarding the poll_list. */
/* Initialize the mutex guarding the FHC CSR */
/* Initialize the poll_list to be empty */
for (i = 0; i < MAX_ZS_CNT; i++) {
}
/* Modify the various registers in the FHC now */
/*
* We know this board to be present now, record that state and
* remove the NOT_BRD_PRES condition
*/
if (!(softsp->is_central)) {
/* Now flush the hardware store buffers. */
#ifdef lint
#endif
/* XXX record the board state in global space */
/* Add kstats for all non-central instances of the FHC. */
}
/*
* Read the device tree to see if this system is in an environmental
* chamber.
*/
if (temperature_chamber == -1) {
}
/* Check for inherited faults from the PROM. */
}
/*
* setup the IGR. Shift the board number over by one to get
* the UPA MID.
*/
/* Now flush the hardware store buffers. */
#ifdef lint
#endif
/* Add the interrupt redistribution callback. */
return (DDI_SUCCESS);
bad:
return (DDI_FAILURE);
}
static uint_t
{
/* Idle the state machine. */
/* Flush the hardware store buffers. */
#ifdef lint
#endif /* lint */
return (intr_return);
}
/*
* fhc_zs_intr_wrapper
*
* This function handles intrerrupts where more than one device may interupt
* the fhc with the same mondo.
*/
static uint_t
{
}
}
}
}
if (result == DDI_INTR_UNCLAIMED) {
(*spurious_cntr)++;
if (*spurious_cntr < MAX_INTR_CNT) {
} else {
*spurious_cntr = (uchar_t)0;
}
} else {
*spurious_cntr = (uchar_t)0;
}
/* Idle the state machine. */
/* flush the store buffers. */
#ifdef lint
#endif
return (result);
}
/*
* add_intrspec - Add an interrupt specification.
*/
static int
{
int ino;
/* Xlate the interrupt */
/* get the mondo number */
/* We don't use the two spare interrupts. */
if (ino >= FHC_MAX_INO) {
return (DDI_FAILURE);
}
/* TOD and Fan Fail interrupts are not usable */
if (ino == FHC_TOD_INO) {
return (DDI_FAILURE);
}
if (ino == FHC_FANFAIL_INO) {
return (DDI_FAILURE);
}
/*
* If the interrupt is for the zs chips, use the vector
* polling lists. Otherwise use a straight handler.
*/
if (ino == FHC_UART_INO) {
/* First lock the mutex for this poll_list */
/*
* Add this interrupt to the polling list.
*/
/* figure out where to add this item in the list */
break;
}
}
if (zs_inst >= MAX_ZS_CNT) {
"fhc%d: poll list overflow",
ret = DDI_FAILURE;
goto done;
}
/*
* If polling list is empty, then install handler
* and enable interrupts for this ino.
*/
if (zs_inst == 0) {
if (ret != DDI_SUCCESS)
goto done;
}
/*
* If both zs handlers are active, then this is the
* second add_intrspec called, so do not enable
* the IMR_VALID bit, it is already on.
*/
if (zs_inst > 0) {
/* now release the mutex and return */
goto done;
} else {
/* just release the mutex */
}
} else { /* normal interrupt installation */
int32_t i;
/* Allocate a nexus interrupt data structure */
for (i = 0; i < FHC_MAX_INO; i++) {
break;
}
}
/*
* Save the fhc_arg in the ispec so we can use this info
* later to uninstall this interrupt spec.
*/
if (ret != DDI_SUCCESS)
goto done;
}
/*
* Clear out a stale 'pending' or 'transmit' state in
* this device's ISM that might have been left from a
* previous session.
*
* Since all FHC interrupts are level interrupts, any
* real interrupting condition will immediately transition
* the ISM back to pending.
*/
/*
* Program the mondo vector accordingly. This MUST be the
* last thing we do. Once we program the ino, the device
* may begin to interrupt.
*/
cpu_id = intr_dist_cpuid();
/* don't do this for fan because fan has a special control */
if (ino == FHC_FANFAIL_INO)
panic("fhc%d: enabling fanfail interrupt",
else
(void *)mondo_vec_reg));
/* Store it in the hardware reg. */
/* Read a FHC register to flush store buffers */
#ifdef lint
#endif
done:
return (ret);
}
/*
* remove_intrspec - Remove an interrupt specification.
*/
static void
{
int i;
int ino;
/* Xlate the interrupt */
/* get the mondo number */
if (ino == FHC_UART_INO) {
int intr_found = 0;
/* Lock the poll_list first */
/*
* Find which entry in the poll list belongs to this
* intrspec.
*/
for (i = 0; i < MAX_ZS_CNT; i++) {
intr_found++;
}
}
/* If we did not find an entry, then we have a problem */
if (!intr_found) {
goto done;
}
/*
* If we have removed all active entries for the poll
* list, then we have to disable interupts at this point.
*/
*mondo_vec_reg &= ~IMR_VALID;
/* flush the hardware buffers */
/* Eliminate the particular handler from the system. */
}
} else {
int32_t i;
for (i = 0; i < FHC_MAX_INO; i++)
break;
if (i >= FHC_MAX_INO)
goto done;
/* Turn off the valid bit in the mapping register. */
/* XXX what about FHC_FANFAIL owned imr? */
*mondo_vec_reg &= ~IMR_VALID;
/* flush the hardware store buffers */
#ifdef lint
#endif
/* Eliminate the particular handler from the system. */
sizeof (struct fhc_wrapper_arg));
}
done:
;
}
/* new intr_ops structure */
static int
{
switch (intr_op) {
case DDI_INTROP_GETCAP:
*(int *)result = DDI_INTR_FLAG_LEVEL;
break;
case DDI_INTROP_ALLOC:
break;
case DDI_INTROP_FREE:
break;
case DDI_INTROP_GETPRI:
/* Xlate the interrupt */
}
break;
case DDI_INTROP_SETPRI:
break;
case DDI_INTROP_ADDISR:
break;
case DDI_INTROP_REMISR:
break;
case DDI_INTROP_ENABLE:
case DDI_INTROP_DISABLE:
break;
case DDI_INTROP_NINTRS:
case DDI_INTROP_NAVAIL:
break;
case DDI_INTROP_SETCAP:
case DDI_INTROP_SETMASK:
case DDI_INTROP_CLRMASK:
case DDI_INTROP_GETPENDING:
ret = DDI_ENOTSUP;
break;
/* only support fixed interrupts */
DDI_INTR_TYPE_FIXED : 0;
break;
default:
break;
}
return (ret);
}
/*
* FHC Control Ops routine
*
* Requests handled here:
* DDI_CTLOPS_INITCHILD see impl_ddi_sunbus_initchild() for details
* DDI_CTLOPS_UNINITCHILD see fhc_uninit_child() for details
* DDI_CTLOPS_REPORTDEV TODO - need to implement this.
*/
static int
{
switch (op) {
case DDI_CTLOPS_INITCHILD:
case DDI_CTLOPS_UNINITCHILD:
return (DDI_SUCCESS);
case DDI_CTLOPS_REPORTDEV:
/*
* TODO - Figure out what makes sense to report here.
*/
return (DDI_SUCCESS);
case DDI_CTLOPS_POKE:
case DDI_CTLOPS_PEEK:
result));
default:
}
}
/*
* We're prepared to claim that the interrupt string is in
* the form of a list of <FHCintr> specifications, or we're dealing
* with on-board devices and we have an interrupt_number property which
* gives us our mondo number.
* Translate the mondos into fhcintrspecs.
*/
/* ARGSUSED */
static void
{
}
static int
void *result)
{
return (DDI_FAILURE);
/* Set up protected environment. */
if (cmd == DDI_CTLOPS_POKE) {
} else {
}
} else
err = DDI_FAILURE;
/* Take down protected environment. */
no_trap();
return (err);
}
/*
* This function initializes the temperature arrays for use. All
* temperatures are set in to invalid value to start.
*/
void
{
int i;
for (i = 0; i < L1_SZ; i++) {
}
for (i = 0; i < L2_SZ; i++) {
}
for (i = 0; i < L3_SZ; i++) {
}
for (i = 0; i < L4_SZ; i++) {
}
for (i = 0; i < L5_SZ; i++) {
}
}
/* Inhibit warning messages below this temperature, eg for CPU poweron. */
/*
* This function manages the temperature history in the temperature
* statistics buffer passed in. It calls the temperature calibration
* routines and maintains the time averaged temperature data.
*/
void
{
int i;
/*
* NOTE: This global counter is not protected since we're called
* serially for each board.
*/
/* determine soft state pointer of parent */
/*
* You need to update the level 5 intervals first, since
* they are based on the data from the level 4 intervals,
* and so on, down to the level 1 intervals.
*/
/* update the level 5 intervals if it is time */
/* Generate the index within the level 5 array */
/* take an average of the level 4 array */
/* Do not include zero values in average */
count++;
}
}
/*
* If there were any level 4 data points to average,
* do so.
*/
if (count != 0) {
} else {
}
}
/* update the level 4 intervals if it is time */
/* Generate the index within the level 4 array */
/* take an average of the level 3 array */
/* Do not include zero values in average */
count++;
}
}
/*
* If there were any level 3 data points to average,
* do so.
*/
if (count != 0) {
} else {
}
}
/* update the level 3 intervals if it is time */
/* Generate the index within the level 3 array */
/* take an average of the level 2 array */
/* Do not include zero values in average */
count++;
}
}
/*
* If there were any level 2 data points to average,
* do so.
*/
if (count != 0) {
} else {
}
}
/* update the level 2 intervals if it is time */
/* Generate the index within the level 2 array */
/* take an average of the level 1 array */
/* Do not include zero values in average */
count++;
}
}
/*
* If there were any level 1 data points to average,
* do so.
*/
if (count != 0) {
} else {
}
}
/* determine the current temperature in degrees Celcius */
/* use override temperature for this board */
} else {
/* Run the calibration function using this board type */
}
/* check if the temperature state for this device needs to change */
/* has the state changed? Then get the board string ready */
if (type == CLOCK_BOARD) {
} else {
FT_BOARD);
}
}
/* heating up, change state now */
if (temp_state == TEMP_WARN) {
/* now warn the user of the problem */
"%s is warm (temperature: %dC). "
"Please check system cooling", buffer,
if (temperature_chamber == -1)
} else if (temp_state == TEMP_DANGER) {
"%s is very hot (temperature: %dC)",
if (temperature_chamber == -1)
if ((temperature_chamber == 0) &&
/*
* NOTE: The "%d seconds" is not
* necessarily accurate in the case
* where we have multiple boards
* overheating and subsequently cooling
* down.
*/
if (shutdown_msg == 0) {
"shutdown scheduled "
"in %d seconds due to "
"over-temperature "
"condition on %s",
buffer);
}
shutdown_msg++;
}
}
/*
* If this is a cpu board, power them off.
*/
if (temperature_chamber == 0) {
}
/*
* Avert the sigpower that would
* otherwise be sent to init.
*/
envstat->shutdown_cnt = 0;
/* cooling down, use state counter */
if (temp_state == TEMP_WARN) {
"%s is cooling "
"(temperature: %dC)", buffer,
} else if (temp_state == TEMP_OK) {
"%s has cooled down "
"(temperature: %dC), system OK",
if (type == CLOCK_BOARD) {
} else {
FT_BOARD);
}
}
/*
* If we just came out of TEMP_DANGER, and
* a warning was issued about shutting down,
* let the user know it's been cancelled
*/
(temperature_chamber == 0) &&
(powerdown_started == 0) &&
(--shutdown_msg == 0)) {
"shutdown due to over-"
"temperature "
"condition cancelled");
}
}
}
} else {
if (temp_state == TEMP_DANGER) {
if (temperature_chamber == -1) {
}
(temperature_chamber == 0) &&
(powerdown_started == 0)) {
powerdown_started = 1;
/* the system is still too hot */
"(temperature: %dC)."
" Overtemp shutdown started", buffer,
fhc_reboot();
}
}
}
/* update the maximum and minimum temperatures if necessary */
}
}
/*
* Update the temperature trend. Currently, the temperature
* trend algorithm is based on the level 2 stats. So, we
* only need to run every time the level 2 stats get updated.
*/
/* Issue a warning if the temperature is rising rapidly. */
/* For CPU boards, don't warn if CPUs just powered on. */
"Current temperature is %dC", buffer,
}
}
}
/*
* This routine determines if the temp of the device passed in is heating
* up, cooling down, or staying stable.
*/
enum temp_trend
{
int ii;
int curr_temp;
int prev_temp;
int trail_temp;
int delta;
int read_cnt;
return (TREND_UNKNOWN);
/* Count how many temperature readings are available */
break;
}
switch (read_cnt) {
case 0:
case 1:
break;
default:
} else if (delta > 0) { /* rise? */
if (prev_temp > trail_temp) {
break;
}
result = TREND_RISE;
break;
}
}
} else if (delta < 0) { /* fall? */
if (prev_temp < trail_temp) {
break;
}
result = TREND_FALL;
break;
}
}
}
}
return (result);
}
/*
* Reboot the system if we can, otherwise attempt a power down
*/
void
fhc_reboot(void)
{
/* send a SIGPWR to init process */
/*
* If we're still booting and init(1) isn't
* set up yet, simply halt.
*/
} else {
power_down("Environmental Shutdown");
halt("Power off the System");
}
}
int
{
char *kstatp;
int i;
/*
* Kstat reads are used to retrieve the current system temperature
* history. Kstat writes are used to reset the max and min
* temperatures.
*/
if (rw == KSTAT_WRITE) {
/*
* search for and reset the max and min to the current
* array contents. Old max and min values will get
* averaged out as they move into the higher level arrays.
*/
/* Pull the max and min from Level 1 array */
for (i = 0; i < L1_SZ; i++) {
}
}
}
/* Pull the max and min from Level 2 array */
for (i = 0; i < L2_SZ; i++) {
}
}
}
/* Pull the max and min from Level 3 array */
for (i = 0; i < L3_SZ; i++) {
}
}
}
/* Pull the max and min from Level 4 array */
for (i = 0; i < L4_SZ; i++) {
}
}
}
/* Pull the max and min from Level 5 array */
for (i = 0; i < L5_SZ; i++) {
}
}
}
} else {
/*
* copy the temperature history buffer into the
* kstat structure.
*/
}
return (0);
}
int
{
short *over;
short *kstatp;
/*
* Kstat reads are used to get the temperature override setting.
* Kstat writes are used to set the temperature override setting.
*/
if (rw == KSTAT_WRITE) {
} else {
}
return (0);
}
/*
* This function uses the calibration tables at the beginning of this file
* to lookup the actual temperature of the thermistor in degrees Celcius.
* If the measurement is out of the bounds of the acceptable values, the
* closest boundary value is used instead.
*/
static short
{
if (dont_calibrate == 1) {
return ((short)temp);
}
switch (type) {
case CPU_BOARD:
/*
* If AC chip revision is >= 4 or if it is unitialized,
* then use the new calibration tables.
*/
if (temp >= CPU2_MX_CNT) {
} else {
}
} else {
if (temp >= CPU_MX_CNT) {
} else {
}
}
break;
case IO_2SBUS_BOARD:
case IO_SBUS_FFB_BOARD:
case IO_PCI_BOARD:
case IO_2SBUS_SOCPLUS_BOARD:
} else {
}
break;
case CLOCK_BOARD:
if (temp < CLK_MN_CNT) {
} else if (temp >= CLK_MX_CNT) {
} else {
}
break;
default:
break;
}
return (result);
}
/*
* Determine the temperature state of this board based on its type and
* the actual temperature in degrees Celcius.
*/
static enum temp_state
{
short warn_limit;
short danger_limit;
switch (type) {
case CPU_BOARD:
/*
* For CPU boards with frequency >= 400 MHZ,
* temperature zones are different.
*/
}
}
}
}
break;
case IO_2SBUS_BOARD:
case IO_SBUS_FFB_BOARD:
case IO_PCI_BOARD:
case IO_2SBUS_SOCPLUS_BOARD:
break;
case CLOCK_BOARD:
break;
case UNINIT_BOARD:
case UNKNOWN_BOARD:
case MEM_BOARD:
default:
break;
}
if (temp >= danger_limit) {
state = TEMP_DANGER;
} else if (temp >= warn_limit) {
}
return (state);
}
static void
{
sizeof (struct fhc_kstat) / sizeof (kstat_named_t),
KSTAT_FLAG_PERSISTENT)) == NULL) {
return;
}
/* initialize the named kstats */
}
static int
{
/* this is a read-only kstat. Bail out on a write */
if (rw == KSTAT_WRITE) {
return (EACCES);
} else {
/*
* copy the current state of the hardware into the
* kstat structure.
*/
}
return (0);
}
static int
{
return (1);
} else {
return (0);
}
}
/*
* This function uses the board list and toggles the OS green board
* LED. The mask input tells which bit fields are being modified,
* and the value input tells the states of the bits.
*/
void
{
/* mask off mask and value for only the LED bits */
/* read the current register state */
/*
* The EPDA bits are special since the register is
* special. We don't want to set them, since setting
* the bits on a shutdown cpu keeps the cpu permanently
* powered off. Also, the CSR_SYNC bit must always be
* set to 0 as it is an OBP semaphore that is expected to
* be clear for cpu restart.
*/
/* mask off the bits to change */
/* or in the new values of the bits. */
/* update the register */
/* flush the hardware registers */
#ifdef lint
#endif
}
}
static int
check_for_chamber(void)
{
int chamber = 0;
int mfgmode_len;
int retval;
char *mfgmode;
/*
* boot -h.
*/
if (!enable_overtemp_powerdown) {
return (1);
}
/*
* An OBP option, 'mfg-mode' is being used to inform us as to
* whether we are in an enviromental chamber. It exists in
* the 'options' node. This is where all OBP 'setenv' (eeprom)
* parameters live.
*/
if (mfgmode_len == -1) {
return (chamber);
}
if (retval != -1) {
chamber = 1;
" Chamber Mode. Overtemperature"
" Shutdown disabled");
}
}
}
return (chamber);
}
static void
{
return;
}
/* fill in board type to display */
switch (type) {
case UNINIT_BOARD:
board);
break;
case UNKNOWN_BOARD:
break;
case CPU_BOARD:
case MEM_BOARD:
break;
case IO_2SBUS_BOARD:
break;
case IO_SBUS_FFB_BOARD:
break;
case IO_PCI_BOARD:
break;
case CLOCK_BOARD:
break;
case IO_2SBUS_SOCPLUS_BOARD:
break;
break;
default:
board);
break;
}
}
void
{
uint_t i;
/* extract the soft state pointer */
/*
* Loop through all the interrupt mapping registers and reprogram
* the target CPU for all valid registers.
*/
for (i = 0; i < FHC_MAX_INO; i++) {
if ((*mondo_vec_reg & IMR_VALID) == 0)
continue;
cpu_id = intr_dist_cpuid();
/* Check the current target of the mondo */
cpu_id) {
/* It is the same, don't reprogram */
return;
}
/* So it's OK to reprogram the CPU target */
/* turn off the valid bit */
*mondo_vec_reg &= ~IMR_VALID;
/* flush the hardware registers */
/*
* wait for the state machine to idle. Do not loop on panic, so
* that system does not hang.
*/
!panicstr)
;
/* re-target the mondo and turn it on */
/* write it back to the hardware. */
/* flush the hardware buffers. */
#ifdef lint
#endif /* lint */
}
}
/*
* reg_fault
*
* This routine registers a fault in the fault list. If the fault
* is unique (does not exist in fault list) then a new fault is
* added to the fault list, with the appropriate structure elements
* filled in.
*/
void
{
if (type >= ft_max_index) {
return;
}
/* Search for the requested fault. If it already exists, return. */
return;
}
}
/* Allocate a new fault structure. */
/* fill in the fault list elements */
/* link it into the list. */
/* Update the total fault count */
ft_nfaults++;
}
/*
* clear_fault
*
* This routine finds the fault list entry specified by the caller,
* deletes it from the fault list, and frees up the memory used for
* the entry. If the requested fault is not found, it exits silently.
*/
void
{
/*
* Search for the requested fault. If it exists, delete it
* and relink the fault list.
*/
/* remove the item from the list */
/* free the memory allocated */
/* Update the total fault count */
ft_nfaults--;
break;
}
}
}
/*
* process_fault_list
*
* This routine walks the global fault list and updates the board list
* with the current status of each Yellow LED. If any faults are found
* in the system, then a non-zero value is returned. Else zero is returned.
*/
int
process_fault_list(void)
{
int fault = 0;
/*
* Note on locking. The bdlist mutex is always acquired and
* held around the ftlist mutex when both are needed for an
* operation. This is to avoid deadlock.
*/
/* First lock the board list */
(void) fhc_bdlist_lock(-1);
/* Grab the fault list lock first */
/* clear the board list of all faults first */
/* walk the fault list here */
fault++;
/*
* If this is a board level fault, find the board, The
* unit number for all board class faults must be the
* actual board number. The caller of reg_fault must
* ensure this for FT_BOARD class faults.
*/
/* Sanity check the board first */
} else {
}
}
}
/* now unlock the fault list */
/* unlock the board list before leaving */
return (fault);
}
/*
* Add a new memloc to the database (and keep 'em sorted by PA)
*/
void
{
/* look for a comparable memloc (as long as new PA smaller) */
/* have we passed our place in the sort? */
break;
}
}
#ifdef DEBUG_MEMDEC
#endif /* DEBUG_MEMDEC */
*pp = p;
}
/*
* Delete all memloc records for a board from the database
*/
void
{
/* delete all entries that match board */
pp = &fhc_base_memloc;
#ifdef DEBUG_MEMDEC
#endif /* DEBUG_MEMDEC */
kmem_free(p, sizeof (struct fhc_memloc));
} else {
}
}
}
/*
* Find a physical address range of sufficient size and return a starting PA
*/
{
struct fhc_memloc *p;
/*
* walk the list of known memlocs and measure the 'gaps'.
* we will need a hole that can align the 'size' requested.
* (e.g. a 256mb bank needs to be on a 256mb boundary).
*/
break;
}
/*
* At this point, we assume that base_pa is good enough.
*/
}
/*
* This simple function to write the MCRs can only be used when
* the contents of memory are not valid as there is a bug in the AC
* ASIC concerning refresh.
*/
static void
uint64_t c,
{
if (GRP_SIZE_IS_SET(d0)) {
}
if (GRP_SIZE_IS_SET(d1)) {
}
}
/* compute the appropriate RASIZE for bank size */
static uint_t
{
csz = 0;
bsz /= 64;
while (bsz) {
csz++;
bsz /= 2;
}
csz /= 2;
return (csz);
}
void
{
/* XXX gross hack to get to board via board number */
#ifdef DEBUG_MEMDEC
#endif /* DEBUG_MEMDEC */
/* assume size is set by connect */
#ifdef DEBUG_MEMDEC
#endif /* DEBUG_MEMDEC */
#ifdef DEBUG_MEMDEC
#endif /* DEBUG_MEMDEC */
if (GRP_SIZE_IS_SET(memdec0)) {
} else {
b0_size = 0;
}
if (GRP_SIZE_IS_SET(memdec1)) {
} else {
b1_size = 0;
}
#ifdef DEBUG_MEMDEC
prom_printf("c = 0x%llx\n", c);
#endif /* DEBUG_MEMDEC */
if (b0_size) {
d0 |= AC_MEM_VALID;
c &= ~0x7;
c |= 0;
c &= ~(0x7 << 8);
} else {
}
if (b1_size) {
d1 |= AC_MEM_VALID;
c &= ~(0x7 << 3);
c |= (0 << 3);
c &= ~(0x7 << 11);
} else {
}
#ifdef DEBUG_MEMDEC
#endif /* DEBUG_MEMDEC */
}
/*
* Creates a variable sized virtual kstat with a snapshot routine in order
* to pass the linked list fault list up to userland. Also creates a
* virtual kstat to pass up the string table for faults.
*/
void
{
}
}
/*
* This routine creates a snapshot of all the fault list data. It is
* called by the kstat framework when a kstat read is done.
*/
static int
{
if (rw == KSTAT_WRITE) {
return (EACCES);
}
}
return (0);
}
/*
* Setup the kstat data size for the kstat framework. This is used in
* conjunction with the ks_snapshot routine. This routine sets the size,
* the kstat framework allocates the memory, and ks_shapshot does the
* data transfer.
*/
static int
{
if (rw == KSTAT_WRITE) {
return (EACCES);
} else {
if (ft_nfaults) {
sizeof (struct ft_list);
} else {
}
}
return (0);
}
/*
* Power off any cpus on the board.
*/
int
{
int error = 0;
/*
* what type of board are we dealing with?
*/
switch (type) {
case CPU_BOARD:
/*
* the shutdown sequence will be:
*
* idle both cpus then shut them off.
* it looks like the hardware gets corrupted if one
* cpu is busy while the other is shutting down...
*/
cpu_is_active(cpa)) {
if (!cpu_intr_on(cpa)) {
}
"Processor %d failed to offline.",
"processor %d failed to offline",
}
}
}
if (error == 0 &&
cpu_is_active(cpb)) {
if (!cpu_intr_on(cpb)) {
}
"Processor %d failed to offline.",
"processor %d failed to offline",
}
}
}
"Processor %d failed to power off.",
"processor %d failed to power off",
}
} else {
}
}
"Processor %d failed to power off.",
"processor %d failed to power off",
}
} else {
}
}
/*
* If all the shutdowns completed, ONLY THEN, clear the
* incorrectly valid dtags...
*
* IMPORTANT: it is an error to read or write dtags while
* they are 'active'
*/
int i;
#ifdef DEBUG
int nonz0 = 0;
int nonz1 = 0;
#endif
for (i = 0; i < FHC_DTAG_SIZE; i += FHC_DTAG_SKIP) {
#ifdef lint
#endif
#ifdef DEBUG
nonz0++;
nonz1++;
#endif
/* always clear the dtags */
}
#ifdef DEBUG
"cpua valid %d, cpub valid %d",
}
#endif
}
break;
default:
break;
}
return (error);
}
/*
* platform code for shutting down cpus.
*/
int
{
int board;
int delays;
extern void idle_stop_xcall(void);
/*
* Lock the board so that we can safely access the
* registers. This cannot be done inside the pause_cpus().
*/
/*
* Capture all CPUs (except for detaching proc) to prevent
* crosscalls to the detaching proc until it has cleared its
* bit in cpu_ready_set.
*
* The CPU's remain paused and the prom_mutex is known to be free.
* This prevents the x-trap victim from blocking when doing prom
* IEEE-1275 calls at a high PIL level.
*/
/*
* Quiesce interrupts on the target CPU. We do this by setting
* the CPU 'not ready'- (i.e. removing the CPU from cpu_ready_set) to
* prevent it from receiving cross calls and cross traps.
* This prevents the processor from receiving any new soft interrupts.
*/
/*
* Wait for slave cpu to shutdown.
* Sense this by watching the hardware EPDx bit.
*/
DELAY(1000);
/* get the current cpu power status */
/* has the cpu actually signalled shutdown? */
if (temp & FHC_EPDA_OFF)
break;
} else {
if (temp & FHC_EPDB_OFF)
break;
}
}
start_cpus();
/* A timeout means we've lost control of the cpu. */
if (delays == 0)
return (0);
}
/*
* shutdown_self
* slave side shutdown. clean up and execute the shutdown sequence.
*/
static void
fhc_cpu_shutdown_self(void)
{
extern void flush_windows(void);
(void) prom_sunfire_cpu_off(); /* inform Ultra Enterprise prom */
panic("fhc_cpu_shutdown_self: cannot return");
/*NOTREACHED*/
}
/*
* Warm start CPU.
*/
static int
{
int rv;
extern void restart_other_cpu(int);
/* power on cpu */
if (rv != 0) {
return (EBUSY);
}
/*
* NOTE: restart_other_cpu pauses cpus during the slave cpu start.
* This helps to quiesce the bus traffic a bit which makes
* the tick sync routine in the prom more robust.
*/
return (0);
}
/*
* Power on CPU.
*/
int
{
int board;
int status;
int status_other;
/* do not power on overtemperature cpu */
state = ((struct environ_soft_state *)
return (EBUSY);
/* policy for dual cpu boards */
if ((status == 0) &&
/*
* Do not leave board's other cpu idling in the prom.
* Start the other cpu and set its state to P_OFFLINE.
*/
if (status_other != 0) {
panic("fhc: failed to start second CPU"
" in pair %d & %d, error %d",
}
}
return (status);
}
/*
* complete the shutdown sequence in case the firmware doesn't.
*
* If the firmware returns, then complete the shutdown code.
* (sunfire firmware presently only updates its status. the
* OS must flush the D-tags and execute the shutdown instruction.)
*/
static void
os_completes_shutdown(void)
{
extern void fhc_shutdown_asm(u_longlong_t, int);
extern void fhc_shutdown_asm_end(void);
/* compute sram global address for this operation */
/* force load i and d translations */
/*
* copy the special shutdown function to sram
* (this is a special integer copy that synchronizes with localspace
* accesses. we need special throttling to ensure copy integrity)
*/
/*
* ensure non corrupting single write operations to
* localspace sram by interleaving reads with writes.
*/
#ifdef lint
#endif
}
/*
* Call the shutdown sequencer.
* NOTE: the base flush address must be unique for each MID.
*/
((void (*)(u_longlong_t, int))copy_addr)(
}
enum temp_state
{
/*
* Due to asynchronous attach of environ, environ may
* not be attached by the time we start calling this routine
* to check the temperature state. Environ not attaching is
* pathological so this will only cover the time between
* board connect and environ attach.
*/
if (!bdp->dev_softsp) {
return (TEMP_OK);
}
}
static void
{
int board_num = 0;
/* if tod is not on clock board, */
/* it'd be on one of io boards */
}
switch (tod_bad) {
case TOD_NOFAULT:
break;
case TOD_REVERSED:
case TOD_STALLED:
case TOD_JUMPED:
case TOD_RATECHANGED:
break;
default:
break;
}
}