1*2874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 23ced8d73SChristophe Lombard /* 33ced8d73SChristophe Lombard * Copyright 2017 IBM Corp. 43ced8d73SChristophe Lombard */ 53ced8d73SChristophe Lombard 63ced8d73SChristophe Lombard #ifndef _MISC_CXLLIB_H 73ced8d73SChristophe Lombard #define _MISC_CXLLIB_H 83ced8d73SChristophe Lombard 93ced8d73SChristophe Lombard #include <linux/pci.h> 103ced8d73SChristophe Lombard #include <asm/reg.h> 113ced8d73SChristophe Lombard 123ced8d73SChristophe Lombard /* 133ced8d73SChristophe Lombard * cxl driver exports a in-kernel 'library' API which can be called by 143ced8d73SChristophe Lombard * other drivers to help interacting with an IBM XSL. 153ced8d73SChristophe Lombard */ 163ced8d73SChristophe Lombard 173ced8d73SChristophe Lombard /* 183ced8d73SChristophe Lombard * tells whether capi is supported on the PCIe slot where the 193ced8d73SChristophe Lombard * device is seated 203ced8d73SChristophe Lombard * 213ced8d73SChristophe Lombard * Input: 223ced8d73SChristophe Lombard * dev: device whose slot needs to be checked 233ced8d73SChristophe Lombard * flags: 0 for the time being 243ced8d73SChristophe Lombard */ 253ced8d73SChristophe Lombard bool cxllib_slot_is_supported(struct pci_dev *dev, unsigned long flags); 263ced8d73SChristophe Lombard 273ced8d73SChristophe Lombard 283ced8d73SChristophe Lombard /* 293ced8d73SChristophe Lombard * Returns the configuration parameters to be used by the XSL or device 303ced8d73SChristophe Lombard * 313ced8d73SChristophe Lombard * Input: 323ced8d73SChristophe Lombard * dev: device, used to find PHB 333ced8d73SChristophe Lombard * Output: 343ced8d73SChristophe Lombard * struct cxllib_xsl_config: 353ced8d73SChristophe Lombard * version 363ced8d73SChristophe Lombard * capi BAR address, i.e. 0x2000000000000-0x2FFFFFFFFFFFF 373ced8d73SChristophe Lombard * capi BAR size 383ced8d73SChristophe Lombard * data send control (XSL_DSNCTL) 393ced8d73SChristophe Lombard * dummy read address (XSL_DRA) 403ced8d73SChristophe Lombard */ 413ced8d73SChristophe Lombard #define CXL_XSL_CONFIG_VERSION1 1 423ced8d73SChristophe Lombard struct cxllib_xsl_config { 433ced8d73SChristophe Lombard u32 version; /* format version for register encoding */ 443ced8d73SChristophe Lombard u32 log_bar_size;/* log size of the capi_window */ 453ced8d73SChristophe Lombard u64 bar_addr; /* address of the start of capi window */ 463ced8d73SChristophe Lombard u64 dsnctl; /* matches definition of XSL_DSNCTL */ 473ced8d73SChristophe Lombard u64 dra; /* real address that can be used for dummy read */ 483ced8d73SChristophe Lombard }; 493ced8d73SChristophe Lombard 503ced8d73SChristophe Lombard int cxllib_get_xsl_config(struct pci_dev *dev, struct cxllib_xsl_config *cfg); 513ced8d73SChristophe Lombard 523ced8d73SChristophe Lombard 533ced8d73SChristophe Lombard /* 543ced8d73SChristophe Lombard * Activate capi for the pci host bridge associated with the device. 553ced8d73SChristophe Lombard * Can be extended to deactivate once we know how to do it. 563ced8d73SChristophe Lombard * Device must be ready to accept messages from the CAPP unit and 573ced8d73SChristophe Lombard * respond accordingly (TLB invalidates, ...) 583ced8d73SChristophe Lombard * 593ced8d73SChristophe Lombard * PHB is switched to capi mode through calls to skiboot. 603ced8d73SChristophe Lombard * CAPP snooping is activated 613ced8d73SChristophe Lombard * 623ced8d73SChristophe Lombard * Input: 633ced8d73SChristophe Lombard * dev: device whose PHB should switch mode 643ced8d73SChristophe Lombard * mode: mode to switch to i.e. CAPI or PCI 653ced8d73SChristophe Lombard * flags: options related to the mode 663ced8d73SChristophe Lombard */ 673ced8d73SChristophe Lombard enum cxllib_mode { 683ced8d73SChristophe Lombard CXL_MODE_CXL, 693ced8d73SChristophe Lombard CXL_MODE_PCI, 703ced8d73SChristophe Lombard }; 713ced8d73SChristophe Lombard 723ced8d73SChristophe Lombard #define CXL_MODE_NO_DMA 0 733ced8d73SChristophe Lombard #define CXL_MODE_DMA_TVT0 1 743ced8d73SChristophe Lombard #define CXL_MODE_DMA_TVT1 2 753ced8d73SChristophe Lombard 763ced8d73SChristophe Lombard int cxllib_switch_phb_mode(struct pci_dev *dev, enum cxllib_mode mode, 773ced8d73SChristophe Lombard unsigned long flags); 783ced8d73SChristophe Lombard 793ced8d73SChristophe Lombard 803ced8d73SChristophe Lombard /* 813ced8d73SChristophe Lombard * Set the device for capi DMA. 823ced8d73SChristophe Lombard * Define its dma_ops and dma offset so that allocations will be using TVT#1 833ced8d73SChristophe Lombard * 843ced8d73SChristophe Lombard * Input: 853ced8d73SChristophe Lombard * dev: device to set 863ced8d73SChristophe Lombard * flags: options. CXL_MODE_DMA_TVT1 should be used 873ced8d73SChristophe Lombard */ 883ced8d73SChristophe Lombard int cxllib_set_device_dma(struct pci_dev *dev, unsigned long flags); 893ced8d73SChristophe Lombard 903ced8d73SChristophe Lombard 913ced8d73SChristophe Lombard /* 923ced8d73SChristophe Lombard * Get the Process Element structure for the given thread 933ced8d73SChristophe Lombard * 943ced8d73SChristophe Lombard * Input: 953ced8d73SChristophe Lombard * task: task_struct for the context of the translation 963ced8d73SChristophe Lombard * translation_mode: whether addresses should be translated 973ced8d73SChristophe Lombard * Output: 983ced8d73SChristophe Lombard * attr: attributes to fill up the Process Element structure from CAIA 993ced8d73SChristophe Lombard */ 1003ced8d73SChristophe Lombard struct cxllib_pe_attributes { 1013ced8d73SChristophe Lombard u64 sr; 1023ced8d73SChristophe Lombard u32 lpid; 1033ced8d73SChristophe Lombard u32 tid; 1043ced8d73SChristophe Lombard u32 pid; 1053ced8d73SChristophe Lombard }; 1063ced8d73SChristophe Lombard #define CXL_TRANSLATED_MODE 0 1073ced8d73SChristophe Lombard #define CXL_REAL_MODE 1 1083ced8d73SChristophe Lombard 1093ced8d73SChristophe Lombard int cxllib_get_PE_attributes(struct task_struct *task, 1103ced8d73SChristophe Lombard unsigned long translation_mode, struct cxllib_pe_attributes *attr); 1113ced8d73SChristophe Lombard 1123ced8d73SChristophe Lombard 1133ced8d73SChristophe Lombard /* 1143ced8d73SChristophe Lombard * Handle memory fault. 1153ced8d73SChristophe Lombard * Fault in all the pages of the specified buffer for the permissions 1163ced8d73SChristophe Lombard * provided in ‘flags’ 1173ced8d73SChristophe Lombard * 1183ced8d73SChristophe Lombard * Shouldn't be called from interrupt context 1193ced8d73SChristophe Lombard * 1203ced8d73SChristophe Lombard * Input: 1213ced8d73SChristophe Lombard * mm: struct mm for the thread faulting the pages 1223ced8d73SChristophe Lombard * addr: base address of the buffer to page in 1233ced8d73SChristophe Lombard * size: size of the buffer to page in 1243ced8d73SChristophe Lombard * flags: permission requested (DSISR_ISSTORE...) 1253ced8d73SChristophe Lombard */ 1263ced8d73SChristophe Lombard int cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags); 1273ced8d73SChristophe Lombard 1283ced8d73SChristophe Lombard 1293ced8d73SChristophe Lombard #endif /* _MISC_CXLLIB_H */ 130