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 5b0fc0e77Sgovinda * Common Development and Distribution License (the "License"). 6b0fc0e77Sgovinda * 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*09b1eac2SEvan Yan * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_PCI_IB_H 277c478bd9Sstevel@tonic-gate #define _SYS_PCI_IB_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #ifdef __cplusplus 307c478bd9Sstevel@tonic-gate extern "C" { 317c478bd9Sstevel@tonic-gate #endif 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 347851eb82Sschwartz #include <sys/pci_tools.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate typedef uint8_t ib_ino_t; 377c478bd9Sstevel@tonic-gate typedef uint16_t ib_mondo_t; 387c478bd9Sstevel@tonic-gate typedef struct ib_ino_info ib_ino_info_t; 39b0fc0e77Sgovinda typedef struct ib_ino_pil ib_ino_pil_t; 407c478bd9Sstevel@tonic-gate typedef uint8_t device_num_t; 417c478bd9Sstevel@tonic-gate typedef uint8_t interrupt_t; 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate /* 447c478bd9Sstevel@tonic-gate * interrupt block soft state structure: 457c478bd9Sstevel@tonic-gate * 467c478bd9Sstevel@tonic-gate * Each pci node may share an interrupt block structure with its peer 477c478bd9Sstevel@tonic-gate * node or have its own private interrupt block structure. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate typedef struct ib ib_t; 507c478bd9Sstevel@tonic-gate struct ib { 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate pci_t *ib_pci_p; /* link back to pci soft state */ 537c478bd9Sstevel@tonic-gate pci_ign_t ib_ign; /* interrupt group # */ 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * PCI slot and onboard I/O interrupt mapping register blocks addresses: 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate uintptr_t ib_slot_intr_map_regs; 597c478bd9Sstevel@tonic-gate #define ib_intr_map_regs ib_slot_intr_map_regs 607c478bd9Sstevel@tonic-gate uintptr_t ib_obio_intr_map_regs; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate /* 637c478bd9Sstevel@tonic-gate * PCI slot and onboard I/O clear interrupt register block addresses: 647c478bd9Sstevel@tonic-gate */ 657c478bd9Sstevel@tonic-gate uintptr_t ib_slot_clear_intr_regs; 667c478bd9Sstevel@tonic-gate uintptr_t ib_obio_clear_intr_regs; 677c478bd9Sstevel@tonic-gate 687c478bd9Sstevel@tonic-gate /* 697c478bd9Sstevel@tonic-gate * UPA expansion slot interrupt mapping register addresses: 707c478bd9Sstevel@tonic-gate */ 717c478bd9Sstevel@tonic-gate volatile uint64_t *ib_upa_imr[2]; 727c478bd9Sstevel@tonic-gate uint64_t ib_upa_imr_state[2]; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * Interrupt retry register address: 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate volatile uint64_t *ib_intr_retry_timer_reg; 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate /* 807c478bd9Sstevel@tonic-gate * PCI slot and onboard I/O interrupt state diag register addresses: 817c478bd9Sstevel@tonic-gate */ 827c478bd9Sstevel@tonic-gate volatile uint64_t *ib_slot_intr_state_diag_reg; 837c478bd9Sstevel@tonic-gate volatile uint64_t *ib_obio_intr_state_diag_reg; 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate uint_t ib_max_ino; /* largest supported INO */ 867c478bd9Sstevel@tonic-gate ib_ino_info_t *ib_ino_lst; /* ino link list */ 877c478bd9Sstevel@tonic-gate kmutex_t ib_ino_lst_mutex; /* mutex for ino link list */ 887c478bd9Sstevel@tonic-gate kmutex_t ib_intr_lock; /* lock for internal intr */ 897c478bd9Sstevel@tonic-gate uint16_t ib_map_reg_counters[8]; /* counters for shared map */ 907c478bd9Sstevel@tonic-gate /* registers */ 917c478bd9Sstevel@tonic-gate }; 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #define PCI_PULSE_INO 0x80000000 947c478bd9Sstevel@tonic-gate #define PSYCHO_MAX_INO 0x3f 957c478bd9Sstevel@tonic-gate #define SCHIZO_MAX_INO 0x37 967c478bd9Sstevel@tonic-gate #define PCI_INO_BITS 6 /* INO#s are 6 bits long */ 977c478bd9Sstevel@tonic-gate #define PCI_IGN_BITS 5 /* IGN#s are 5 bits long */ 987c478bd9Sstevel@tonic-gate 997c478bd9Sstevel@tonic-gate /* 100b0fc0e77Sgovinda * ih structure: one per every consumer of each ino and pil pair with interrupt 101b0fc0e77Sgovinda * registered. 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate typedef struct ih { 1047c478bd9Sstevel@tonic-gate dev_info_t *ih_dip; /* devinfo structure */ 1057c478bd9Sstevel@tonic-gate uint32_t ih_inum; /* interrupt number for this device */ 1067c478bd9Sstevel@tonic-gate uint_t ih_intr_state; /* Only used for fixed interrupts */ 1077c478bd9Sstevel@tonic-gate uint_t (*ih_handler)(); /* interrupt handler */ 1087c478bd9Sstevel@tonic-gate caddr_t ih_handler_arg1; /* interrupt handler argument #1 */ 1097c478bd9Sstevel@tonic-gate caddr_t ih_handler_arg2; /* interrupt handler argument #2 */ 1107c478bd9Sstevel@tonic-gate ddi_acc_handle_t ih_config_handle; /* config space reg map handle */ 1117c478bd9Sstevel@tonic-gate struct ih *ih_next; /* next entry in list */ 1127c478bd9Sstevel@tonic-gate uint64_t ih_ticks; /* ticks spent in this handler */ 1137c478bd9Sstevel@tonic-gate uint64_t ih_nsec; /* nsec spent in this handler */ 114b0fc0e77Sgovinda kstat_t *ih_ksp; /* pointer to kstat information */ 115b0fc0e77Sgovinda ib_ino_pil_t *ih_ipil_p; /* only for use by kstat */ 1167c478bd9Sstevel@tonic-gate } ih_t; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate /* Only used for fixed or legacy interrupts */ 1197c478bd9Sstevel@tonic-gate #define PCI_INTR_STATE_DISABLE 0 /* disabled */ 1207c478bd9Sstevel@tonic-gate #define PCI_INTR_STATE_ENABLE 1 /* enabled */ 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* 123b0fc0e77Sgovinda * ino_pil structure: one per each ino and pil pair with interrupt registered 124b0fc0e77Sgovinda */ 125b0fc0e77Sgovinda struct ib_ino_pil { 126b0fc0e77Sgovinda ushort_t ipil_pil; /* PIL for this ino */ 127b0fc0e77Sgovinda ushort_t ipil_ih_size; /* size of ih_t list */ 128b0fc0e77Sgovinda ih_t *ipil_ih_head; /* ih_t list head */ 129b0fc0e77Sgovinda ih_t *ipil_ih_tail; /* ih_t list tail */ 130b0fc0e77Sgovinda ih_t *ipil_ih_start; /* starting point in ih_t list */ 131b0fc0e77Sgovinda ib_ino_info_t *ipil_ino_p; /* pointer to ib_ino_info_t */ 132b0fc0e77Sgovinda ib_ino_pil_t *ipil_next_p; /* pointer to next ib_ino_pil_t */ 133b0fc0e77Sgovinda }; 134b0fc0e77Sgovinda 135b0fc0e77Sgovinda /* 136b0fc0e77Sgovinda * ino structure: one per each ino with interrupt registered 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate struct ib_ino_info { 1397c478bd9Sstevel@tonic-gate ib_ino_t ino_ino; /* INO number - 8 bit */ 140b0fc0e77Sgovinda uint64_t ino_mondo; /* store mondo number */ 1417c478bd9Sstevel@tonic-gate uint8_t ino_slot_no; /* PCI slot number 0-8 */ 1427c478bd9Sstevel@tonic-gate ib_t *ino_ib_p; /* link back to interrupt block state */ 1437c478bd9Sstevel@tonic-gate volatile uint64_t *ino_clr_reg; /* ino interrupt clear register */ 1447c478bd9Sstevel@tonic-gate volatile uint64_t *ino_map_reg; /* ino interrupt mapping register */ 1457c478bd9Sstevel@tonic-gate uint64_t ino_map_reg_save; /* = *ino_map_reg if saved */ 146b0fc0e77Sgovinda volatile uint_t ino_unclaimed_intrs; /* number of unclaimed intrs */ 1477c478bd9Sstevel@tonic-gate clock_t ino_spurintr_begin; /* begin time of spurious intr series */ 1487c478bd9Sstevel@tonic-gate int ino_established; /* ino has been associated with a cpu */ 1497c478bd9Sstevel@tonic-gate uint32_t ino_cpuid; /* cpu that ino is targeting */ 1507c478bd9Sstevel@tonic-gate int32_t ino_intr_weight; /* intr weight of devices sharing ino */ 151b0fc0e77Sgovinda ushort_t ino_ipil_size; /* number of ib_ino_pil_t sharing ino */ 152b0fc0e77Sgovinda ushort_t ino_lopil; /* lowest PIL sharing ino */ 153b0fc0e77Sgovinda ushort_t ino_claimed; /* pil bit masks, who claimed intr */ 154b0fc0e77Sgovinda ib_ino_pil_t *ino_ipil_p; /* pointer to first ib_ino_pil_t */ 155b0fc0e77Sgovinda ib_ino_info_t *ino_next_p; /* pointer to next ib_ino_info_t */ 1567c478bd9Sstevel@tonic-gate }; 1577c478bd9Sstevel@tonic-gate 1587c478bd9Sstevel@tonic-gate #define IB_INTR_WAIT 1 /* wait for interrupt completion */ 1597c478bd9Sstevel@tonic-gate #define IB_INTR_NOWAIT 0 /* already handling intr, no wait */ 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate #define IB2CB(ib_p) ((ib_p)->ib_pci_p->pci_cb_p) 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate #define IB_MONDO_TO_INO(mondo) ((ib_ino_t)((mondo) & 0x3f)) 1647c478bd9Sstevel@tonic-gate #define IB_INO_INTR_ON(reg_p) *(reg_p) |= COMMON_INTR_MAP_REG_VALID 1657c478bd9Sstevel@tonic-gate #define IB_INO_INTR_OFF(reg_p) *(reg_p) &= ~COMMON_INTR_MAP_REG_VALID 1667c478bd9Sstevel@tonic-gate #define IB_INO_INTR_RESET(reg_p) *(reg_p) = 0ull 1677c478bd9Sstevel@tonic-gate #define IB_INO_INTR_STATE_REG(ib_p, ino) ((ino) & 0x20 ? \ 1687c478bd9Sstevel@tonic-gate ib_p->ib_obio_intr_state_diag_reg : ib_p->ib_slot_intr_state_diag_reg) 1697c478bd9Sstevel@tonic-gate #define IB_INO_INTR_PENDING(reg_p, ino) \ 1707c478bd9Sstevel@tonic-gate (((*(reg_p) >> (((ino) & 0x1f) << 1)) & COMMON_CLEAR_INTR_REG_MASK) == \ 1717c478bd9Sstevel@tonic-gate COMMON_CLEAR_INTR_REG_PENDING) 1727c478bd9Sstevel@tonic-gate #define IB_INO_INTR_CLEAR(reg_p) *(reg_p) = COMMON_CLEAR_INTR_REG_IDLE 1737c478bd9Sstevel@tonic-gate #define IB_INO_INTR_TRIG(reg_p) *(reg_p) = COMMON_CLEAR_INTR_REG_RECEIVED 1747c478bd9Sstevel@tonic-gate #define IB_INO_INTR_PEND(reg_p) *(reg_p) = COMMON_CLEAR_INTR_REG_PENDING 1757c478bd9Sstevel@tonic-gate #define IB_INO_INTR_ISON(imr) ((imr) >> 31) 1767c478bd9Sstevel@tonic-gate #define IB_IMR2MONDO(imr) \ 1777c478bd9Sstevel@tonic-gate ((imr) & (COMMON_INTR_MAP_REG_IGN | COMMON_INTR_MAP_REG_INO)) 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate #define IB_IS_OBIO_INO(ino) (ino & 0x20) 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate #ifdef _STARFIRE 1827c478bd9Sstevel@tonic-gate /* 1837c478bd9Sstevel@tonic-gate * returns a uniq ino per interrupt mapping register 1847c478bd9Sstevel@tonic-gate * For on board devices, inos are not shared. But for plugin devices, 1857c478bd9Sstevel@tonic-gate * return the 1st ino of the 4 that are sharing the same mapping register. 1867c478bd9Sstevel@tonic-gate */ 1877c478bd9Sstevel@tonic-gate #define IB_GET_MAPREG_INO(ino) \ 188f47a9c50Smathue ((volatile uint64_t *)(uintptr_t)((ino & 0x20) ? \ 189f47a9c50Smathue ino : ((ino >> 2) << 2))) 1907c478bd9Sstevel@tonic-gate #endif /* _STARFIRE */ 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate #define IB_IGN_TO_MONDO(ign, ino) (((ign) << PCI_INO_BITS) | (ino)) 1937c478bd9Sstevel@tonic-gate #define IB_INO_TO_MONDO(ib_p, ino) IB_IGN_TO_MONDO((ib_p)->ib_ign, ino) 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate extern void ib_create(pci_t *pci_p); 1967c478bd9Sstevel@tonic-gate extern void ib_destroy(pci_t *pci_p); 1977c478bd9Sstevel@tonic-gate extern void ib_configure(ib_t *ib_p); 1987c478bd9Sstevel@tonic-gate extern uint64_t ib_get_map_reg(ib_mondo_t mondo, uint32_t cpu_id); 1997c478bd9Sstevel@tonic-gate extern void ib_intr_enable(pci_t *pci_p, ib_ino_t ino); 2007c478bd9Sstevel@tonic-gate extern void ib_intr_disable(ib_t *ib_p, ib_ino_t ino, int wait); 2017c478bd9Sstevel@tonic-gate extern void ib_nintr_clear(ib_t *ib_p, ib_ino_t ino); 2027c478bd9Sstevel@tonic-gate extern void ib_suspend(ib_t *ib_p); 2037c478bd9Sstevel@tonic-gate extern void ib_resume(ib_t *ib_p); 2047c478bd9Sstevel@tonic-gate 2057c478bd9Sstevel@tonic-gate extern ib_ino_info_t *ib_locate_ino(ib_t *ib_p, ib_ino_t ino_num); 206b0fc0e77Sgovinda extern ib_ino_pil_t *ib_new_ino_pil(ib_t *ib_p, ib_ino_t ino_num, uint_t pil, 207b0fc0e77Sgovinda ih_t *ih_p); 208b0fc0e77Sgovinda extern void ib_delete_ino_pil(ib_t *ib_p, ib_ino_pil_t *ipil_p); 2097c478bd9Sstevel@tonic-gate extern void ib_free_ino_all(ib_t *ib_p); 210b0fc0e77Sgovinda extern ib_ino_pil_t *ib_ino_locate_ipil(ib_ino_info_t *ino_p, uint_t pil); 211b0fc0e77Sgovinda extern void ib_ino_add_intr(pci_t *pci_p, ib_ino_pil_t *ipil_p, ih_t *ih_p); 212b0fc0e77Sgovinda extern void ib_ino_rem_intr(pci_t *pci_p, ib_ino_pil_t *ipil_p, ih_t *ih_p); 213b0fc0e77Sgovinda extern ih_t *ib_intr_locate_ih(ib_ino_pil_t *ipil_p, dev_info_t *dip, 2147c478bd9Sstevel@tonic-gate uint32_t inum); 2157c478bd9Sstevel@tonic-gate extern ih_t *ib_alloc_ih(dev_info_t *dip, uint32_t inum, 2167c478bd9Sstevel@tonic-gate uint_t (*int_handler)(caddr_t int_handler_arg1, caddr_t int_handler_arg2), 2177c478bd9Sstevel@tonic-gate caddr_t int_handler_arg1, caddr_t int_handler_arg2); 2187c478bd9Sstevel@tonic-gate extern void ib_free_ih(ih_t *ih_p); 2197c478bd9Sstevel@tonic-gate extern void ib_ino_map_reg_share(ib_t *ib_p, ib_ino_t ino, 2207c478bd9Sstevel@tonic-gate ib_ino_info_t *ino_p); 2217c478bd9Sstevel@tonic-gate extern int ib_ino_map_reg_unshare(ib_t *ib_p, ib_ino_t ino, 2227c478bd9Sstevel@tonic-gate ib_ino_info_t *ino_p); 2237c478bd9Sstevel@tonic-gate extern uint32_t ib_register_intr(ib_t *ib_p, ib_mondo_t mondo, uint_t pil, 2247c478bd9Sstevel@tonic-gate uint_t (*handler)(caddr_t arg), caddr_t arg); 2257c478bd9Sstevel@tonic-gate extern void ib_unregister_intr(ib_mondo_t mondo); 2267c478bd9Sstevel@tonic-gate extern void ib_intr_dist_nintr(ib_t *ib_p, ib_ino_t ino, 2277c478bd9Sstevel@tonic-gate volatile uint64_t *imr_p); 2287c478bd9Sstevel@tonic-gate extern void ib_intr_dist_all(void *arg, int32_t max_weight, int32_t weight); 2297851eb82Sschwartz extern void ib_cpu_ticks_to_ih_nsec(ib_t *ib_p, ih_t *ih_p, uint32_t cpu_id); 230*09b1eac2SEvan Yan extern int ib_update_intr_state(pci_t *pci_p, dev_info_t *rdip, 231*09b1eac2SEvan Yan ddi_intr_handle_impl_t *hdlp, uint_t new_intr_state); 232*09b1eac2SEvan Yan extern int ib_get_intr_target(pci_t *pci_p, ib_ino_t ino, int *cpu_id_p); 233*09b1eac2SEvan Yan extern int ib_set_intr_target(pci_t *pci_p, ib_ino_t ino, int cpu_id); 2347851eb82Sschwartz extern uint8_t ib_get_ino_devs(ib_t *ib_p, uint32_t ino, uint8_t *devs_ret, 2357851eb82Sschwartz pcitool_intr_dev_t *devs); 2367851eb82Sschwartz extern void ib_log_new_cpu(ib_t *ib_p, uint32_t old_cpu_id, uint32_t new_cpu_id, 2377851eb82Sschwartz uint32_t ino); 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate extern int pci_pil[]; 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate #endif 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate #endif /* _SYS_PCI_IB_H */ 246