162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright 2014 IBM Corp. 462306a36Sopenharmony_ci */ 562306a36Sopenharmony_ci 662306a36Sopenharmony_ci#ifndef _CXL_H_ 762306a36Sopenharmony_ci#define _CXL_H_ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#include <linux/interrupt.h> 1062306a36Sopenharmony_ci#include <linux/semaphore.h> 1162306a36Sopenharmony_ci#include <linux/device.h> 1262306a36Sopenharmony_ci#include <linux/types.h> 1362306a36Sopenharmony_ci#include <linux/cdev.h> 1462306a36Sopenharmony_ci#include <linux/pid.h> 1562306a36Sopenharmony_ci#include <linux/io.h> 1662306a36Sopenharmony_ci#include <linux/pci.h> 1762306a36Sopenharmony_ci#include <linux/fs.h> 1862306a36Sopenharmony_ci#include <asm/cputable.h> 1962306a36Sopenharmony_ci#include <asm/mmu.h> 2062306a36Sopenharmony_ci#include <asm/reg.h> 2162306a36Sopenharmony_ci#include <misc/cxl-base.h> 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#include <misc/cxl.h> 2462306a36Sopenharmony_ci#include <uapi/misc/cxl.h> 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ciextern uint cxl_verbose; 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_cistruct property; 2962306a36Sopenharmony_ci 3062306a36Sopenharmony_ci#define CXL_TIMEOUT 5 3162306a36Sopenharmony_ci 3262306a36Sopenharmony_ci/* 3362306a36Sopenharmony_ci * Bump version each time a user API change is made, whether it is 3462306a36Sopenharmony_ci * backwards compatible ot not. 3562306a36Sopenharmony_ci */ 3662306a36Sopenharmony_ci#define CXL_API_VERSION 3 3762306a36Sopenharmony_ci#define CXL_API_VERSION_COMPATIBLE 1 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci/* 4062306a36Sopenharmony_ci * Opaque types to avoid accidentally passing registers for the wrong MMIO 4162306a36Sopenharmony_ci * 4262306a36Sopenharmony_ci * At the end of the day, I'm not married to using typedef here, but it might 4362306a36Sopenharmony_ci * (and has!) help avoid bugs like mixing up CXL_PSL_CtxTime and 4462306a36Sopenharmony_ci * CXL_PSL_CtxTime_An, or calling cxl_p1n_write instead of cxl_p1_write. 4562306a36Sopenharmony_ci * 4662306a36Sopenharmony_ci * I'm quite happy if these are changed back to #defines before upstreaming, it 4762306a36Sopenharmony_ci * should be little more than a regexp search+replace operation in this file. 4862306a36Sopenharmony_ci */ 4962306a36Sopenharmony_citypedef struct { 5062306a36Sopenharmony_ci const int x; 5162306a36Sopenharmony_ci} cxl_p1_reg_t; 5262306a36Sopenharmony_citypedef struct { 5362306a36Sopenharmony_ci const int x; 5462306a36Sopenharmony_ci} cxl_p1n_reg_t; 5562306a36Sopenharmony_citypedef struct { 5662306a36Sopenharmony_ci const int x; 5762306a36Sopenharmony_ci} cxl_p2n_reg_t; 5862306a36Sopenharmony_ci#define cxl_reg_off(reg) \ 5962306a36Sopenharmony_ci (reg.x) 6062306a36Sopenharmony_ci 6162306a36Sopenharmony_ci/* Memory maps. Ref CXL Appendix A */ 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci/* PSL Privilege 1 Memory Map */ 6462306a36Sopenharmony_ci/* Configuration and Control area - CAIA 1&2 */ 6562306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_CtxTime = {0x0000}; 6662306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_ErrIVTE = {0x0008}; 6762306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_KEY1 = {0x0010}; 6862306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_KEY2 = {0x0018}; 6962306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_Control = {0x0020}; 7062306a36Sopenharmony_ci/* Downloading */ 7162306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_DLCNTL = {0x0060}; 7262306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_DLADDR = {0x0068}; 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_ci/* PSL Lookaside Buffer Management Area - CAIA 1 */ 7562306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_LBISEL = {0x0080}; 7662306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_SLBIE = {0x0088}; 7762306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_SLBIA = {0x0090}; 7862306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_TLBIE = {0x00A0}; 7962306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_TLBIA = {0x00A8}; 8062306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_AFUSEL = {0x00B0}; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci/* 0x00C0:7EFF Implementation dependent area */ 8362306a36Sopenharmony_ci/* PSL registers - CAIA 1 */ 8462306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_FIR1 = {0x0100}; 8562306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_FIR2 = {0x0108}; 8662306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_Timebase = {0x0110}; 8762306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_VERSION = {0x0118}; 8862306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_RESLCKTO = {0x0128}; 8962306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_TB_CTLSTAT = {0x0140}; 9062306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_FIR_CNTL = {0x0148}; 9162306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_DSNDCTL = {0x0150}; 9262306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_SNWRALLOC = {0x0158}; 9362306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL_TRACE = {0x0170}; 9462306a36Sopenharmony_ci/* PSL registers - CAIA 2 */ 9562306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_CONTROL = {0x0020}; 9662306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_XSL9_INV = {0x0110}; 9762306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_XSL9_DBG = {0x0130}; 9862306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_XSL9_DEF = {0x0140}; 9962306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_XSL9_DSNCTL = {0x0168}; 10062306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_FIR1 = {0x0300}; 10162306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_FIR_MASK = {0x0308}; 10262306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_Timebase = {0x0310}; 10362306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_DEBUG = {0x0320}; 10462306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_FIR_CNTL = {0x0348}; 10562306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_DSNDCTL = {0x0350}; 10662306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_TB_CTLSTAT = {0x0340}; 10762306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_TRACECFG = {0x0368}; 10862306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_APCDEDALLOC = {0x0378}; 10962306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_APCDEDTYPE = {0x0380}; 11062306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_TNR_ADDR = {0x0388}; 11162306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_CTCCFG = {0x0390}; 11262306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_PSL9_GP_CT = {0x0398}; 11362306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_XSL9_IERAT = {0x0588}; 11462306a36Sopenharmony_cistatic const cxl_p1_reg_t CXL_XSL9_ILPP = {0x0590}; 11562306a36Sopenharmony_ci 11662306a36Sopenharmony_ci/* 0x7F00:7FFF Reserved PCIe MSI-X Pending Bit Array area */ 11762306a36Sopenharmony_ci/* 0x8000:FFFF Reserved PCIe MSI-X Table Area */ 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci/* PSL Slice Privilege 1 Memory Map */ 12062306a36Sopenharmony_ci/* Configuration Area - CAIA 1&2 */ 12162306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_SR_An = {0x00}; 12262306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_LPID_An = {0x08}; 12362306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_AMBAR_An = {0x10}; 12462306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_SPOffset_An = {0x18}; 12562306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_ID_An = {0x20}; 12662306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_SERR_An = {0x28}; 12762306a36Sopenharmony_ci/* Memory Management and Lookaside Buffer Management - CAIA 1*/ 12862306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_SDR_An = {0x30}; 12962306a36Sopenharmony_ci/* Memory Management and Lookaside Buffer Management - CAIA 1&2 */ 13062306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_AMOR_An = {0x38}; 13162306a36Sopenharmony_ci/* Pointer Area - CAIA 1&2 */ 13262306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_HAURP_An = {0x80}; 13362306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_SPAP_An = {0x88}; 13462306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_LLCMD_An = {0x90}; 13562306a36Sopenharmony_ci/* Control Area - CAIA 1&2 */ 13662306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_SCNTL_An = {0xA0}; 13762306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_CtxTime_An = {0xA8}; 13862306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_IVTE_Offset_An = {0xB0}; 13962306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_IVTE_Limit_An = {0xB8}; 14062306a36Sopenharmony_ci/* 0xC0:FF Implementation Dependent Area - CAIA 1&2 */ 14162306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_FIR_SLICE_An = {0xC0}; 14262306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_AFU_DEBUG_An = {0xC8}; 14362306a36Sopenharmony_ci/* 0xC0:FF Implementation Dependent Area - CAIA 1 */ 14462306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_APCALLOC_A = {0xD0}; 14562306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_COALLOC_A = {0xD8}; 14662306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_RXCTL_A = {0xE0}; 14762306a36Sopenharmony_cistatic const cxl_p1n_reg_t CXL_PSL_SLICE_TRACE = {0xE8}; 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_ci/* PSL Slice Privilege 2 Memory Map */ 15062306a36Sopenharmony_ci/* Configuration and Control Area - CAIA 1&2 */ 15162306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_PSL_PID_TID_An = {0x000}; 15262306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_CSRP_An = {0x008}; 15362306a36Sopenharmony_ci/* Configuration and Control Area - CAIA 1 */ 15462306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_AURP0_An = {0x010}; 15562306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_AURP1_An = {0x018}; 15662306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_SSTP0_An = {0x020}; 15762306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_SSTP1_An = {0x028}; 15862306a36Sopenharmony_ci/* Configuration and Control Area - CAIA 1 */ 15962306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_PSL_AMR_An = {0x030}; 16062306a36Sopenharmony_ci/* Segment Lookaside Buffer Management - CAIA 1 */ 16162306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_SLBIE_An = {0x040}; 16262306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_SLBIA_An = {0x048}; 16362306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_SLBI_Select_An = {0x050}; 16462306a36Sopenharmony_ci/* Interrupt Registers - CAIA 1&2 */ 16562306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_PSL_DSISR_An = {0x060}; 16662306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_PSL_DAR_An = {0x068}; 16762306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_PSL_DSR_An = {0x070}; 16862306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_PSL_TFC_An = {0x078}; 16962306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_PSL_PEHandle_An = {0x080}; 17062306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_PSL_ErrStat_An = {0x088}; 17162306a36Sopenharmony_ci/* AFU Registers - CAIA 1&2 */ 17262306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_AFU_Cntl_An = {0x090}; 17362306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_AFU_ERR_An = {0x098}; 17462306a36Sopenharmony_ci/* Work Element Descriptor - CAIA 1&2 */ 17562306a36Sopenharmony_cistatic const cxl_p2n_reg_t CXL_PSL_WED_An = {0x0A0}; 17662306a36Sopenharmony_ci/* 0x0C0:FFF Implementation Dependent Area */ 17762306a36Sopenharmony_ci 17862306a36Sopenharmony_ci#define CXL_PSL_SPAP_Addr 0x0ffffffffffff000ULL 17962306a36Sopenharmony_ci#define CXL_PSL_SPAP_Size 0x0000000000000ff0ULL 18062306a36Sopenharmony_ci#define CXL_PSL_SPAP_Size_Shift 4 18162306a36Sopenharmony_ci#define CXL_PSL_SPAP_V 0x0000000000000001ULL 18262306a36Sopenharmony_ci 18362306a36Sopenharmony_ci/****** CXL_PSL_Control ****************************************************/ 18462306a36Sopenharmony_ci#define CXL_PSL_Control_tb (0x1ull << (63-63)) 18562306a36Sopenharmony_ci#define CXL_PSL_Control_Fr (0x1ull << (63-31)) 18662306a36Sopenharmony_ci#define CXL_PSL_Control_Fs_MASK (0x3ull << (63-29)) 18762306a36Sopenharmony_ci#define CXL_PSL_Control_Fs_Complete (0x3ull << (63-29)) 18862306a36Sopenharmony_ci 18962306a36Sopenharmony_ci/****** CXL_PSL_DLCNTL *****************************************************/ 19062306a36Sopenharmony_ci#define CXL_PSL_DLCNTL_D (0x1ull << (63-28)) 19162306a36Sopenharmony_ci#define CXL_PSL_DLCNTL_C (0x1ull << (63-29)) 19262306a36Sopenharmony_ci#define CXL_PSL_DLCNTL_E (0x1ull << (63-30)) 19362306a36Sopenharmony_ci#define CXL_PSL_DLCNTL_S (0x1ull << (63-31)) 19462306a36Sopenharmony_ci#define CXL_PSL_DLCNTL_CE (CXL_PSL_DLCNTL_C | CXL_PSL_DLCNTL_E) 19562306a36Sopenharmony_ci#define CXL_PSL_DLCNTL_DCES (CXL_PSL_DLCNTL_D | CXL_PSL_DLCNTL_CE | CXL_PSL_DLCNTL_S) 19662306a36Sopenharmony_ci 19762306a36Sopenharmony_ci/****** CXL_PSL_SR_An ******************************************************/ 19862306a36Sopenharmony_ci#define CXL_PSL_SR_An_SF MSR_SF /* 64bit */ 19962306a36Sopenharmony_ci#define CXL_PSL_SR_An_TA (1ull << (63-1)) /* Tags active, GA1: 0 */ 20062306a36Sopenharmony_ci#define CXL_PSL_SR_An_HV MSR_HV /* Hypervisor, GA1: 0 */ 20162306a36Sopenharmony_ci#define CXL_PSL_SR_An_XLAT_hpt (0ull << (63-6))/* Hashed page table (HPT) mode */ 20262306a36Sopenharmony_ci#define CXL_PSL_SR_An_XLAT_roh (2ull << (63-6))/* Radix on HPT mode */ 20362306a36Sopenharmony_ci#define CXL_PSL_SR_An_XLAT_ror (3ull << (63-6))/* Radix on Radix mode */ 20462306a36Sopenharmony_ci#define CXL_PSL_SR_An_BOT (1ull << (63-10)) /* Use the in-memory segment table */ 20562306a36Sopenharmony_ci#define CXL_PSL_SR_An_PR MSR_PR /* Problem state, GA1: 1 */ 20662306a36Sopenharmony_ci#define CXL_PSL_SR_An_ISL (1ull << (63-53)) /* Ignore Segment Large Page */ 20762306a36Sopenharmony_ci#define CXL_PSL_SR_An_TC (1ull << (63-54)) /* Page Table secondary hash */ 20862306a36Sopenharmony_ci#define CXL_PSL_SR_An_US (1ull << (63-56)) /* User state, GA1: X */ 20962306a36Sopenharmony_ci#define CXL_PSL_SR_An_SC (1ull << (63-58)) /* Segment Table secondary hash */ 21062306a36Sopenharmony_ci#define CXL_PSL_SR_An_R MSR_DR /* Relocate, GA1: 1 */ 21162306a36Sopenharmony_ci#define CXL_PSL_SR_An_MP (1ull << (63-62)) /* Master Process */ 21262306a36Sopenharmony_ci#define CXL_PSL_SR_An_LE (1ull << (63-63)) /* Little Endian */ 21362306a36Sopenharmony_ci 21462306a36Sopenharmony_ci/****** CXL_PSL_ID_An ****************************************************/ 21562306a36Sopenharmony_ci#define CXL_PSL_ID_An_F (1ull << (63-31)) 21662306a36Sopenharmony_ci#define CXL_PSL_ID_An_L (1ull << (63-30)) 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ci/****** CXL_PSL_SERR_An ****************************************************/ 21962306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afuto (1ull << (63-0)) 22062306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afudis (1ull << (63-1)) 22162306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afuov (1ull << (63-2)) 22262306a36Sopenharmony_ci#define CXL_PSL_SERR_An_badsrc (1ull << (63-3)) 22362306a36Sopenharmony_ci#define CXL_PSL_SERR_An_badctx (1ull << (63-4)) 22462306a36Sopenharmony_ci#define CXL_PSL_SERR_An_llcmdis (1ull << (63-5)) 22562306a36Sopenharmony_ci#define CXL_PSL_SERR_An_llcmdto (1ull << (63-6)) 22662306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afupar (1ull << (63-7)) 22762306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afudup (1ull << (63-8)) 22862306a36Sopenharmony_ci#define CXL_PSL_SERR_An_IRQS ( \ 22962306a36Sopenharmony_ci CXL_PSL_SERR_An_afuto | CXL_PSL_SERR_An_afudis | CXL_PSL_SERR_An_afuov | \ 23062306a36Sopenharmony_ci CXL_PSL_SERR_An_badsrc | CXL_PSL_SERR_An_badctx | CXL_PSL_SERR_An_llcmdis | \ 23162306a36Sopenharmony_ci CXL_PSL_SERR_An_llcmdto | CXL_PSL_SERR_An_afupar | CXL_PSL_SERR_An_afudup) 23262306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afuto_mask (1ull << (63-32)) 23362306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afudis_mask (1ull << (63-33)) 23462306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afuov_mask (1ull << (63-34)) 23562306a36Sopenharmony_ci#define CXL_PSL_SERR_An_badsrc_mask (1ull << (63-35)) 23662306a36Sopenharmony_ci#define CXL_PSL_SERR_An_badctx_mask (1ull << (63-36)) 23762306a36Sopenharmony_ci#define CXL_PSL_SERR_An_llcmdis_mask (1ull << (63-37)) 23862306a36Sopenharmony_ci#define CXL_PSL_SERR_An_llcmdto_mask (1ull << (63-38)) 23962306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afupar_mask (1ull << (63-39)) 24062306a36Sopenharmony_ci#define CXL_PSL_SERR_An_afudup_mask (1ull << (63-40)) 24162306a36Sopenharmony_ci#define CXL_PSL_SERR_An_IRQ_MASKS ( \ 24262306a36Sopenharmony_ci CXL_PSL_SERR_An_afuto_mask | CXL_PSL_SERR_An_afudis_mask | CXL_PSL_SERR_An_afuov_mask | \ 24362306a36Sopenharmony_ci CXL_PSL_SERR_An_badsrc_mask | CXL_PSL_SERR_An_badctx_mask | CXL_PSL_SERR_An_llcmdis_mask | \ 24462306a36Sopenharmony_ci CXL_PSL_SERR_An_llcmdto_mask | CXL_PSL_SERR_An_afupar_mask | CXL_PSL_SERR_An_afudup_mask) 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci#define CXL_PSL_SERR_An_AE (1ull << (63-30)) 24762306a36Sopenharmony_ci 24862306a36Sopenharmony_ci/****** CXL_PSL_SCNTL_An ****************************************************/ 24962306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_CR (0x1ull << (63-15)) 25062306a36Sopenharmony_ci/* Programming Modes: */ 25162306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_PM_MASK (0xffffull << (63-31)) 25262306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_PM_Shared (0x0000ull << (63-31)) 25362306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_PM_OS (0x0001ull << (63-31)) 25462306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_PM_Process (0x0002ull << (63-31)) 25562306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_PM_AFU (0x0004ull << (63-31)) 25662306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_PM_AFU_PBT (0x0104ull << (63-31)) 25762306a36Sopenharmony_ci/* Purge Status (ro) */ 25862306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_Ps_MASK (0x3ull << (63-39)) 25962306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_Ps_Pending (0x1ull << (63-39)) 26062306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_Ps_Complete (0x3ull << (63-39)) 26162306a36Sopenharmony_ci/* Purge */ 26262306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_Pc (0x1ull << (63-48)) 26362306a36Sopenharmony_ci/* Suspend Status (ro) */ 26462306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_Ss_MASK (0x3ull << (63-55)) 26562306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_Ss_Pending (0x1ull << (63-55)) 26662306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_Ss_Complete (0x3ull << (63-55)) 26762306a36Sopenharmony_ci/* Suspend Control */ 26862306a36Sopenharmony_ci#define CXL_PSL_SCNTL_An_Sc (0x1ull << (63-63)) 26962306a36Sopenharmony_ci 27062306a36Sopenharmony_ci/* AFU Slice Enable Status (ro) */ 27162306a36Sopenharmony_ci#define CXL_AFU_Cntl_An_ES_MASK (0x7ull << (63-2)) 27262306a36Sopenharmony_ci#define CXL_AFU_Cntl_An_ES_Disabled (0x0ull << (63-2)) 27362306a36Sopenharmony_ci#define CXL_AFU_Cntl_An_ES_Enabled (0x4ull << (63-2)) 27462306a36Sopenharmony_ci/* AFU Slice Enable */ 27562306a36Sopenharmony_ci#define CXL_AFU_Cntl_An_E (0x1ull << (63-3)) 27662306a36Sopenharmony_ci/* AFU Slice Reset status (ro) */ 27762306a36Sopenharmony_ci#define CXL_AFU_Cntl_An_RS_MASK (0x3ull << (63-5)) 27862306a36Sopenharmony_ci#define CXL_AFU_Cntl_An_RS_Pending (0x1ull << (63-5)) 27962306a36Sopenharmony_ci#define CXL_AFU_Cntl_An_RS_Complete (0x2ull << (63-5)) 28062306a36Sopenharmony_ci/* AFU Slice Reset */ 28162306a36Sopenharmony_ci#define CXL_AFU_Cntl_An_RA (0x1ull << (63-7)) 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci/****** CXL_SSTP0/1_An ******************************************************/ 28462306a36Sopenharmony_ci/* These top bits are for the segment that CONTAINS the segment table */ 28562306a36Sopenharmony_ci#define CXL_SSTP0_An_B_SHIFT SLB_VSID_SSIZE_SHIFT 28662306a36Sopenharmony_ci#define CXL_SSTP0_An_KS (1ull << (63-2)) 28762306a36Sopenharmony_ci#define CXL_SSTP0_An_KP (1ull << (63-3)) 28862306a36Sopenharmony_ci#define CXL_SSTP0_An_N (1ull << (63-4)) 28962306a36Sopenharmony_ci#define CXL_SSTP0_An_L (1ull << (63-5)) 29062306a36Sopenharmony_ci#define CXL_SSTP0_An_C (1ull << (63-6)) 29162306a36Sopenharmony_ci#define CXL_SSTP0_An_TA (1ull << (63-7)) 29262306a36Sopenharmony_ci#define CXL_SSTP0_An_LP_SHIFT (63-9) /* 2 Bits */ 29362306a36Sopenharmony_ci/* And finally, the virtual address & size of the segment table: */ 29462306a36Sopenharmony_ci#define CXL_SSTP0_An_SegTableSize_SHIFT (63-31) /* 12 Bits */ 29562306a36Sopenharmony_ci#define CXL_SSTP0_An_SegTableSize_MASK \ 29662306a36Sopenharmony_ci (((1ull << 12) - 1) << CXL_SSTP0_An_SegTableSize_SHIFT) 29762306a36Sopenharmony_ci#define CXL_SSTP0_An_STVA_U_MASK ((1ull << (63-49))-1) 29862306a36Sopenharmony_ci#define CXL_SSTP1_An_STVA_L_MASK (~((1ull << (63-55))-1)) 29962306a36Sopenharmony_ci#define CXL_SSTP1_An_V (1ull << (63-63)) 30062306a36Sopenharmony_ci 30162306a36Sopenharmony_ci/****** CXL_PSL_SLBIE_[An] - CAIA 1 **************************************************/ 30262306a36Sopenharmony_ci/* write: */ 30362306a36Sopenharmony_ci#define CXL_SLBIE_C PPC_BIT(36) /* Class */ 30462306a36Sopenharmony_ci#define CXL_SLBIE_SS PPC_BITMASK(37, 38) /* Segment Size */ 30562306a36Sopenharmony_ci#define CXL_SLBIE_SS_SHIFT PPC_BITLSHIFT(38) 30662306a36Sopenharmony_ci#define CXL_SLBIE_TA PPC_BIT(38) /* Tags Active */ 30762306a36Sopenharmony_ci/* read: */ 30862306a36Sopenharmony_ci#define CXL_SLBIE_MAX PPC_BITMASK(24, 31) 30962306a36Sopenharmony_ci#define CXL_SLBIE_PENDING PPC_BITMASK(56, 63) 31062306a36Sopenharmony_ci 31162306a36Sopenharmony_ci/****** Common to all CXL_TLBIA/SLBIA_[An] - CAIA 1 **********************************/ 31262306a36Sopenharmony_ci#define CXL_TLB_SLB_P (1ull) /* Pending (read) */ 31362306a36Sopenharmony_ci 31462306a36Sopenharmony_ci/****** Common to all CXL_TLB/SLB_IA/IE_[An] registers - CAIA 1 **********************/ 31562306a36Sopenharmony_ci#define CXL_TLB_SLB_IQ_ALL (0ull) /* Inv qualifier */ 31662306a36Sopenharmony_ci#define CXL_TLB_SLB_IQ_LPID (1ull) /* Inv qualifier */ 31762306a36Sopenharmony_ci#define CXL_TLB_SLB_IQ_LPIDPID (3ull) /* Inv qualifier */ 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ci/****** CXL_PSL_AFUSEL ******************************************************/ 32062306a36Sopenharmony_ci#define CXL_PSL_AFUSEL_A (1ull << (63-55)) /* Adapter wide invalidates affect all AFUs */ 32162306a36Sopenharmony_ci 32262306a36Sopenharmony_ci/****** CXL_PSL_DSISR_An - CAIA 1 ****************************************************/ 32362306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_DS (1ull << (63-0)) /* Segment not found */ 32462306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_DM (1ull << (63-1)) /* PTE not found (See also: M) or protection fault */ 32562306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_ST (1ull << (63-2)) /* Segment Table PTE not found */ 32662306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_UR (1ull << (63-3)) /* AURP PTE not found */ 32762306a36Sopenharmony_ci#define CXL_PSL_DSISR_TRANS (CXL_PSL_DSISR_An_DS | CXL_PSL_DSISR_An_DM | CXL_PSL_DSISR_An_ST | CXL_PSL_DSISR_An_UR) 32862306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_PE (1ull << (63-4)) /* PSL Error (implementation specific) */ 32962306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_AE (1ull << (63-5)) /* AFU Error */ 33062306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_OC (1ull << (63-6)) /* OS Context Warning */ 33162306a36Sopenharmony_ci#define CXL_PSL_DSISR_PENDING (CXL_PSL_DSISR_TRANS | CXL_PSL_DSISR_An_PE | CXL_PSL_DSISR_An_AE | CXL_PSL_DSISR_An_OC) 33262306a36Sopenharmony_ci/* NOTE: Bits 32:63 are undefined if DSISR[DS] = 1 */ 33362306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_M DSISR_NOHPTE /* PTE not found */ 33462306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_P DSISR_PROTFAULT /* Storage protection violation */ 33562306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_A (1ull << (63-37)) /* AFU lock access to write through or cache inhibited storage */ 33662306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_S DSISR_ISSTORE /* Access was afu_wr or afu_zero */ 33762306a36Sopenharmony_ci#define CXL_PSL_DSISR_An_K DSISR_KEYFAULT /* Access not permitted by virtual page class key protection */ 33862306a36Sopenharmony_ci 33962306a36Sopenharmony_ci/****** CXL_PSL_DSISR_An - CAIA 2 ****************************************************/ 34062306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_TF (1ull << (63-3)) /* Translation fault */ 34162306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_PE (1ull << (63-4)) /* PSL Error (implementation specific) */ 34262306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_AE (1ull << (63-5)) /* AFU Error */ 34362306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_OC (1ull << (63-6)) /* OS Context Warning */ 34462306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_S (1ull << (63-38)) /* TF for a write operation */ 34562306a36Sopenharmony_ci#define CXL_PSL9_DSISR_PENDING (CXL_PSL9_DSISR_An_TF | CXL_PSL9_DSISR_An_PE | CXL_PSL9_DSISR_An_AE | CXL_PSL9_DSISR_An_OC) 34662306a36Sopenharmony_ci/* 34762306a36Sopenharmony_ci * NOTE: Bits 56:63 (Checkout Response Status) are valid when DSISR_An[TF] = 1 34862306a36Sopenharmony_ci * Status (0:7) Encoding 34962306a36Sopenharmony_ci */ 35062306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_CO_MASK 0x00000000000000ffULL 35162306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_SF 0x0000000000000080ULL /* Segment Fault 0b10000000 */ 35262306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_PF_SLR 0x0000000000000088ULL /* PTE not found (Single Level Radix) 0b10001000 */ 35362306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_PF_RGC 0x000000000000008CULL /* PTE not found (Radix Guest (child)) 0b10001100 */ 35462306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_PF_RGP 0x0000000000000090ULL /* PTE not found (Radix Guest (parent)) 0b10010000 */ 35562306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_PF_HRH 0x0000000000000094ULL /* PTE not found (HPT/Radix Host) 0b10010100 */ 35662306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_PF_STEG 0x000000000000009CULL /* PTE not found (STEG VA) 0b10011100 */ 35762306a36Sopenharmony_ci#define CXL_PSL9_DSISR_An_URTCH 0x00000000000000B4ULL /* Unsupported Radix Tree Configuration 0b10110100 */ 35862306a36Sopenharmony_ci 35962306a36Sopenharmony_ci/****** CXL_PSL_TFC_An ******************************************************/ 36062306a36Sopenharmony_ci#define CXL_PSL_TFC_An_A (1ull << (63-28)) /* Acknowledge non-translation fault */ 36162306a36Sopenharmony_ci#define CXL_PSL_TFC_An_C (1ull << (63-29)) /* Continue (abort transaction) */ 36262306a36Sopenharmony_ci#define CXL_PSL_TFC_An_AE (1ull << (63-30)) /* Restart PSL with address error */ 36362306a36Sopenharmony_ci#define CXL_PSL_TFC_An_R (1ull << (63-31)) /* Restart PSL transaction */ 36462306a36Sopenharmony_ci 36562306a36Sopenharmony_ci/****** CXL_PSL_DEBUG *****************************************************/ 36662306a36Sopenharmony_ci#define CXL_PSL_DEBUG_CDC (1ull << (63-27)) /* Coherent Data cache support */ 36762306a36Sopenharmony_ci 36862306a36Sopenharmony_ci/****** CXL_XSL9_IERAT_ERAT - CAIA 2 **********************************/ 36962306a36Sopenharmony_ci#define CXL_XSL9_IERAT_MLPID (1ull << (63-0)) /* Match LPID */ 37062306a36Sopenharmony_ci#define CXL_XSL9_IERAT_MPID (1ull << (63-1)) /* Match PID */ 37162306a36Sopenharmony_ci#define CXL_XSL9_IERAT_PRS (1ull << (63-4)) /* PRS bit for Radix invalidations */ 37262306a36Sopenharmony_ci#define CXL_XSL9_IERAT_INVR (1ull << (63-3)) /* Invalidate Radix */ 37362306a36Sopenharmony_ci#define CXL_XSL9_IERAT_IALL (1ull << (63-8)) /* Invalidate All */ 37462306a36Sopenharmony_ci#define CXL_XSL9_IERAT_IINPROG (1ull << (63-63)) /* Invalidate in progress */ 37562306a36Sopenharmony_ci 37662306a36Sopenharmony_ci/* cxl_process_element->software_status */ 37762306a36Sopenharmony_ci#define CXL_PE_SOFTWARE_STATE_V (1ul << (31 - 0)) /* Valid */ 37862306a36Sopenharmony_ci#define CXL_PE_SOFTWARE_STATE_C (1ul << (31 - 29)) /* Complete */ 37962306a36Sopenharmony_ci#define CXL_PE_SOFTWARE_STATE_S (1ul << (31 - 30)) /* Suspend */ 38062306a36Sopenharmony_ci#define CXL_PE_SOFTWARE_STATE_T (1ul << (31 - 31)) /* Terminate */ 38162306a36Sopenharmony_ci 38262306a36Sopenharmony_ci/****** CXL_PSL_RXCTL_An (Implementation Specific) ************************** 38362306a36Sopenharmony_ci * Controls AFU Hang Pulse, which sets the timeout for the AFU to respond to 38462306a36Sopenharmony_ci * the PSL for any response (except MMIO). Timeouts will occur between 1x to 2x 38562306a36Sopenharmony_ci * of the hang pulse frequency. 38662306a36Sopenharmony_ci */ 38762306a36Sopenharmony_ci#define CXL_PSL_RXCTL_AFUHP_4S 0x7000000000000000ULL 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ci/* SPA->sw_command_status */ 39062306a36Sopenharmony_ci#define CXL_SPA_SW_CMD_MASK 0xffff000000000000ULL 39162306a36Sopenharmony_ci#define CXL_SPA_SW_CMD_TERMINATE 0x0001000000000000ULL 39262306a36Sopenharmony_ci#define CXL_SPA_SW_CMD_REMOVE 0x0002000000000000ULL 39362306a36Sopenharmony_ci#define CXL_SPA_SW_CMD_SUSPEND 0x0003000000000000ULL 39462306a36Sopenharmony_ci#define CXL_SPA_SW_CMD_RESUME 0x0004000000000000ULL 39562306a36Sopenharmony_ci#define CXL_SPA_SW_CMD_ADD 0x0005000000000000ULL 39662306a36Sopenharmony_ci#define CXL_SPA_SW_CMD_UPDATE 0x0006000000000000ULL 39762306a36Sopenharmony_ci#define CXL_SPA_SW_STATE_MASK 0x0000ffff00000000ULL 39862306a36Sopenharmony_ci#define CXL_SPA_SW_STATE_TERMINATED 0x0000000100000000ULL 39962306a36Sopenharmony_ci#define CXL_SPA_SW_STATE_REMOVED 0x0000000200000000ULL 40062306a36Sopenharmony_ci#define CXL_SPA_SW_STATE_SUSPENDED 0x0000000300000000ULL 40162306a36Sopenharmony_ci#define CXL_SPA_SW_STATE_RESUMED 0x0000000400000000ULL 40262306a36Sopenharmony_ci#define CXL_SPA_SW_STATE_ADDED 0x0000000500000000ULL 40362306a36Sopenharmony_ci#define CXL_SPA_SW_STATE_UPDATED 0x0000000600000000ULL 40462306a36Sopenharmony_ci#define CXL_SPA_SW_PSL_ID_MASK 0x00000000ffff0000ULL 40562306a36Sopenharmony_ci#define CXL_SPA_SW_LINK_MASK 0x000000000000ffffULL 40662306a36Sopenharmony_ci 40762306a36Sopenharmony_ci#define CXL_MAX_SLICES 4 40862306a36Sopenharmony_ci#define MAX_AFU_MMIO_REGS 3 40962306a36Sopenharmony_ci 41062306a36Sopenharmony_ci#define CXL_MODE_TIME_SLICED 0x4 41162306a36Sopenharmony_ci#define CXL_SUPPORTED_MODES (CXL_MODE_DEDICATED | CXL_MODE_DIRECTED) 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_ci#define CXL_DEV_MINORS 13 /* 1 control + 4 AFUs * 3 (dedicated/master/shared) */ 41462306a36Sopenharmony_ci#define CXL_CARD_MINOR(adapter) (adapter->adapter_num * CXL_DEV_MINORS) 41562306a36Sopenharmony_ci#define CXL_DEVT_ADAPTER(dev) (MINOR(dev) / CXL_DEV_MINORS) 41662306a36Sopenharmony_ci 41762306a36Sopenharmony_ci#define CXL_PSL9_TRACEID_MAX 0xAU 41862306a36Sopenharmony_ci#define CXL_PSL9_TRACESTATE_FIN 0x3U 41962306a36Sopenharmony_ci 42062306a36Sopenharmony_cienum cxl_context_status { 42162306a36Sopenharmony_ci CLOSED, 42262306a36Sopenharmony_ci OPENED, 42362306a36Sopenharmony_ci STARTED 42462306a36Sopenharmony_ci}; 42562306a36Sopenharmony_ci 42662306a36Sopenharmony_cienum prefault_modes { 42762306a36Sopenharmony_ci CXL_PREFAULT_NONE, 42862306a36Sopenharmony_ci CXL_PREFAULT_WED, 42962306a36Sopenharmony_ci CXL_PREFAULT_ALL, 43062306a36Sopenharmony_ci}; 43162306a36Sopenharmony_ci 43262306a36Sopenharmony_cienum cxl_attrs { 43362306a36Sopenharmony_ci CXL_ADAPTER_ATTRS, 43462306a36Sopenharmony_ci CXL_AFU_MASTER_ATTRS, 43562306a36Sopenharmony_ci CXL_AFU_ATTRS, 43662306a36Sopenharmony_ci}; 43762306a36Sopenharmony_ci 43862306a36Sopenharmony_cistruct cxl_sste { 43962306a36Sopenharmony_ci __be64 esid_data; 44062306a36Sopenharmony_ci __be64 vsid_data; 44162306a36Sopenharmony_ci}; 44262306a36Sopenharmony_ci 44362306a36Sopenharmony_ci#define to_cxl_adapter(d) container_of(d, struct cxl, dev) 44462306a36Sopenharmony_ci#define to_cxl_afu(d) container_of(d, struct cxl_afu, dev) 44562306a36Sopenharmony_ci 44662306a36Sopenharmony_cistruct cxl_afu_native { 44762306a36Sopenharmony_ci void __iomem *p1n_mmio; 44862306a36Sopenharmony_ci void __iomem *afu_desc_mmio; 44962306a36Sopenharmony_ci irq_hw_number_t psl_hwirq; 45062306a36Sopenharmony_ci unsigned int psl_virq; 45162306a36Sopenharmony_ci struct mutex spa_mutex; 45262306a36Sopenharmony_ci /* 45362306a36Sopenharmony_ci * Only the first part of the SPA is used for the process element 45462306a36Sopenharmony_ci * linked list. The only other part that software needs to worry about 45562306a36Sopenharmony_ci * is sw_command_status, which we store a separate pointer to. 45662306a36Sopenharmony_ci * Everything else in the SPA is only used by hardware 45762306a36Sopenharmony_ci */ 45862306a36Sopenharmony_ci struct cxl_process_element *spa; 45962306a36Sopenharmony_ci __be64 *sw_command_status; 46062306a36Sopenharmony_ci unsigned int spa_size; 46162306a36Sopenharmony_ci int spa_order; 46262306a36Sopenharmony_ci int spa_max_procs; 46362306a36Sopenharmony_ci u64 pp_offset; 46462306a36Sopenharmony_ci}; 46562306a36Sopenharmony_ci 46662306a36Sopenharmony_cistruct cxl_afu_guest { 46762306a36Sopenharmony_ci struct cxl_afu *parent; 46862306a36Sopenharmony_ci u64 handle; 46962306a36Sopenharmony_ci phys_addr_t p2n_phys; 47062306a36Sopenharmony_ci u64 p2n_size; 47162306a36Sopenharmony_ci int max_ints; 47262306a36Sopenharmony_ci bool handle_err; 47362306a36Sopenharmony_ci struct delayed_work work_err; 47462306a36Sopenharmony_ci int previous_state; 47562306a36Sopenharmony_ci}; 47662306a36Sopenharmony_ci 47762306a36Sopenharmony_cistruct cxl_afu { 47862306a36Sopenharmony_ci struct cxl_afu_native *native; 47962306a36Sopenharmony_ci struct cxl_afu_guest *guest; 48062306a36Sopenharmony_ci irq_hw_number_t serr_hwirq; 48162306a36Sopenharmony_ci unsigned int serr_virq; 48262306a36Sopenharmony_ci char *psl_irq_name; 48362306a36Sopenharmony_ci char *err_irq_name; 48462306a36Sopenharmony_ci void __iomem *p2n_mmio; 48562306a36Sopenharmony_ci phys_addr_t psn_phys; 48662306a36Sopenharmony_ci u64 pp_size; 48762306a36Sopenharmony_ci 48862306a36Sopenharmony_ci struct cxl *adapter; 48962306a36Sopenharmony_ci struct device dev; 49062306a36Sopenharmony_ci struct cdev afu_cdev_s, afu_cdev_m, afu_cdev_d; 49162306a36Sopenharmony_ci struct device *chardev_s, *chardev_m, *chardev_d; 49262306a36Sopenharmony_ci struct idr contexts_idr; 49362306a36Sopenharmony_ci struct dentry *debugfs; 49462306a36Sopenharmony_ci struct mutex contexts_lock; 49562306a36Sopenharmony_ci spinlock_t afu_cntl_lock; 49662306a36Sopenharmony_ci 49762306a36Sopenharmony_ci /* -1: AFU deconfigured/locked, >= 0: number of readers */ 49862306a36Sopenharmony_ci atomic_t configured_state; 49962306a36Sopenharmony_ci 50062306a36Sopenharmony_ci /* AFU error buffer fields and bin attribute for sysfs */ 50162306a36Sopenharmony_ci u64 eb_len, eb_offset; 50262306a36Sopenharmony_ci struct bin_attribute attr_eb; 50362306a36Sopenharmony_ci 50462306a36Sopenharmony_ci /* pointer to the vphb */ 50562306a36Sopenharmony_ci struct pci_controller *phb; 50662306a36Sopenharmony_ci 50762306a36Sopenharmony_ci int pp_irqs; 50862306a36Sopenharmony_ci int irqs_max; 50962306a36Sopenharmony_ci int num_procs; 51062306a36Sopenharmony_ci int max_procs_virtualised; 51162306a36Sopenharmony_ci int slice; 51262306a36Sopenharmony_ci int modes_supported; 51362306a36Sopenharmony_ci int current_mode; 51462306a36Sopenharmony_ci int crs_num; 51562306a36Sopenharmony_ci u64 crs_len; 51662306a36Sopenharmony_ci u64 crs_offset; 51762306a36Sopenharmony_ci struct list_head crs; 51862306a36Sopenharmony_ci enum prefault_modes prefault_mode; 51962306a36Sopenharmony_ci bool psa; 52062306a36Sopenharmony_ci bool pp_psa; 52162306a36Sopenharmony_ci bool enabled; 52262306a36Sopenharmony_ci}; 52362306a36Sopenharmony_ci 52462306a36Sopenharmony_ci 52562306a36Sopenharmony_cistruct cxl_irq_name { 52662306a36Sopenharmony_ci struct list_head list; 52762306a36Sopenharmony_ci char *name; 52862306a36Sopenharmony_ci}; 52962306a36Sopenharmony_ci 53062306a36Sopenharmony_cistruct irq_avail { 53162306a36Sopenharmony_ci irq_hw_number_t offset; 53262306a36Sopenharmony_ci irq_hw_number_t range; 53362306a36Sopenharmony_ci unsigned long *bitmap; 53462306a36Sopenharmony_ci}; 53562306a36Sopenharmony_ci 53662306a36Sopenharmony_ci/* 53762306a36Sopenharmony_ci * This is a cxl context. If the PSL is in dedicated mode, there will be one 53862306a36Sopenharmony_ci * of these per AFU. If in AFU directed there can be lots of these. 53962306a36Sopenharmony_ci */ 54062306a36Sopenharmony_cistruct cxl_context { 54162306a36Sopenharmony_ci struct cxl_afu *afu; 54262306a36Sopenharmony_ci 54362306a36Sopenharmony_ci /* Problem state MMIO */ 54462306a36Sopenharmony_ci phys_addr_t psn_phys; 54562306a36Sopenharmony_ci u64 psn_size; 54662306a36Sopenharmony_ci 54762306a36Sopenharmony_ci /* Used to unmap any mmaps when force detaching */ 54862306a36Sopenharmony_ci struct address_space *mapping; 54962306a36Sopenharmony_ci struct mutex mapping_lock; 55062306a36Sopenharmony_ci struct page *ff_page; 55162306a36Sopenharmony_ci bool mmio_err_ff; 55262306a36Sopenharmony_ci bool kernelapi; 55362306a36Sopenharmony_ci 55462306a36Sopenharmony_ci spinlock_t sste_lock; /* Protects segment table entries */ 55562306a36Sopenharmony_ci struct cxl_sste *sstp; 55662306a36Sopenharmony_ci u64 sstp0, sstp1; 55762306a36Sopenharmony_ci unsigned int sst_size, sst_lru; 55862306a36Sopenharmony_ci 55962306a36Sopenharmony_ci wait_queue_head_t wq; 56062306a36Sopenharmony_ci /* use mm context associated with this pid for ds faults */ 56162306a36Sopenharmony_ci struct pid *pid; 56262306a36Sopenharmony_ci spinlock_t lock; /* Protects pending_irq_mask, pending_fault and fault_addr */ 56362306a36Sopenharmony_ci /* Only used in PR mode */ 56462306a36Sopenharmony_ci u64 process_token; 56562306a36Sopenharmony_ci 56662306a36Sopenharmony_ci /* driver private data */ 56762306a36Sopenharmony_ci void *priv; 56862306a36Sopenharmony_ci 56962306a36Sopenharmony_ci unsigned long *irq_bitmap; /* Accessed from IRQ context */ 57062306a36Sopenharmony_ci struct cxl_irq_ranges irqs; 57162306a36Sopenharmony_ci struct list_head irq_names; 57262306a36Sopenharmony_ci u64 fault_addr; 57362306a36Sopenharmony_ci u64 fault_dsisr; 57462306a36Sopenharmony_ci u64 afu_err; 57562306a36Sopenharmony_ci 57662306a36Sopenharmony_ci /* 57762306a36Sopenharmony_ci * This status and it's lock pretects start and detach context 57862306a36Sopenharmony_ci * from racing. It also prevents detach from racing with 57962306a36Sopenharmony_ci * itself 58062306a36Sopenharmony_ci */ 58162306a36Sopenharmony_ci enum cxl_context_status status; 58262306a36Sopenharmony_ci struct mutex status_mutex; 58362306a36Sopenharmony_ci 58462306a36Sopenharmony_ci 58562306a36Sopenharmony_ci /* XXX: Is it possible to need multiple work items at once? */ 58662306a36Sopenharmony_ci struct work_struct fault_work; 58762306a36Sopenharmony_ci u64 dsisr; 58862306a36Sopenharmony_ci u64 dar; 58962306a36Sopenharmony_ci 59062306a36Sopenharmony_ci struct cxl_process_element *elem; 59162306a36Sopenharmony_ci 59262306a36Sopenharmony_ci /* 59362306a36Sopenharmony_ci * pe is the process element handle, assigned by this driver when the 59462306a36Sopenharmony_ci * context is initialized. 59562306a36Sopenharmony_ci * 59662306a36Sopenharmony_ci * external_pe is the PE shown outside of cxl. 59762306a36Sopenharmony_ci * On bare-metal, pe=external_pe, because we decide what the handle is. 59862306a36Sopenharmony_ci * In a guest, we only find out about the pe used by pHyp when the 59962306a36Sopenharmony_ci * context is attached, and that's the value we want to report outside 60062306a36Sopenharmony_ci * of cxl. 60162306a36Sopenharmony_ci */ 60262306a36Sopenharmony_ci int pe; 60362306a36Sopenharmony_ci int external_pe; 60462306a36Sopenharmony_ci 60562306a36Sopenharmony_ci u32 irq_count; 60662306a36Sopenharmony_ci bool pe_inserted; 60762306a36Sopenharmony_ci bool master; 60862306a36Sopenharmony_ci bool kernel; 60962306a36Sopenharmony_ci bool pending_irq; 61062306a36Sopenharmony_ci bool pending_fault; 61162306a36Sopenharmony_ci bool pending_afu_err; 61262306a36Sopenharmony_ci 61362306a36Sopenharmony_ci /* Used by AFU drivers for driver specific event delivery */ 61462306a36Sopenharmony_ci struct cxl_afu_driver_ops *afu_driver_ops; 61562306a36Sopenharmony_ci atomic_t afu_driver_events; 61662306a36Sopenharmony_ci 61762306a36Sopenharmony_ci struct rcu_head rcu; 61862306a36Sopenharmony_ci 61962306a36Sopenharmony_ci struct mm_struct *mm; 62062306a36Sopenharmony_ci 62162306a36Sopenharmony_ci u16 tidr; 62262306a36Sopenharmony_ci bool assign_tidr; 62362306a36Sopenharmony_ci}; 62462306a36Sopenharmony_ci 62562306a36Sopenharmony_cistruct cxl_irq_info; 62662306a36Sopenharmony_ci 62762306a36Sopenharmony_cistruct cxl_service_layer_ops { 62862306a36Sopenharmony_ci int (*adapter_regs_init)(struct cxl *adapter, struct pci_dev *dev); 62962306a36Sopenharmony_ci int (*invalidate_all)(struct cxl *adapter); 63062306a36Sopenharmony_ci int (*afu_regs_init)(struct cxl_afu *afu); 63162306a36Sopenharmony_ci int (*sanitise_afu_regs)(struct cxl_afu *afu); 63262306a36Sopenharmony_ci int (*register_serr_irq)(struct cxl_afu *afu); 63362306a36Sopenharmony_ci void (*release_serr_irq)(struct cxl_afu *afu); 63462306a36Sopenharmony_ci irqreturn_t (*handle_interrupt)(int irq, struct cxl_context *ctx, struct cxl_irq_info *irq_info); 63562306a36Sopenharmony_ci irqreturn_t (*fail_irq)(struct cxl_afu *afu, struct cxl_irq_info *irq_info); 63662306a36Sopenharmony_ci int (*activate_dedicated_process)(struct cxl_afu *afu); 63762306a36Sopenharmony_ci int (*attach_afu_directed)(struct cxl_context *ctx, u64 wed, u64 amr); 63862306a36Sopenharmony_ci int (*attach_dedicated_process)(struct cxl_context *ctx, u64 wed, u64 amr); 63962306a36Sopenharmony_ci void (*update_dedicated_ivtes)(struct cxl_context *ctx); 64062306a36Sopenharmony_ci void (*debugfs_add_adapter_regs)(struct cxl *adapter, struct dentry *dir); 64162306a36Sopenharmony_ci void (*debugfs_add_afu_regs)(struct cxl_afu *afu, struct dentry *dir); 64262306a36Sopenharmony_ci void (*psl_irq_dump_registers)(struct cxl_context *ctx); 64362306a36Sopenharmony_ci void (*err_irq_dump_registers)(struct cxl *adapter); 64462306a36Sopenharmony_ci void (*debugfs_stop_trace)(struct cxl *adapter); 64562306a36Sopenharmony_ci void (*write_timebase_ctrl)(struct cxl *adapter); 64662306a36Sopenharmony_ci u64 (*timebase_read)(struct cxl *adapter); 64762306a36Sopenharmony_ci int capi_mode; 64862306a36Sopenharmony_ci bool needs_reset_before_disable; 64962306a36Sopenharmony_ci}; 65062306a36Sopenharmony_ci 65162306a36Sopenharmony_cistruct cxl_native { 65262306a36Sopenharmony_ci u64 afu_desc_off; 65362306a36Sopenharmony_ci u64 afu_desc_size; 65462306a36Sopenharmony_ci void __iomem *p1_mmio; 65562306a36Sopenharmony_ci void __iomem *p2_mmio; 65662306a36Sopenharmony_ci irq_hw_number_t err_hwirq; 65762306a36Sopenharmony_ci unsigned int err_virq; 65862306a36Sopenharmony_ci u64 ps_off; 65962306a36Sopenharmony_ci bool no_data_cache; /* set if no data cache on the card */ 66062306a36Sopenharmony_ci const struct cxl_service_layer_ops *sl_ops; 66162306a36Sopenharmony_ci}; 66262306a36Sopenharmony_ci 66362306a36Sopenharmony_cistruct cxl_guest { 66462306a36Sopenharmony_ci struct platform_device *pdev; 66562306a36Sopenharmony_ci int irq_nranges; 66662306a36Sopenharmony_ci struct cdev cdev; 66762306a36Sopenharmony_ci irq_hw_number_t irq_base_offset; 66862306a36Sopenharmony_ci struct irq_avail *irq_avail; 66962306a36Sopenharmony_ci spinlock_t irq_alloc_lock; 67062306a36Sopenharmony_ci u64 handle; 67162306a36Sopenharmony_ci char *status; 67262306a36Sopenharmony_ci u16 vendor; 67362306a36Sopenharmony_ci u16 device; 67462306a36Sopenharmony_ci u16 subsystem_vendor; 67562306a36Sopenharmony_ci u16 subsystem; 67662306a36Sopenharmony_ci}; 67762306a36Sopenharmony_ci 67862306a36Sopenharmony_cistruct cxl { 67962306a36Sopenharmony_ci struct cxl_native *native; 68062306a36Sopenharmony_ci struct cxl_guest *guest; 68162306a36Sopenharmony_ci spinlock_t afu_list_lock; 68262306a36Sopenharmony_ci struct cxl_afu *afu[CXL_MAX_SLICES]; 68362306a36Sopenharmony_ci struct device dev; 68462306a36Sopenharmony_ci struct dentry *trace; 68562306a36Sopenharmony_ci struct dentry *psl_err_chk; 68662306a36Sopenharmony_ci struct dentry *debugfs; 68762306a36Sopenharmony_ci char *irq_name; 68862306a36Sopenharmony_ci struct bin_attribute cxl_attr; 68962306a36Sopenharmony_ci int adapter_num; 69062306a36Sopenharmony_ci int user_irqs; 69162306a36Sopenharmony_ci u64 ps_size; 69262306a36Sopenharmony_ci u16 psl_rev; 69362306a36Sopenharmony_ci u16 base_image; 69462306a36Sopenharmony_ci u8 vsec_status; 69562306a36Sopenharmony_ci u8 caia_major; 69662306a36Sopenharmony_ci u8 caia_minor; 69762306a36Sopenharmony_ci u8 slices; 69862306a36Sopenharmony_ci bool user_image_loaded; 69962306a36Sopenharmony_ci bool perst_loads_image; 70062306a36Sopenharmony_ci bool perst_select_user; 70162306a36Sopenharmony_ci bool perst_same_image; 70262306a36Sopenharmony_ci bool psl_timebase_synced; 70362306a36Sopenharmony_ci bool tunneled_ops_supported; 70462306a36Sopenharmony_ci 70562306a36Sopenharmony_ci /* 70662306a36Sopenharmony_ci * number of contexts mapped on to this card. Possible values are: 70762306a36Sopenharmony_ci * >0: Number of contexts mapped and new one can be mapped. 70862306a36Sopenharmony_ci * 0: No active contexts and new ones can be mapped. 70962306a36Sopenharmony_ci * -1: No contexts mapped and new ones cannot be mapped. 71062306a36Sopenharmony_ci */ 71162306a36Sopenharmony_ci atomic_t contexts_num; 71262306a36Sopenharmony_ci}; 71362306a36Sopenharmony_ci 71462306a36Sopenharmony_ciint cxl_pci_alloc_one_irq(struct cxl *adapter); 71562306a36Sopenharmony_civoid cxl_pci_release_one_irq(struct cxl *adapter, int hwirq); 71662306a36Sopenharmony_ciint cxl_pci_alloc_irq_ranges(struct cxl_irq_ranges *irqs, struct cxl *adapter, unsigned int num); 71762306a36Sopenharmony_civoid cxl_pci_release_irq_ranges(struct cxl_irq_ranges *irqs, struct cxl *adapter); 71862306a36Sopenharmony_ciint cxl_pci_setup_irq(struct cxl *adapter, unsigned int hwirq, unsigned int virq); 71962306a36Sopenharmony_ciint cxl_update_image_control(struct cxl *adapter); 72062306a36Sopenharmony_ciint cxl_pci_reset(struct cxl *adapter); 72162306a36Sopenharmony_civoid cxl_pci_release_afu(struct device *dev); 72262306a36Sopenharmony_cissize_t cxl_pci_read_adapter_vpd(struct cxl *adapter, void *buf, size_t len); 72362306a36Sopenharmony_ci 72462306a36Sopenharmony_ci/* common == phyp + powernv - CAIA 1&2 */ 72562306a36Sopenharmony_cistruct cxl_process_element_common { 72662306a36Sopenharmony_ci __be32 tid; 72762306a36Sopenharmony_ci __be32 pid; 72862306a36Sopenharmony_ci __be64 csrp; 72962306a36Sopenharmony_ci union { 73062306a36Sopenharmony_ci struct { 73162306a36Sopenharmony_ci __be64 aurp0; 73262306a36Sopenharmony_ci __be64 aurp1; 73362306a36Sopenharmony_ci __be64 sstp0; 73462306a36Sopenharmony_ci __be64 sstp1; 73562306a36Sopenharmony_ci } psl8; /* CAIA 1 */ 73662306a36Sopenharmony_ci struct { 73762306a36Sopenharmony_ci u8 reserved2[8]; 73862306a36Sopenharmony_ci u8 reserved3[8]; 73962306a36Sopenharmony_ci u8 reserved4[8]; 74062306a36Sopenharmony_ci u8 reserved5[8]; 74162306a36Sopenharmony_ci } psl9; /* CAIA 2 */ 74262306a36Sopenharmony_ci } u; 74362306a36Sopenharmony_ci __be64 amr; 74462306a36Sopenharmony_ci u8 reserved6[4]; 74562306a36Sopenharmony_ci __be64 wed; 74662306a36Sopenharmony_ci} __packed; 74762306a36Sopenharmony_ci 74862306a36Sopenharmony_ci/* just powernv - CAIA 1&2 */ 74962306a36Sopenharmony_cistruct cxl_process_element { 75062306a36Sopenharmony_ci __be64 sr; 75162306a36Sopenharmony_ci __be64 SPOffset; 75262306a36Sopenharmony_ci union { 75362306a36Sopenharmony_ci __be64 sdr; /* CAIA 1 */ 75462306a36Sopenharmony_ci u8 reserved1[8]; /* CAIA 2 */ 75562306a36Sopenharmony_ci } u; 75662306a36Sopenharmony_ci __be64 haurp; 75762306a36Sopenharmony_ci __be32 ctxtime; 75862306a36Sopenharmony_ci __be16 ivte_offsets[4]; 75962306a36Sopenharmony_ci __be16 ivte_ranges[4]; 76062306a36Sopenharmony_ci __be32 lpid; 76162306a36Sopenharmony_ci struct cxl_process_element_common common; 76262306a36Sopenharmony_ci __be32 software_state; 76362306a36Sopenharmony_ci} __packed; 76462306a36Sopenharmony_ci 76562306a36Sopenharmony_cistatic inline bool cxl_adapter_link_ok(struct cxl *cxl, struct cxl_afu *afu) 76662306a36Sopenharmony_ci{ 76762306a36Sopenharmony_ci struct pci_dev *pdev; 76862306a36Sopenharmony_ci 76962306a36Sopenharmony_ci if (cpu_has_feature(CPU_FTR_HVMODE)) { 77062306a36Sopenharmony_ci pdev = to_pci_dev(cxl->dev.parent); 77162306a36Sopenharmony_ci return !pci_channel_offline(pdev); 77262306a36Sopenharmony_ci } 77362306a36Sopenharmony_ci return true; 77462306a36Sopenharmony_ci} 77562306a36Sopenharmony_ci 77662306a36Sopenharmony_cistatic inline void __iomem *_cxl_p1_addr(struct cxl *cxl, cxl_p1_reg_t reg) 77762306a36Sopenharmony_ci{ 77862306a36Sopenharmony_ci WARN_ON(!cpu_has_feature(CPU_FTR_HVMODE)); 77962306a36Sopenharmony_ci return cxl->native->p1_mmio + cxl_reg_off(reg); 78062306a36Sopenharmony_ci} 78162306a36Sopenharmony_ci 78262306a36Sopenharmony_cistatic inline void cxl_p1_write(struct cxl *cxl, cxl_p1_reg_t reg, u64 val) 78362306a36Sopenharmony_ci{ 78462306a36Sopenharmony_ci if (likely(cxl_adapter_link_ok(cxl, NULL))) 78562306a36Sopenharmony_ci out_be64(_cxl_p1_addr(cxl, reg), val); 78662306a36Sopenharmony_ci} 78762306a36Sopenharmony_ci 78862306a36Sopenharmony_cistatic inline u64 cxl_p1_read(struct cxl *cxl, cxl_p1_reg_t reg) 78962306a36Sopenharmony_ci{ 79062306a36Sopenharmony_ci if (likely(cxl_adapter_link_ok(cxl, NULL))) 79162306a36Sopenharmony_ci return in_be64(_cxl_p1_addr(cxl, reg)); 79262306a36Sopenharmony_ci else 79362306a36Sopenharmony_ci return ~0ULL; 79462306a36Sopenharmony_ci} 79562306a36Sopenharmony_ci 79662306a36Sopenharmony_cistatic inline void __iomem *_cxl_p1n_addr(struct cxl_afu *afu, cxl_p1n_reg_t reg) 79762306a36Sopenharmony_ci{ 79862306a36Sopenharmony_ci WARN_ON(!cpu_has_feature(CPU_FTR_HVMODE)); 79962306a36Sopenharmony_ci return afu->native->p1n_mmio + cxl_reg_off(reg); 80062306a36Sopenharmony_ci} 80162306a36Sopenharmony_ci 80262306a36Sopenharmony_cistatic inline void cxl_p1n_write(struct cxl_afu *afu, cxl_p1n_reg_t reg, u64 val) 80362306a36Sopenharmony_ci{ 80462306a36Sopenharmony_ci if (likely(cxl_adapter_link_ok(afu->adapter, afu))) 80562306a36Sopenharmony_ci out_be64(_cxl_p1n_addr(afu, reg), val); 80662306a36Sopenharmony_ci} 80762306a36Sopenharmony_ci 80862306a36Sopenharmony_cistatic inline u64 cxl_p1n_read(struct cxl_afu *afu, cxl_p1n_reg_t reg) 80962306a36Sopenharmony_ci{ 81062306a36Sopenharmony_ci if (likely(cxl_adapter_link_ok(afu->adapter, afu))) 81162306a36Sopenharmony_ci return in_be64(_cxl_p1n_addr(afu, reg)); 81262306a36Sopenharmony_ci else 81362306a36Sopenharmony_ci return ~0ULL; 81462306a36Sopenharmony_ci} 81562306a36Sopenharmony_ci 81662306a36Sopenharmony_cistatic inline void __iomem *_cxl_p2n_addr(struct cxl_afu *afu, cxl_p2n_reg_t reg) 81762306a36Sopenharmony_ci{ 81862306a36Sopenharmony_ci return afu->p2n_mmio + cxl_reg_off(reg); 81962306a36Sopenharmony_ci} 82062306a36Sopenharmony_ci 82162306a36Sopenharmony_cistatic inline void cxl_p2n_write(struct cxl_afu *afu, cxl_p2n_reg_t reg, u64 val) 82262306a36Sopenharmony_ci{ 82362306a36Sopenharmony_ci if (likely(cxl_adapter_link_ok(afu->adapter, afu))) 82462306a36Sopenharmony_ci out_be64(_cxl_p2n_addr(afu, reg), val); 82562306a36Sopenharmony_ci} 82662306a36Sopenharmony_ci 82762306a36Sopenharmony_cistatic inline u64 cxl_p2n_read(struct cxl_afu *afu, cxl_p2n_reg_t reg) 82862306a36Sopenharmony_ci{ 82962306a36Sopenharmony_ci if (likely(cxl_adapter_link_ok(afu->adapter, afu))) 83062306a36Sopenharmony_ci return in_be64(_cxl_p2n_addr(afu, reg)); 83162306a36Sopenharmony_ci else 83262306a36Sopenharmony_ci return ~0ULL; 83362306a36Sopenharmony_ci} 83462306a36Sopenharmony_ci 83562306a36Sopenharmony_cistatic inline bool cxl_is_power8(void) 83662306a36Sopenharmony_ci{ 83762306a36Sopenharmony_ci if ((pvr_version_is(PVR_POWER8E)) || 83862306a36Sopenharmony_ci (pvr_version_is(PVR_POWER8NVL)) || 83962306a36Sopenharmony_ci (pvr_version_is(PVR_POWER8))) 84062306a36Sopenharmony_ci return true; 84162306a36Sopenharmony_ci return false; 84262306a36Sopenharmony_ci} 84362306a36Sopenharmony_ci 84462306a36Sopenharmony_cistatic inline bool cxl_is_power9(void) 84562306a36Sopenharmony_ci{ 84662306a36Sopenharmony_ci if (pvr_version_is(PVR_POWER9)) 84762306a36Sopenharmony_ci return true; 84862306a36Sopenharmony_ci return false; 84962306a36Sopenharmony_ci} 85062306a36Sopenharmony_ci 85162306a36Sopenharmony_cissize_t cxl_pci_afu_read_err_buffer(struct cxl_afu *afu, char *buf, 85262306a36Sopenharmony_ci loff_t off, size_t count); 85362306a36Sopenharmony_ci 85462306a36Sopenharmony_ci 85562306a36Sopenharmony_cistruct cxl_calls { 85662306a36Sopenharmony_ci void (*cxl_slbia)(struct mm_struct *mm); 85762306a36Sopenharmony_ci struct module *owner; 85862306a36Sopenharmony_ci}; 85962306a36Sopenharmony_ciint register_cxl_calls(struct cxl_calls *calls); 86062306a36Sopenharmony_civoid unregister_cxl_calls(struct cxl_calls *calls); 86162306a36Sopenharmony_ciint cxl_update_properties(struct device_node *dn, struct property *new_prop); 86262306a36Sopenharmony_ci 86362306a36Sopenharmony_civoid cxl_remove_adapter_nr(struct cxl *adapter); 86462306a36Sopenharmony_ci 86562306a36Sopenharmony_civoid cxl_release_spa(struct cxl_afu *afu); 86662306a36Sopenharmony_ci 86762306a36Sopenharmony_cidev_t cxl_get_dev(void); 86862306a36Sopenharmony_ciint cxl_file_init(void); 86962306a36Sopenharmony_civoid cxl_file_exit(void); 87062306a36Sopenharmony_ciint cxl_register_adapter(struct cxl *adapter); 87162306a36Sopenharmony_ciint cxl_register_afu(struct cxl_afu *afu); 87262306a36Sopenharmony_ciint cxl_chardev_d_afu_add(struct cxl_afu *afu); 87362306a36Sopenharmony_ciint cxl_chardev_m_afu_add(struct cxl_afu *afu); 87462306a36Sopenharmony_ciint cxl_chardev_s_afu_add(struct cxl_afu *afu); 87562306a36Sopenharmony_civoid cxl_chardev_afu_remove(struct cxl_afu *afu); 87662306a36Sopenharmony_ci 87762306a36Sopenharmony_civoid cxl_context_detach_all(struct cxl_afu *afu); 87862306a36Sopenharmony_civoid cxl_context_free(struct cxl_context *ctx); 87962306a36Sopenharmony_civoid cxl_context_detach(struct cxl_context *ctx); 88062306a36Sopenharmony_ci 88162306a36Sopenharmony_ciint cxl_sysfs_adapter_add(struct cxl *adapter); 88262306a36Sopenharmony_civoid cxl_sysfs_adapter_remove(struct cxl *adapter); 88362306a36Sopenharmony_ciint cxl_sysfs_afu_add(struct cxl_afu *afu); 88462306a36Sopenharmony_civoid cxl_sysfs_afu_remove(struct cxl_afu *afu); 88562306a36Sopenharmony_ciint cxl_sysfs_afu_m_add(struct cxl_afu *afu); 88662306a36Sopenharmony_civoid cxl_sysfs_afu_m_remove(struct cxl_afu *afu); 88762306a36Sopenharmony_ci 88862306a36Sopenharmony_cistruct cxl *cxl_alloc_adapter(void); 88962306a36Sopenharmony_cistruct cxl_afu *cxl_alloc_afu(struct cxl *adapter, int slice); 89062306a36Sopenharmony_ciint cxl_afu_select_best_mode(struct cxl_afu *afu); 89162306a36Sopenharmony_ci 89262306a36Sopenharmony_ciint cxl_native_register_psl_irq(struct cxl_afu *afu); 89362306a36Sopenharmony_civoid cxl_native_release_psl_irq(struct cxl_afu *afu); 89462306a36Sopenharmony_ciint cxl_native_register_psl_err_irq(struct cxl *adapter); 89562306a36Sopenharmony_civoid cxl_native_release_psl_err_irq(struct cxl *adapter); 89662306a36Sopenharmony_ciint cxl_native_register_serr_irq(struct cxl_afu *afu); 89762306a36Sopenharmony_civoid cxl_native_release_serr_irq(struct cxl_afu *afu); 89862306a36Sopenharmony_ciint afu_register_irqs(struct cxl_context *ctx, u32 count); 89962306a36Sopenharmony_civoid afu_release_irqs(struct cxl_context *ctx, void *cookie); 90062306a36Sopenharmony_civoid afu_irq_name_free(struct cxl_context *ctx); 90162306a36Sopenharmony_ci 90262306a36Sopenharmony_ciint cxl_attach_afu_directed_psl9(struct cxl_context *ctx, u64 wed, u64 amr); 90362306a36Sopenharmony_ciint cxl_attach_afu_directed_psl8(struct cxl_context *ctx, u64 wed, u64 amr); 90462306a36Sopenharmony_ciint cxl_activate_dedicated_process_psl9(struct cxl_afu *afu); 90562306a36Sopenharmony_ciint cxl_activate_dedicated_process_psl8(struct cxl_afu *afu); 90662306a36Sopenharmony_ciint cxl_attach_dedicated_process_psl9(struct cxl_context *ctx, u64 wed, u64 amr); 90762306a36Sopenharmony_ciint cxl_attach_dedicated_process_psl8(struct cxl_context *ctx, u64 wed, u64 amr); 90862306a36Sopenharmony_civoid cxl_update_dedicated_ivtes_psl9(struct cxl_context *ctx); 90962306a36Sopenharmony_civoid cxl_update_dedicated_ivtes_psl8(struct cxl_context *ctx); 91062306a36Sopenharmony_ci 91162306a36Sopenharmony_ci#ifdef CONFIG_DEBUG_FS 91262306a36Sopenharmony_ci 91362306a36Sopenharmony_civoid cxl_debugfs_init(void); 91462306a36Sopenharmony_civoid cxl_debugfs_exit(void); 91562306a36Sopenharmony_civoid cxl_debugfs_adapter_add(struct cxl *adapter); 91662306a36Sopenharmony_civoid cxl_debugfs_adapter_remove(struct cxl *adapter); 91762306a36Sopenharmony_civoid cxl_debugfs_afu_add(struct cxl_afu *afu); 91862306a36Sopenharmony_civoid cxl_debugfs_afu_remove(struct cxl_afu *afu); 91962306a36Sopenharmony_civoid cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir); 92062306a36Sopenharmony_civoid cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir); 92162306a36Sopenharmony_civoid cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir); 92262306a36Sopenharmony_civoid cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir); 92362306a36Sopenharmony_ci 92462306a36Sopenharmony_ci#else /* CONFIG_DEBUG_FS */ 92562306a36Sopenharmony_ci 92662306a36Sopenharmony_cistatic inline void __init cxl_debugfs_init(void) 92762306a36Sopenharmony_ci{ 92862306a36Sopenharmony_ci} 92962306a36Sopenharmony_ci 93062306a36Sopenharmony_cistatic inline void cxl_debugfs_exit(void) 93162306a36Sopenharmony_ci{ 93262306a36Sopenharmony_ci} 93362306a36Sopenharmony_ci 93462306a36Sopenharmony_cistatic inline void cxl_debugfs_adapter_add(struct cxl *adapter) 93562306a36Sopenharmony_ci{ 93662306a36Sopenharmony_ci} 93762306a36Sopenharmony_ci 93862306a36Sopenharmony_cistatic inline void cxl_debugfs_adapter_remove(struct cxl *adapter) 93962306a36Sopenharmony_ci{ 94062306a36Sopenharmony_ci} 94162306a36Sopenharmony_ci 94262306a36Sopenharmony_cistatic inline void cxl_debugfs_afu_add(struct cxl_afu *afu) 94362306a36Sopenharmony_ci{ 94462306a36Sopenharmony_ci} 94562306a36Sopenharmony_ci 94662306a36Sopenharmony_cistatic inline void cxl_debugfs_afu_remove(struct cxl_afu *afu) 94762306a36Sopenharmony_ci{ 94862306a36Sopenharmony_ci} 94962306a36Sopenharmony_ci 95062306a36Sopenharmony_cistatic inline void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, 95162306a36Sopenharmony_ci struct dentry *dir) 95262306a36Sopenharmony_ci{ 95362306a36Sopenharmony_ci} 95462306a36Sopenharmony_ci 95562306a36Sopenharmony_cistatic inline void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, 95662306a36Sopenharmony_ci struct dentry *dir) 95762306a36Sopenharmony_ci{ 95862306a36Sopenharmony_ci} 95962306a36Sopenharmony_ci 96062306a36Sopenharmony_cistatic inline void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir) 96162306a36Sopenharmony_ci{ 96262306a36Sopenharmony_ci} 96362306a36Sopenharmony_ci 96462306a36Sopenharmony_cistatic inline void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir) 96562306a36Sopenharmony_ci{ 96662306a36Sopenharmony_ci} 96762306a36Sopenharmony_ci 96862306a36Sopenharmony_ci#endif /* CONFIG_DEBUG_FS */ 96962306a36Sopenharmony_ci 97062306a36Sopenharmony_civoid cxl_handle_fault(struct work_struct *work); 97162306a36Sopenharmony_civoid cxl_prefault(struct cxl_context *ctx, u64 wed); 97262306a36Sopenharmony_ciint cxl_handle_mm_fault(struct mm_struct *mm, u64 dsisr, u64 dar); 97362306a36Sopenharmony_ci 97462306a36Sopenharmony_cistruct cxl *get_cxl_adapter(int num); 97562306a36Sopenharmony_ciint cxl_alloc_sst(struct cxl_context *ctx); 97662306a36Sopenharmony_civoid cxl_dump_debug_buffer(void *addr, size_t size); 97762306a36Sopenharmony_ci 97862306a36Sopenharmony_civoid init_cxl_native(void); 97962306a36Sopenharmony_ci 98062306a36Sopenharmony_cistruct cxl_context *cxl_context_alloc(void); 98162306a36Sopenharmony_ciint cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master); 98262306a36Sopenharmony_civoid cxl_context_set_mapping(struct cxl_context *ctx, 98362306a36Sopenharmony_ci struct address_space *mapping); 98462306a36Sopenharmony_civoid cxl_context_free(struct cxl_context *ctx); 98562306a36Sopenharmony_ciint cxl_context_iomap(struct cxl_context *ctx, struct vm_area_struct *vma); 98662306a36Sopenharmony_ciunsigned int cxl_map_irq(struct cxl *adapter, irq_hw_number_t hwirq, 98762306a36Sopenharmony_ci irq_handler_t handler, void *cookie, const char *name); 98862306a36Sopenharmony_civoid cxl_unmap_irq(unsigned int virq, void *cookie); 98962306a36Sopenharmony_ciint __detach_context(struct cxl_context *ctx); 99062306a36Sopenharmony_ci 99162306a36Sopenharmony_ci/* 99262306a36Sopenharmony_ci * This must match the layout of the H_COLLECT_CA_INT_INFO retbuf defined 99362306a36Sopenharmony_ci * in PAPR. 99462306a36Sopenharmony_ci * Field pid_tid is now 'reserved' because it's no more used on bare-metal. 99562306a36Sopenharmony_ci * On a guest environment, PSL_PID_An is located on the upper 32 bits and 99662306a36Sopenharmony_ci * PSL_TID_An register in the lower 32 bits. 99762306a36Sopenharmony_ci */ 99862306a36Sopenharmony_cistruct cxl_irq_info { 99962306a36Sopenharmony_ci u64 dsisr; 100062306a36Sopenharmony_ci u64 dar; 100162306a36Sopenharmony_ci u64 dsr; 100262306a36Sopenharmony_ci u64 reserved; 100362306a36Sopenharmony_ci u64 afu_err; 100462306a36Sopenharmony_ci u64 errstat; 100562306a36Sopenharmony_ci u64 proc_handle; 100662306a36Sopenharmony_ci u64 padding[2]; /* to match the expected retbuf size for plpar_hcall9 */ 100762306a36Sopenharmony_ci}; 100862306a36Sopenharmony_ci 100962306a36Sopenharmony_civoid cxl_assign_psn_space(struct cxl_context *ctx); 101062306a36Sopenharmony_ciint cxl_invalidate_all_psl9(struct cxl *adapter); 101162306a36Sopenharmony_ciint cxl_invalidate_all_psl8(struct cxl *adapter); 101262306a36Sopenharmony_ciirqreturn_t cxl_irq_psl9(int irq, struct cxl_context *ctx, struct cxl_irq_info *irq_info); 101362306a36Sopenharmony_ciirqreturn_t cxl_irq_psl8(int irq, struct cxl_context *ctx, struct cxl_irq_info *irq_info); 101462306a36Sopenharmony_ciirqreturn_t cxl_fail_irq_psl(struct cxl_afu *afu, struct cxl_irq_info *irq_info); 101562306a36Sopenharmony_ciint cxl_register_one_irq(struct cxl *adapter, irq_handler_t handler, 101662306a36Sopenharmony_ci void *cookie, irq_hw_number_t *dest_hwirq, 101762306a36Sopenharmony_ci unsigned int *dest_virq, const char *name); 101862306a36Sopenharmony_ci 101962306a36Sopenharmony_ciint cxl_check_error(struct cxl_afu *afu); 102062306a36Sopenharmony_ciint cxl_afu_slbia(struct cxl_afu *afu); 102162306a36Sopenharmony_ciint cxl_data_cache_flush(struct cxl *adapter); 102262306a36Sopenharmony_ciint cxl_afu_disable(struct cxl_afu *afu); 102362306a36Sopenharmony_ciint cxl_psl_purge(struct cxl_afu *afu); 102462306a36Sopenharmony_ciint cxl_calc_capp_routing(struct pci_dev *dev, u64 *chipid, 102562306a36Sopenharmony_ci u32 *phb_index, u64 *capp_unit_id); 102662306a36Sopenharmony_ciint cxl_slot_is_switched(struct pci_dev *dev); 102762306a36Sopenharmony_ciint cxl_get_xsl9_dsnctl(struct pci_dev *dev, u64 capp_unit_id, u64 *reg); 102862306a36Sopenharmony_ciu64 cxl_calculate_sr(bool master, bool kernel, bool real_mode, bool p9); 102962306a36Sopenharmony_ci 103062306a36Sopenharmony_civoid cxl_native_irq_dump_regs_psl9(struct cxl_context *ctx); 103162306a36Sopenharmony_civoid cxl_native_irq_dump_regs_psl8(struct cxl_context *ctx); 103262306a36Sopenharmony_civoid cxl_native_err_irq_dump_regs_psl8(struct cxl *adapter); 103362306a36Sopenharmony_civoid cxl_native_err_irq_dump_regs_psl9(struct cxl *adapter); 103462306a36Sopenharmony_ciint cxl_pci_vphb_add(struct cxl_afu *afu); 103562306a36Sopenharmony_civoid cxl_pci_vphb_remove(struct cxl_afu *afu); 103662306a36Sopenharmony_civoid cxl_release_mapping(struct cxl_context *ctx); 103762306a36Sopenharmony_ci 103862306a36Sopenharmony_ciextern struct pci_driver cxl_pci_driver; 103962306a36Sopenharmony_ciextern struct platform_driver cxl_of_driver; 104062306a36Sopenharmony_ciint afu_allocate_irqs(struct cxl_context *ctx, u32 count); 104162306a36Sopenharmony_ci 104262306a36Sopenharmony_ciint afu_open(struct inode *inode, struct file *file); 104362306a36Sopenharmony_ciint afu_release(struct inode *inode, struct file *file); 104462306a36Sopenharmony_cilong afu_ioctl(struct file *file, unsigned int cmd, unsigned long arg); 104562306a36Sopenharmony_ciint afu_mmap(struct file *file, struct vm_area_struct *vm); 104662306a36Sopenharmony_ci__poll_t afu_poll(struct file *file, struct poll_table_struct *poll); 104762306a36Sopenharmony_cissize_t afu_read(struct file *file, char __user *buf, size_t count, loff_t *off); 104862306a36Sopenharmony_ciextern const struct file_operations afu_fops; 104962306a36Sopenharmony_ci 105062306a36Sopenharmony_cistruct cxl *cxl_guest_init_adapter(struct device_node *np, struct platform_device *dev); 105162306a36Sopenharmony_civoid cxl_guest_remove_adapter(struct cxl *adapter); 105262306a36Sopenharmony_ciint cxl_of_read_adapter_handle(struct cxl *adapter, struct device_node *np); 105362306a36Sopenharmony_ciint cxl_of_read_adapter_properties(struct cxl *adapter, struct device_node *np); 105462306a36Sopenharmony_cissize_t cxl_guest_read_adapter_vpd(struct cxl *adapter, void *buf, size_t len); 105562306a36Sopenharmony_cissize_t cxl_guest_read_afu_vpd(struct cxl_afu *afu, void *buf, size_t len); 105662306a36Sopenharmony_ciint cxl_guest_init_afu(struct cxl *adapter, int slice, struct device_node *afu_np); 105762306a36Sopenharmony_civoid cxl_guest_remove_afu(struct cxl_afu *afu); 105862306a36Sopenharmony_ciint cxl_of_read_afu_handle(struct cxl_afu *afu, struct device_node *afu_np); 105962306a36Sopenharmony_ciint cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *afu_np); 106062306a36Sopenharmony_ciint cxl_guest_add_chardev(struct cxl *adapter); 106162306a36Sopenharmony_civoid cxl_guest_remove_chardev(struct cxl *adapter); 106262306a36Sopenharmony_civoid cxl_guest_reload_module(struct cxl *adapter); 106362306a36Sopenharmony_ciint cxl_of_probe(struct platform_device *pdev); 106462306a36Sopenharmony_ci 106562306a36Sopenharmony_cistruct cxl_backend_ops { 106662306a36Sopenharmony_ci struct module *module; 106762306a36Sopenharmony_ci int (*adapter_reset)(struct cxl *adapter); 106862306a36Sopenharmony_ci int (*alloc_one_irq)(struct cxl *adapter); 106962306a36Sopenharmony_ci void (*release_one_irq)(struct cxl *adapter, int hwirq); 107062306a36Sopenharmony_ci int (*alloc_irq_ranges)(struct cxl_irq_ranges *irqs, 107162306a36Sopenharmony_ci struct cxl *adapter, unsigned int num); 107262306a36Sopenharmony_ci void (*release_irq_ranges)(struct cxl_irq_ranges *irqs, 107362306a36Sopenharmony_ci struct cxl *adapter); 107462306a36Sopenharmony_ci int (*setup_irq)(struct cxl *adapter, unsigned int hwirq, 107562306a36Sopenharmony_ci unsigned int virq); 107662306a36Sopenharmony_ci irqreturn_t (*handle_psl_slice_error)(struct cxl_context *ctx, 107762306a36Sopenharmony_ci u64 dsisr, u64 errstat); 107862306a36Sopenharmony_ci irqreturn_t (*psl_interrupt)(int irq, void *data); 107962306a36Sopenharmony_ci int (*ack_irq)(struct cxl_context *ctx, u64 tfc, u64 psl_reset_mask); 108062306a36Sopenharmony_ci void (*irq_wait)(struct cxl_context *ctx); 108162306a36Sopenharmony_ci int (*attach_process)(struct cxl_context *ctx, bool kernel, 108262306a36Sopenharmony_ci u64 wed, u64 amr); 108362306a36Sopenharmony_ci int (*detach_process)(struct cxl_context *ctx); 108462306a36Sopenharmony_ci void (*update_ivtes)(struct cxl_context *ctx); 108562306a36Sopenharmony_ci bool (*support_attributes)(const char *attr_name, enum cxl_attrs type); 108662306a36Sopenharmony_ci bool (*link_ok)(struct cxl *cxl, struct cxl_afu *afu); 108762306a36Sopenharmony_ci void (*release_afu)(struct device *dev); 108862306a36Sopenharmony_ci ssize_t (*afu_read_err_buffer)(struct cxl_afu *afu, char *buf, 108962306a36Sopenharmony_ci loff_t off, size_t count); 109062306a36Sopenharmony_ci int (*afu_check_and_enable)(struct cxl_afu *afu); 109162306a36Sopenharmony_ci int (*afu_activate_mode)(struct cxl_afu *afu, int mode); 109262306a36Sopenharmony_ci int (*afu_deactivate_mode)(struct cxl_afu *afu, int mode); 109362306a36Sopenharmony_ci int (*afu_reset)(struct cxl_afu *afu); 109462306a36Sopenharmony_ci int (*afu_cr_read8)(struct cxl_afu *afu, int cr_idx, u64 offset, u8 *val); 109562306a36Sopenharmony_ci int (*afu_cr_read16)(struct cxl_afu *afu, int cr_idx, u64 offset, u16 *val); 109662306a36Sopenharmony_ci int (*afu_cr_read32)(struct cxl_afu *afu, int cr_idx, u64 offset, u32 *val); 109762306a36Sopenharmony_ci int (*afu_cr_read64)(struct cxl_afu *afu, int cr_idx, u64 offset, u64 *val); 109862306a36Sopenharmony_ci int (*afu_cr_write8)(struct cxl_afu *afu, int cr_idx, u64 offset, u8 val); 109962306a36Sopenharmony_ci int (*afu_cr_write16)(struct cxl_afu *afu, int cr_idx, u64 offset, u16 val); 110062306a36Sopenharmony_ci int (*afu_cr_write32)(struct cxl_afu *afu, int cr_idx, u64 offset, u32 val); 110162306a36Sopenharmony_ci ssize_t (*read_adapter_vpd)(struct cxl *adapter, void *buf, size_t count); 110262306a36Sopenharmony_ci}; 110362306a36Sopenharmony_ciextern const struct cxl_backend_ops cxl_native_ops; 110462306a36Sopenharmony_ciextern const struct cxl_backend_ops cxl_guest_ops; 110562306a36Sopenharmony_ciextern const struct cxl_backend_ops *cxl_ops; 110662306a36Sopenharmony_ci 110762306a36Sopenharmony_ci/* check if the given pci_dev is on the cxl vphb bus */ 110862306a36Sopenharmony_cibool cxl_pci_is_vphb_device(struct pci_dev *dev); 110962306a36Sopenharmony_ci 111062306a36Sopenharmony_ci/* decode AFU error bits in the PSL register PSL_SERR_An */ 111162306a36Sopenharmony_civoid cxl_afu_decode_psl_serr(struct cxl_afu *afu, u64 serr); 111262306a36Sopenharmony_ci 111362306a36Sopenharmony_ci/* 111462306a36Sopenharmony_ci * Increments the number of attached contexts on an adapter. 111562306a36Sopenharmony_ci * In case an adapter_context_lock is taken the return -EBUSY. 111662306a36Sopenharmony_ci */ 111762306a36Sopenharmony_ciint cxl_adapter_context_get(struct cxl *adapter); 111862306a36Sopenharmony_ci 111962306a36Sopenharmony_ci/* Decrements the number of attached contexts on an adapter */ 112062306a36Sopenharmony_civoid cxl_adapter_context_put(struct cxl *adapter); 112162306a36Sopenharmony_ci 112262306a36Sopenharmony_ci/* If no active contexts then prevents contexts from being attached */ 112362306a36Sopenharmony_ciint cxl_adapter_context_lock(struct cxl *adapter); 112462306a36Sopenharmony_ci 112562306a36Sopenharmony_ci/* Unlock the contexts-lock if taken. Warn and force unlock otherwise */ 112662306a36Sopenharmony_civoid cxl_adapter_context_unlock(struct cxl *adapter); 112762306a36Sopenharmony_ci 112862306a36Sopenharmony_ci/* Increases the reference count to "struct mm_struct" */ 112962306a36Sopenharmony_civoid cxl_context_mm_count_get(struct cxl_context *ctx); 113062306a36Sopenharmony_ci 113162306a36Sopenharmony_ci/* Decrements the reference count to "struct mm_struct" */ 113262306a36Sopenharmony_civoid cxl_context_mm_count_put(struct cxl_context *ctx); 113362306a36Sopenharmony_ci 113462306a36Sopenharmony_ci#endif 1135