17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*b0fc0e77Sgovinda * Common Development and Distribution License (the "License"). 6*b0fc0e77Sgovinda * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*b0fc0e77Sgovinda * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <sys/param.h> 307c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 317c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 327c478bd9Sstevel@tonic-gate #include <vm/seg.h> 337c478bd9Sstevel@tonic-gate #include <sys/iommu.h> 347c478bd9Sstevel@tonic-gate #include <sys/vtrace.h> 357c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 367c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 377c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 387c478bd9Sstevel@tonic-gate #include <sys/systm.h> 397c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 407c478bd9Sstevel@tonic-gate #include <sys/cyclic.h> 417c478bd9Sstevel@tonic-gate #include <sys/cpu_sgn.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate extern cpu_sgnblk_t *cpu_sgnblkp[NCPU]; 447c478bd9Sstevel@tonic-gate extern struct cpu *SIGBCPU; 457c478bd9Sstevel@tonic-gate extern void power_down(const char *); 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate uint_t bbus_intr_inum; 48*b0fc0e77Sgovinda uint64_t bbus_poll_inum; 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * Support for sgnblk polling. 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* Internal function prototypes */ 557c478bd9Sstevel@tonic-gate static void sgnblk_poll_init(); 567c478bd9Sstevel@tonic-gate static uint_t bbus_poll(caddr_t arg1, caddr_t arg2); 577c478bd9Sstevel@tonic-gate static void sgnblk_poll_handler(void *unused); 587c478bd9Sstevel@tonic-gate #ifdef THROTTLE 597c478bd9Sstevel@tonic-gate static void sgnblk_poll_throttle(uint64_t interval); 607c478bd9Sstevel@tonic-gate #endif /* THROTTLE */ 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* Default sgnblk polling interval is every 5 seconds. */ 637c478bd9Sstevel@tonic-gate #define ONE_SECOND (1000000) /* in usecs */ 647c478bd9Sstevel@tonic-gate #ifdef THROTTLE 657c478bd9Sstevel@tonic-gate #define SGNBLK_POLL_INTERVAL (5 * ONE_SECOND) 667c478bd9Sstevel@tonic-gate #define SGNBLK_POLL_FAST (ONE_SECOND >> 1) 677c478bd9Sstevel@tonic-gate #define SGNBLK_POLL_FAST_WIN ((60 * ONE_SECOND) / \ 687c478bd9Sstevel@tonic-gate SGNBLK_POLL_FAST) 697c478bd9Sstevel@tonic-gate #else /* THROTTLE */ 707c478bd9Sstevel@tonic-gate /* 717c478bd9Sstevel@tonic-gate * Until we can find a way to throttle back to 0.5 second intervals 727c478bd9Sstevel@tonic-gate * we're stuck fixed on 2.5 second intervals. 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate #define SGNBLK_POLL_INTERVAL ((2 * ONE_SECOND) + (ONE_SECOND >> 1)) 757c478bd9Sstevel@tonic-gate #endif /* THROTTLE */ 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #define MAX_SGNBLK_POLL_CLNT 5 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate void (*pollclntfunc[MAX_SGNBLK_POLL_CLNT])(); 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * sgnblk_mutex Protects juggling & sgnblk_poll_refs[]. 827c478bd9Sstevel@tonic-gate * sgnblk_poll_mutex Protects pollclntfunc[]. 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate kmutex_t sgnblk_mutex; 857c478bd9Sstevel@tonic-gate kmutex_t sgnblk_poll_mutex; 867c478bd9Sstevel@tonic-gate static uint64_t sgnblk_poll_interval = SGNBLK_POLL_INTERVAL; 877c478bd9Sstevel@tonic-gate #ifdef THROTTLE 887c478bd9Sstevel@tonic-gate static uint64_t sgnblk_poll_fast = SGNBLK_POLL_FAST; 897c478bd9Sstevel@tonic-gate static int64_t sgnblk_poll_fast_win = SGNBLK_POLL_FAST_WIN; 907c478bd9Sstevel@tonic-gate #endif /* THROTTLE */ 917c478bd9Sstevel@tonic-gate static processorid_t sgnblk_pollcpu = -1; 927c478bd9Sstevel@tonic-gate /* 937c478bd9Sstevel@tonic-gate * Note that the sigblock polling depends on CY_HIGH_LEVEL 947c478bd9Sstevel@tonic-gate * being higher than PIL_13 since we ultimately need to 957c478bd9Sstevel@tonic-gate * dispatch a PIL_13 soft handler. 967c478bd9Sstevel@tonic-gate * Also, we assume one sgnblk handler for the entire system. 977c478bd9Sstevel@tonic-gate * Once upon a time we had them per-cpu. With the Cyclic stuff 987c478bd9Sstevel@tonic-gate * we would have to bind our cyclic handler to a cpu and doing 997c478bd9Sstevel@tonic-gate * this prevents that cpu from being offlined. Since the Cyclic 1007c478bd9Sstevel@tonic-gate * subsystem could indirectly juggle us without us knowing we 1017c478bd9Sstevel@tonic-gate * have to assume we're running from any possible cpu and not 1027c478bd9Sstevel@tonic-gate * always SIGBCPU. 1037c478bd9Sstevel@tonic-gate */ 1047c478bd9Sstevel@tonic-gate #ifdef THROTTLE 1057c478bd9Sstevel@tonic-gate static cyclic_id_t sgnblk_poll_cycid = CYCLIC_NONE; 1067c478bd9Sstevel@tonic-gate #endif /* THROTTLE */ 1077c478bd9Sstevel@tonic-gate static cyc_handler_t sgnblk_poll_cychandler = { 1087c478bd9Sstevel@tonic-gate sgnblk_poll_handler, 1097c478bd9Sstevel@tonic-gate NULL, 1107c478bd9Sstevel@tonic-gate CY_HIGH_LEVEL 1117c478bd9Sstevel@tonic-gate }; 1127c478bd9Sstevel@tonic-gate static cyc_time_t sgnblk_poll_time; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate /* 1157c478bd9Sstevel@tonic-gate * Anybody that references the polling (SIGBCPU) can 1167c478bd9Sstevel@tonic-gate * register a callback function that will be called if 1177c478bd9Sstevel@tonic-gate * the polling cpu is juggled, e.g. during a DR operation. 1187c478bd9Sstevel@tonic-gate */ 1197c478bd9Sstevel@tonic-gate #define MAX_SGNBLK_POLL_REFS 10 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate struct sgnblk_poll_refs { 1227c478bd9Sstevel@tonic-gate void (*callback)(cpu_sgnblk_t *sigbp, void *arg); 1237c478bd9Sstevel@tonic-gate void *arg; 1247c478bd9Sstevel@tonic-gate } sgnblk_poll_refs[MAX_SGNBLK_POLL_REFS]; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * Bootbus intr handler: Generic handler for all SSP/CBS 1287c478bd9Sstevel@tonic-gate * interrupt requests initiated via the hw bootbus intr 1297c478bd9Sstevel@tonic-gate * mechanism. This is similar to the level15 1307c478bd9Sstevel@tonic-gate * interrupt handling for sigb commands in the CS6400. 1317c478bd9Sstevel@tonic-gate * Most of these code were stolen from the sigb stuff in 1327c478bd9Sstevel@tonic-gate * in CS6400. 1337c478bd9Sstevel@tonic-gate */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate extern struct cpu cpu0; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1387c478bd9Sstevel@tonic-gate static uint_t 1397c478bd9Sstevel@tonic-gate bbus_intr(caddr_t arg) 1407c478bd9Sstevel@tonic-gate { 1417c478bd9Sstevel@tonic-gate int cmd = 0; 1427c478bd9Sstevel@tonic-gate processorid_t cpu_id = CPU->cpu_id; 1437c478bd9Sstevel@tonic-gate int retflag; 1447c478bd9Sstevel@tonic-gate int resp = 0; 1457c478bd9Sstevel@tonic-gate proc_t *initpp; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate ASSERT(cpu_sgnblkp[cpu_id] != NULL); 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * Check for unsolicited messages in the host's mailbox. 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate retflag = cpu_sgnblkp[cpu_id]->sigb_host_mbox.flag; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate switch (retflag) { 1557c478bd9Sstevel@tonic-gate case CBS_TO_HOST: 1567c478bd9Sstevel@tonic-gate retflag = HOST_TO_CBS; 1577c478bd9Sstevel@tonic-gate break; 1587c478bd9Sstevel@tonic-gate default: 1597c478bd9Sstevel@tonic-gate retflag = SIGB_MBOX_EMPTY; 1607c478bd9Sstevel@tonic-gate break; 1617c478bd9Sstevel@tonic-gate } 1627c478bd9Sstevel@tonic-gate if (retflag == SIGB_MBOX_EMPTY) 1637c478bd9Sstevel@tonic-gate return (0); /* interrupt not claimed */ 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate /* 1667c478bd9Sstevel@tonic-gate * We only look for UNSOLICITED messages, i.e. commands. 1677c478bd9Sstevel@tonic-gate * Responses to these commands are returned into the same 1687c478bd9Sstevel@tonic-gate * mailbox from which the command was received, i.e. host's. 1697c478bd9Sstevel@tonic-gate * 1707c478bd9Sstevel@tonic-gate * If the host should solicit a message from the SSP, that 1717c478bd9Sstevel@tonic-gate * message/command goes into the SSP's mailbox (sigb_ssp_mbox). 1727c478bd9Sstevel@tonic-gate * The responses (from the SSP) to these messages will be 1737c478bd9Sstevel@tonic-gate * read from the ssp mailbox by whomever solicited it, but 1747c478bd9Sstevel@tonic-gate * will NOT be handled through this level 15 interrupt 1757c478bd9Sstevel@tonic-gate * mechanism. 1767c478bd9Sstevel@tonic-gate * 1777c478bd9Sstevel@tonic-gate * Note that use of the flag field of the signature block mailbox 1787c478bd9Sstevel@tonic-gate * structure and the mailbox protocol itself, serializes access 1797c478bd9Sstevel@tonic-gate * to these mailboxes. 1807c478bd9Sstevel@tonic-gate */ 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate resp = 0; 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate /* 1857c478bd9Sstevel@tonic-gate * The first sizeof (uint_t) bytes of the data field 1867c478bd9Sstevel@tonic-gate * is the command. 1877c478bd9Sstevel@tonic-gate */ 1887c478bd9Sstevel@tonic-gate cmd = cpu_sgnblkp[cpu_id]->sigb_host_mbox.cmd; 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate switch (cmd) { 1917c478bd9Sstevel@tonic-gate case SSP_GOTO_OBP: 1927c478bd9Sstevel@tonic-gate /* 1937c478bd9Sstevel@tonic-gate * Let's set the mailbox flag to BUSY while we are in OBP 1947c478bd9Sstevel@tonic-gate */ 1957c478bd9Sstevel@tonic-gate cpu_sgnblkp[cpu_id]->sigb_host_mbox.flag = SIGB_MBOX_BUSY; 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate debug_enter("SSP requested (SSP_GOTO_OBP)"); 1987c478bd9Sstevel@tonic-gate /* 1997c478bd9Sstevel@tonic-gate * This command does NOT require a response. 2007c478bd9Sstevel@tonic-gate */ 2017c478bd9Sstevel@tonic-gate resp = 0; 2027c478bd9Sstevel@tonic-gate break; 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate case SSP_GOTO_PANIC: 2057c478bd9Sstevel@tonic-gate /* 2067c478bd9Sstevel@tonic-gate * Let's reset the mailbox flag before we bail. 2077c478bd9Sstevel@tonic-gate */ 2087c478bd9Sstevel@tonic-gate cpu_sgnblkp[cpu_id]->sigb_host_mbox.flag = SIGB_MBOX_EMPTY; 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "SSP requested (SSP_GOTO_PANIC)\n"); 2117c478bd9Sstevel@tonic-gate /* should never reach this point */ 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate resp = 0; 2147c478bd9Sstevel@tonic-gate break; 2157c478bd9Sstevel@tonic-gate case SSP_ENVIRON: 2167c478bd9Sstevel@tonic-gate /* 2177c478bd9Sstevel@tonic-gate * Environmental Interrupt. 2187c478bd9Sstevel@tonic-gate */ 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate /* 2217c478bd9Sstevel@tonic-gate * Send SIGPWR to init(1) it will run rc0, which will uadmin to 2227c478bd9Sstevel@tonic-gate * powerdown. 2237c478bd9Sstevel@tonic-gate */ 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate mutex_enter(&pidlock); 2267c478bd9Sstevel@tonic-gate initpp = prfind(P_INITPID); 2277c478bd9Sstevel@tonic-gate mutex_exit(&pidlock); 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate /* 2307c478bd9Sstevel@tonic-gate * If we're still booting and init(1) isn't set up yet, 2317c478bd9Sstevel@tonic-gate * simply halt. 2327c478bd9Sstevel@tonic-gate */ 2337c478bd9Sstevel@tonic-gate if (initpp == NULL) { 2347c478bd9Sstevel@tonic-gate extern void halt(char *); 2357c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "?Environmental Interrupt"); 2367c478bd9Sstevel@tonic-gate power_down((char *)NULL); 2377c478bd9Sstevel@tonic-gate halt("Power off the System!\n"); /* just in case */ 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate /* 2417c478bd9Sstevel@tonic-gate * else, graceful shutdown with inittab and all getting involved 2427c478bd9Sstevel@tonic-gate * 2437c478bd9Sstevel@tonic-gate * XXX: Do we Need to modify the init process for the Cray 6400! 2447c478bd9Sstevel@tonic-gate */ 2457c478bd9Sstevel@tonic-gate psignal(initpp, SIGPWR); 2467c478bd9Sstevel@tonic-gate 2477c478bd9Sstevel@tonic-gate /* 2487c478bd9Sstevel@tonic-gate * XXX: kick off a sanity timeout panic in case the /etc/inittab 2497c478bd9Sstevel@tonic-gate * or /etc/rc0 files are hosed. The 6400 needs to hang here 2507c478bd9Sstevel@tonic-gate * when we return from psignal. 2517c478bd9Sstevel@tonic-gate * 2527c478bd9Sstevel@tonic-gate * cmn_err(CE_PANIC, "SSP requested (SSP_ENVIRON)\n"); 2537c478bd9Sstevel@tonic-gate * should never reach this point 2547c478bd9Sstevel@tonic-gate */ 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate resp = 0; 2577c478bd9Sstevel@tonic-gate break; 2587c478bd9Sstevel@tonic-gate /* 2597c478bd9Sstevel@tonic-gate * Could handle more mailbox commands right here. 2607c478bd9Sstevel@tonic-gate */ 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate default: 2637c478bd9Sstevel@tonic-gate resp = SIGB_BAD_MBOX_CMD; 2647c478bd9Sstevel@tonic-gate break; 2657c478bd9Sstevel@tonic-gate } 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate /* 2687c478bd9Sstevel@tonic-gate * If resp is non-zero then we'll automatically reset 2697c478bd9Sstevel@tonic-gate * the handler_sigb lock once we've sent the response, 2707c478bd9Sstevel@tonic-gate * however if no response is needed, then resetlck must 2717c478bd9Sstevel@tonic-gate * be set so that the handler_sigb lock is reset. 2727c478bd9Sstevel@tonic-gate */ 2737c478bd9Sstevel@tonic-gate if (resp != 0) { 2747c478bd9Sstevel@tonic-gate /* 2757c478bd9Sstevel@tonic-gate * Had some kind of trouble handling the mailbox 2767c478bd9Sstevel@tonic-gate * command. Need to send back an error response 2777c478bd9Sstevel@tonic-gate * and back out of the cpu_sgnblk handling. 2787c478bd9Sstevel@tonic-gate */ 2797c478bd9Sstevel@tonic-gate cpu_sgnblkp[cpu_id]->sigb_host_mbox.cmd = resp; 2807c478bd9Sstevel@tonic-gate bcopy((caddr_t)&cmd, 2817c478bd9Sstevel@tonic-gate (caddr_t)&cpu_sgnblkp[cpu_id]->sigb_host_mbox.data[0], 2827c478bd9Sstevel@tonic-gate sizeof (cmd)); 2837c478bd9Sstevel@tonic-gate cpu_sgnblkp[cpu_id]->sigb_host_mbox.flag = retflag; 2847c478bd9Sstevel@tonic-gate } else { 2857c478bd9Sstevel@tonic-gate /* 2867c478bd9Sstevel@tonic-gate * No response expected, but we still have to 2877c478bd9Sstevel@tonic-gate * reset the flag to empty for the next person. 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate cpu_sgnblkp[cpu_id]->sigb_host_mbox.flag = SIGB_MBOX_EMPTY; 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate return (1); /* interrupt claimed */ 2927c478bd9Sstevel@tonic-gate } 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate void 2957c478bd9Sstevel@tonic-gate register_bbus_intr() 2967c478bd9Sstevel@tonic-gate { 2977c478bd9Sstevel@tonic-gate /* 2987c478bd9Sstevel@tonic-gate * Starfire's ASIC have the capability to generate a mondo 2997c478bd9Sstevel@tonic-gate * vector. The SSP uses this capability via the Boot Bus to 3007c478bd9Sstevel@tonic-gate * send an interrupt to a domain. 3017c478bd9Sstevel@tonic-gate * 3027c478bd9Sstevel@tonic-gate * The SSP generates a mondo with: 3037c478bd9Sstevel@tonic-gate * ign = UPAID_TO_IGN(bootcpu_upaid) 3047c478bd9Sstevel@tonic-gate * ino = 0 3057c478bd9Sstevel@tonic-gate * 3067c478bd9Sstevel@tonic-gate * An interrupt handler is added for this inum. 3077c478bd9Sstevel@tonic-gate */ 3087c478bd9Sstevel@tonic-gate bbus_intr_inum = UPAID_TO_IGN(cpu0.cpu_id) * MAX_INO; 309*b0fc0e77Sgovinda VERIFY(add_ivintr(bbus_intr_inum, PIL_13, (intrfunc)bbus_intr, 310*b0fc0e77Sgovinda NULL, NULL, NULL) == 0); 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate /* 3147c478bd9Sstevel@tonic-gate * Due to a HW flaw in starfire, liberal use 3157c478bd9Sstevel@tonic-gate * of bootbus intrs under heavy system load 3167c478bd9Sstevel@tonic-gate * may cause the machine to arbstop. The workaround 3177c478bd9Sstevel@tonic-gate * is to provide a polling mechanism thru the signature 3187c478bd9Sstevel@tonic-gate * block interface to allow another way for the SSP to 3197c478bd9Sstevel@tonic-gate * interrupt the host. Applications like IDN which generate 3207c478bd9Sstevel@tonic-gate * a high degree of SSP to host interruptions for 3217c478bd9Sstevel@tonic-gate * synchronization will need to use the polling facility 3227c478bd9Sstevel@tonic-gate * instead of the hw bootbus interrupt mechanism. 3237c478bd9Sstevel@tonic-gate * The HW bootbus intr support is left intact as it 3247c478bd9Sstevel@tonic-gate * will still be used by existing SSP applications for system 3257c478bd9Sstevel@tonic-gate * recovery in the event of system hangs etc.. In such situations, 3267c478bd9Sstevel@tonic-gate * HW bootbus intr is a better mechanism as it is HW generated 3277c478bd9Sstevel@tonic-gate * level 15 interrupt that has a better chance of kicking 3287c478bd9Sstevel@tonic-gate * a otherwise hung OS into recovery. 3297c478bd9Sstevel@tonic-gate * 3307c478bd9Sstevel@tonic-gate * Polling is done by scheduling a constant tick timer 3317c478bd9Sstevel@tonic-gate * interrupt at a certain predefined interval. 3327c478bd9Sstevel@tonic-gate * The handler will do a poll and if there is a 3337c478bd9Sstevel@tonic-gate * "intr" request, scheduled a soft level 13 intr 3347c478bd9Sstevel@tonic-gate * to handle it. Allocate the inum for the level 3357c478bd9Sstevel@tonic-gate * 13 intr here. 3367c478bd9Sstevel@tonic-gate */ 337*b0fc0e77Sgovinda bbus_poll_inum = add_softintr(PIL_13, bbus_poll, 0, SOFTINT_ST); 3387c478bd9Sstevel@tonic-gate } 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate static void 3417c478bd9Sstevel@tonic-gate sgnblk_poll_init() 3427c478bd9Sstevel@tonic-gate { 3437c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&sgnblk_mutex)); 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate mutex_init(&sgnblk_poll_mutex, NULL, 3467c478bd9Sstevel@tonic-gate MUTEX_SPIN, (void *)ipltospl(PIL_14)); 3477c478bd9Sstevel@tonic-gate sgnblk_pollcpu = SIGBCPU->cpu_id; 3487c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 3497c478bd9Sstevel@tonic-gate sgnblk_poll_time.cyt_when = 0ull; 3507c478bd9Sstevel@tonic-gate sgnblk_poll_time.cyt_interval = sgnblk_poll_interval * 1000ull; 3517c478bd9Sstevel@tonic-gate #ifdef THROTTLE 3527c478bd9Sstevel@tonic-gate sgnblk_poll_cycid = cyclic_add(&sgnblk_poll_cychandler, 3537c478bd9Sstevel@tonic-gate &sgnblk_poll_time); 3547c478bd9Sstevel@tonic-gate #else /* THROTTLE */ 3557c478bd9Sstevel@tonic-gate (void) cyclic_add(&sgnblk_poll_cychandler, &sgnblk_poll_time); 3567c478bd9Sstevel@tonic-gate #endif /* THROTTLE */ 3577c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 3587c478bd9Sstevel@tonic-gate ASSERT(sgnblk_pollcpu == SIGBCPU->cpu_id); 3597c478bd9Sstevel@tonic-gate } 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate int 3627c478bd9Sstevel@tonic-gate sgnblk_poll_register(void(*func)(processorid_t cpu_id, 3637c478bd9Sstevel@tonic-gate cpu_sgnblk_t *cpu_sgnblkp)) 3647c478bd9Sstevel@tonic-gate { 3657c478bd9Sstevel@tonic-gate int i; 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate /* 3687c478bd9Sstevel@tonic-gate * See if we need to initialize 3697c478bd9Sstevel@tonic-gate * sgnblk polling 3707c478bd9Sstevel@tonic-gate */ 3717c478bd9Sstevel@tonic-gate mutex_enter(&sgnblk_mutex); 3727c478bd9Sstevel@tonic-gate if (sgnblk_pollcpu == -1) 3737c478bd9Sstevel@tonic-gate sgnblk_poll_init(); 3747c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_mutex); 3757c478bd9Sstevel@tonic-gate 3767c478bd9Sstevel@tonic-gate mutex_enter(&sgnblk_poll_mutex); 3777c478bd9Sstevel@tonic-gate 3787c478bd9Sstevel@tonic-gate /* 3797c478bd9Sstevel@tonic-gate * Look for a empty slot 3807c478bd9Sstevel@tonic-gate */ 3817c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SGNBLK_POLL_CLNT; i++) { 3827c478bd9Sstevel@tonic-gate if (pollclntfunc[i] == NULL) { 3837c478bd9Sstevel@tonic-gate pollclntfunc[i] = func; 3847c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_poll_mutex); 3857c478bd9Sstevel@tonic-gate return (1); 3867c478bd9Sstevel@tonic-gate } 3877c478bd9Sstevel@tonic-gate } 3887c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_poll_mutex); 3897c478bd9Sstevel@tonic-gate return (0); /* failed */ 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate int 3937c478bd9Sstevel@tonic-gate sgnblk_poll_unregister(void(*func)(processorid_t cpu_id, 3947c478bd9Sstevel@tonic-gate cpu_sgnblk_t *cpu_sgnblkp)) 3957c478bd9Sstevel@tonic-gate { 3967c478bd9Sstevel@tonic-gate int i; 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate mutex_enter(&sgnblk_poll_mutex); 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate /* 4017c478bd9Sstevel@tonic-gate * Look for the slot matching the function passed in. 4027c478bd9Sstevel@tonic-gate */ 4037c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SGNBLK_POLL_CLNT; i++) { 4047c478bd9Sstevel@tonic-gate if (pollclntfunc[i] == func) { 4057c478bd9Sstevel@tonic-gate pollclntfunc[i] = NULL; 4067c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_poll_mutex); 4077c478bd9Sstevel@tonic-gate return (1); 4087c478bd9Sstevel@tonic-gate } 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_poll_mutex); 4117c478bd9Sstevel@tonic-gate return (0); /* failed */ 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate /* 4167c478bd9Sstevel@tonic-gate * For DR support. 4177c478bd9Sstevel@tonic-gate * Juggle poll tick client to another cpu 4187c478bd9Sstevel@tonic-gate * Assumed to be called single threaded. 4197c478bd9Sstevel@tonic-gate */ 4207c478bd9Sstevel@tonic-gate void 4217c478bd9Sstevel@tonic-gate juggle_sgnblk_poll(struct cpu *cp) 4227c478bd9Sstevel@tonic-gate { 4237c478bd9Sstevel@tonic-gate int i; 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate mutex_enter(&sgnblk_mutex); 4267c478bd9Sstevel@tonic-gate 4277c478bd9Sstevel@tonic-gate if (sgnblk_pollcpu == -1 || 4287c478bd9Sstevel@tonic-gate (cp != NULL && sgnblk_pollcpu == cp->cpu_id)) { 4297c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_mutex); 4307c478bd9Sstevel@tonic-gate return; 4317c478bd9Sstevel@tonic-gate } 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate /* 4347c478bd9Sstevel@tonic-gate * Disable by simply returning here 4357c478bd9Sstevel@tonic-gate * Passing a null cp is assumed to be 4367c478bd9Sstevel@tonic-gate * sgnpoll disable request. 4377c478bd9Sstevel@tonic-gate */ 4387c478bd9Sstevel@tonic-gate if (cp == NULL) { 4397c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SGNBLK_POLL_REFS; i++) { 4407c478bd9Sstevel@tonic-gate void (*func)(), *arg; 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate if ((func = sgnblk_poll_refs[i].callback) != NULL) { 4437c478bd9Sstevel@tonic-gate arg = sgnblk_poll_refs[i].arg; 4447c478bd9Sstevel@tonic-gate (*func)(NULL, arg); 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate } 4477c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_mutex); 4487c478bd9Sstevel@tonic-gate return; 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate sgnblk_pollcpu = cp->cpu_id; 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SGNBLK_POLL_REFS; i++) { 4547c478bd9Sstevel@tonic-gate void (*func)(), *arg; 4557c478bd9Sstevel@tonic-gate 4567c478bd9Sstevel@tonic-gate if ((func = sgnblk_poll_refs[i].callback) != NULL) { 4577c478bd9Sstevel@tonic-gate arg = sgnblk_poll_refs[i].arg; 4587c478bd9Sstevel@tonic-gate (*func)(cpu_sgnblkp[sgnblk_pollcpu], arg); 4597c478bd9Sstevel@tonic-gate } 4607c478bd9Sstevel@tonic-gate } 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_mutex); 4637c478bd9Sstevel@tonic-gate } 4647c478bd9Sstevel@tonic-gate 4657c478bd9Sstevel@tonic-gate #ifdef THROTTLE 4667c478bd9Sstevel@tonic-gate /*ARGSUSED0*/ 4677c478bd9Sstevel@tonic-gate static void 4687c478bd9Sstevel@tonic-gate _sgnblk_poll_throttle(void *unused) 4697c478bd9Sstevel@tonic-gate { 4707c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 4717c478bd9Sstevel@tonic-gate if (sgnblk_poll_cycid != CYCLIC_NONE) { 4727c478bd9Sstevel@tonic-gate cyclic_remove(sgnblk_poll_cycid); 4737c478bd9Sstevel@tonic-gate sgnblk_poll_cycid = CYCLIC_NONE; 4747c478bd9Sstevel@tonic-gate } 4757c478bd9Sstevel@tonic-gate 4767c478bd9Sstevel@tonic-gate if (sgnblk_poll_time.cyt_interval > 0ull) 4777c478bd9Sstevel@tonic-gate sgnblk_poll_cycid = cyclic_add(&sgnblk_poll_cychandler, 4787c478bd9Sstevel@tonic-gate &sgnblk_poll_time); 4797c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 4807c478bd9Sstevel@tonic-gate } 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate /* 4837c478bd9Sstevel@tonic-gate * We don't want to remove the cyclic within the context of 4847c478bd9Sstevel@tonic-gate * the handler so we kick off the throttle in background 4857c478bd9Sstevel@tonic-gate * via a timeout call. 4867c478bd9Sstevel@tonic-gate */ 4877c478bd9Sstevel@tonic-gate static void 4887c478bd9Sstevel@tonic-gate sgnblk_poll_throttle(uint64_t new_interval) 4897c478bd9Sstevel@tonic-gate { 4907c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 4917c478bd9Sstevel@tonic-gate sgnblk_poll_time.cyt_when = 0ull; 4927c478bd9Sstevel@tonic-gate sgnblk_poll_time.cyt_interval = new_interval * 1000ull; 4937c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 4947c478bd9Sstevel@tonic-gate 4957c478bd9Sstevel@tonic-gate (void) timeout(_sgnblk_poll_throttle, NULL, (clock_t)0); 4967c478bd9Sstevel@tonic-gate } 4977c478bd9Sstevel@tonic-gate #endif /* THROTTLE */ 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate /* 5007c478bd9Sstevel@tonic-gate * High priority interrupt handler (PIL_14) 5017c478bd9Sstevel@tonic-gate * for signature block mbox polling. 5027c478bd9Sstevel@tonic-gate */ 5037c478bd9Sstevel@tonic-gate /*ARGSUSED0*/ 5047c478bd9Sstevel@tonic-gate static void 5057c478bd9Sstevel@tonic-gate sgnblk_poll_handler(void *unused) 5067c478bd9Sstevel@tonic-gate { 5077c478bd9Sstevel@tonic-gate processorid_t cpuid = SIGBCPU->cpu_id; 5087c478bd9Sstevel@tonic-gate #ifdef THROTTLE 5097c478bd9Sstevel@tonic-gate static int64_t sb_window = -1; 5107c478bd9Sstevel@tonic-gate static uint64_t sb_interval = 0; 5117c478bd9Sstevel@tonic-gate #endif /* THROTTLE */ 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate if (cpu_sgnblkp[cpuid] == NULL) 5147c478bd9Sstevel@tonic-gate return; 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate /* 5177c478bd9Sstevel@tonic-gate * Poll for SSP requests 5187c478bd9Sstevel@tonic-gate */ 5197c478bd9Sstevel@tonic-gate if (cpu_sgnblkp[cpuid]->sigb_host_mbox.intr == SIGB_INTR_SEND) { 5207c478bd9Sstevel@tonic-gate /* reset the flag - sure hope this is atomic */ 5217c478bd9Sstevel@tonic-gate cpu_sgnblkp[cpuid]->sigb_host_mbox.intr = SIGB_INTR_OFF; 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate #ifdef THROTTLE 5247c478bd9Sstevel@tonic-gate /* 5257c478bd9Sstevel@tonic-gate * Go into fast poll mode for a short duration 5267c478bd9Sstevel@tonic-gate * (SGNBLK_POLL_FAST_WIN) in SGNBLK_POLL_FAST interval. 5277c478bd9Sstevel@tonic-gate * The assumption here is that we just got activity 5287c478bd9Sstevel@tonic-gate * on the mbox poll, the probability of more coming down 5297c478bd9Sstevel@tonic-gate * the pipe is high - so let's look more often. 5307c478bd9Sstevel@tonic-gate */ 5317c478bd9Sstevel@tonic-gate if ((sb_window < 0) && (sb_interval > sgnblk_poll_fast)) { 5327c478bd9Sstevel@tonic-gate sb_interval = sgnblk_poll_fast; 5337c478bd9Sstevel@tonic-gate sgnblk_poll_throttle(sb_interval); 5347c478bd9Sstevel@tonic-gate } 5357c478bd9Sstevel@tonic-gate sb_window = sgnblk_poll_fast_win; 5367c478bd9Sstevel@tonic-gate #endif /* THROTTLE */ 5377c478bd9Sstevel@tonic-gate 5387c478bd9Sstevel@tonic-gate /* schedule poll processing */ 5397c478bd9Sstevel@tonic-gate setsoftint(bbus_poll_inum); 5407c478bd9Sstevel@tonic-gate 5417c478bd9Sstevel@tonic-gate #ifdef THROTTLE 5427c478bd9Sstevel@tonic-gate } else if (sb_window >= 0) { 5437c478bd9Sstevel@tonic-gate /* Revert to slow polling once fast window ends */ 5447c478bd9Sstevel@tonic-gate if ((--sb_window < 0) && 5457c478bd9Sstevel@tonic-gate (sb_interval < sgnblk_poll_interval)) { 5467c478bd9Sstevel@tonic-gate sb_interval = sgnblk_poll_interval; 5477c478bd9Sstevel@tonic-gate sgnblk_poll_throttle(sb_interval); 5487c478bd9Sstevel@tonic-gate } 5497c478bd9Sstevel@tonic-gate #endif /* THROTTLE */ 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 5547c478bd9Sstevel@tonic-gate static uint_t 5557c478bd9Sstevel@tonic-gate bbus_poll(caddr_t arg1, caddr_t arg2) 5567c478bd9Sstevel@tonic-gate { 5577c478bd9Sstevel@tonic-gate int i; 5587c478bd9Sstevel@tonic-gate processorid_t cpu_id = SIGBCPU->cpu_id; 5597c478bd9Sstevel@tonic-gate cpu_sgnblk_t *sgnblkp = cpu_sgnblkp[cpu_id]; 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate /* 5627c478bd9Sstevel@tonic-gate * Go thru the poll client array and call the 5637c478bd9Sstevel@tonic-gate * poll client functions one by one 5647c478bd9Sstevel@tonic-gate */ 5657c478bd9Sstevel@tonic-gate mutex_enter(&sgnblk_poll_mutex); 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SGNBLK_POLL_CLNT; i++) { 5687c478bd9Sstevel@tonic-gate void (*func)(processorid_t cpuid, cpu_sgnblk_t *sgnblkp); 5697c478bd9Sstevel@tonic-gate 5707c478bd9Sstevel@tonic-gate if ((func = pollclntfunc[i]) != NULL) { 5717c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_poll_mutex); 5727c478bd9Sstevel@tonic-gate (*func)(cpu_id, sgnblkp); 5737c478bd9Sstevel@tonic-gate mutex_enter(&sgnblk_poll_mutex); 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate } 5767c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_poll_mutex); 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate return (1); 5797c478bd9Sstevel@tonic-gate } 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate int 5827c478bd9Sstevel@tonic-gate sgnblk_poll_reference(void (*callback)(cpu_sgnblk_t *sigb, void *arg), 5837c478bd9Sstevel@tonic-gate void *arg) 5847c478bd9Sstevel@tonic-gate { 5857c478bd9Sstevel@tonic-gate int i, slot; 5867c478bd9Sstevel@tonic-gate cpu_sgnblk_t *sigbp; 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate if (callback == NULL) 5897c478bd9Sstevel@tonic-gate return (-1); 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate mutex_enter(&sgnblk_mutex); 5927c478bd9Sstevel@tonic-gate /* 5937c478bd9Sstevel@tonic-gate * First verify caller is not already registered. 5947c478bd9Sstevel@tonic-gate */ 5957c478bd9Sstevel@tonic-gate slot = -1; 5967c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SGNBLK_POLL_REFS; i++) { 5977c478bd9Sstevel@tonic-gate if ((slot == -1) && (sgnblk_poll_refs[i].callback == NULL)) { 5987c478bd9Sstevel@tonic-gate slot = i; 5997c478bd9Sstevel@tonic-gate continue; 6007c478bd9Sstevel@tonic-gate } 6017c478bd9Sstevel@tonic-gate if (sgnblk_poll_refs[i].callback == callback) { 6027c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_mutex); 6037c478bd9Sstevel@tonic-gate return (-1); 6047c478bd9Sstevel@tonic-gate } 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate /* 6077c478bd9Sstevel@tonic-gate * Now find an empty entry. 6087c478bd9Sstevel@tonic-gate */ 6097c478bd9Sstevel@tonic-gate if (slot == -1) { 6107c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_mutex); 6117c478bd9Sstevel@tonic-gate return (-1); 6127c478bd9Sstevel@tonic-gate } 6137c478bd9Sstevel@tonic-gate sgnblk_poll_refs[slot].callback = callback; 6147c478bd9Sstevel@tonic-gate sgnblk_poll_refs[slot].arg = arg; 6157c478bd9Sstevel@tonic-gate 6167c478bd9Sstevel@tonic-gate sigbp = (sgnblk_pollcpu != -1) ? cpu_sgnblkp[sgnblk_pollcpu] : NULL; 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate (*callback)(sigbp, arg); 6197c478bd9Sstevel@tonic-gate 6207c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_mutex); 6217c478bd9Sstevel@tonic-gate 6227c478bd9Sstevel@tonic-gate return (0); 6237c478bd9Sstevel@tonic-gate } 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate void 6267c478bd9Sstevel@tonic-gate sgnblk_poll_unreference(void (*callback)(cpu_sgnblk_t *sigb, void *arg)) 6277c478bd9Sstevel@tonic-gate { 6287c478bd9Sstevel@tonic-gate int i; 6297c478bd9Sstevel@tonic-gate 6307c478bd9Sstevel@tonic-gate mutex_enter(&sgnblk_mutex); 6317c478bd9Sstevel@tonic-gate for (i = 0; i < MAX_SGNBLK_POLL_REFS; i++) { 6327c478bd9Sstevel@tonic-gate if (sgnblk_poll_refs[i].callback == callback) { 6337c478bd9Sstevel@tonic-gate void *arg; 6347c478bd9Sstevel@tonic-gate 6357c478bd9Sstevel@tonic-gate arg = sgnblk_poll_refs[i].arg; 6367c478bd9Sstevel@tonic-gate (*callback)(NULL, arg); 6377c478bd9Sstevel@tonic-gate sgnblk_poll_refs[i].callback = NULL; 6387c478bd9Sstevel@tonic-gate sgnblk_poll_refs[i].arg = NULL; 6397c478bd9Sstevel@tonic-gate break; 6407c478bd9Sstevel@tonic-gate } 6417c478bd9Sstevel@tonic-gate } 6427c478bd9Sstevel@tonic-gate mutex_exit(&sgnblk_mutex); 6437c478bd9Sstevel@tonic-gate } 644