18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright 2017 IBM Corp.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef _MISC_CXLLIB_H
78c2ecf20Sopenharmony_ci#define _MISC_CXLLIB_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <linux/pci.h>
108c2ecf20Sopenharmony_ci#include <asm/reg.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci/*
138c2ecf20Sopenharmony_ci * cxl driver exports a in-kernel 'library' API which can be called by
148c2ecf20Sopenharmony_ci * other drivers to help interacting with an IBM XSL.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * tells whether capi is supported on the PCIe slot where the
198c2ecf20Sopenharmony_ci * device is seated
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * Input:
228c2ecf20Sopenharmony_ci *	dev: device whose slot needs to be checked
238c2ecf20Sopenharmony_ci *	flags: 0 for the time being
248c2ecf20Sopenharmony_ci */
258c2ecf20Sopenharmony_cibool cxllib_slot_is_supported(struct pci_dev *dev, unsigned long flags);
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/*
298c2ecf20Sopenharmony_ci * Returns the configuration parameters to be used by the XSL or device
308c2ecf20Sopenharmony_ci *
318c2ecf20Sopenharmony_ci * Input:
328c2ecf20Sopenharmony_ci *	dev: device, used to find PHB
338c2ecf20Sopenharmony_ci * Output:
348c2ecf20Sopenharmony_ci *	struct cxllib_xsl_config:
358c2ecf20Sopenharmony_ci *		version
368c2ecf20Sopenharmony_ci *		capi BAR address, i.e. 0x2000000000000-0x2FFFFFFFFFFFF
378c2ecf20Sopenharmony_ci *		capi BAR size
388c2ecf20Sopenharmony_ci *		data send control (XSL_DSNCTL)
398c2ecf20Sopenharmony_ci *		dummy read address (XSL_DRA)
408c2ecf20Sopenharmony_ci */
418c2ecf20Sopenharmony_ci#define CXL_XSL_CONFIG_VERSION1		1
428c2ecf20Sopenharmony_cistruct cxllib_xsl_config {
438c2ecf20Sopenharmony_ci	u32	version;     /* format version for register encoding */
448c2ecf20Sopenharmony_ci	u32	log_bar_size;/* log size of the capi_window */
458c2ecf20Sopenharmony_ci	u64	bar_addr;    /* address of the start of capi window */
468c2ecf20Sopenharmony_ci	u64	dsnctl;      /* matches definition of XSL_DSNCTL */
478c2ecf20Sopenharmony_ci	u64	dra;         /* real address that can be used for dummy read */
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ciint cxllib_get_xsl_config(struct pci_dev *dev, struct cxllib_xsl_config *cfg);
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/*
548c2ecf20Sopenharmony_ci * Activate capi for the pci host bridge associated with the device.
558c2ecf20Sopenharmony_ci * Can be extended to deactivate once we know how to do it.
568c2ecf20Sopenharmony_ci * Device must be ready to accept messages from the CAPP unit and
578c2ecf20Sopenharmony_ci * respond accordingly (TLB invalidates, ...)
588c2ecf20Sopenharmony_ci *
598c2ecf20Sopenharmony_ci * PHB is switched to capi mode through calls to skiboot.
608c2ecf20Sopenharmony_ci * CAPP snooping is activated
618c2ecf20Sopenharmony_ci *
628c2ecf20Sopenharmony_ci * Input:
638c2ecf20Sopenharmony_ci *	dev: device whose PHB should switch mode
648c2ecf20Sopenharmony_ci *	mode: mode to switch to i.e. CAPI or PCI
658c2ecf20Sopenharmony_ci *	flags: options related to the mode
668c2ecf20Sopenharmony_ci */
678c2ecf20Sopenharmony_cienum cxllib_mode {
688c2ecf20Sopenharmony_ci	CXL_MODE_CXL,
698c2ecf20Sopenharmony_ci	CXL_MODE_PCI,
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#define CXL_MODE_NO_DMA       0
738c2ecf20Sopenharmony_ci#define CXL_MODE_DMA_TVT0     1
748c2ecf20Sopenharmony_ci#define CXL_MODE_DMA_TVT1     2
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ciint cxllib_switch_phb_mode(struct pci_dev *dev, enum cxllib_mode mode,
778c2ecf20Sopenharmony_ci			unsigned long flags);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci/*
818c2ecf20Sopenharmony_ci * Set the device for capi DMA.
828c2ecf20Sopenharmony_ci * Define its dma_ops and dma offset so that allocations will be using TVT#1
838c2ecf20Sopenharmony_ci *
848c2ecf20Sopenharmony_ci * Input:
858c2ecf20Sopenharmony_ci *	dev: device to set
868c2ecf20Sopenharmony_ci *	flags: options. CXL_MODE_DMA_TVT1 should be used
878c2ecf20Sopenharmony_ci */
888c2ecf20Sopenharmony_ciint cxllib_set_device_dma(struct pci_dev *dev, unsigned long flags);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci/*
928c2ecf20Sopenharmony_ci * Get the Process Element structure for the given thread
938c2ecf20Sopenharmony_ci *
948c2ecf20Sopenharmony_ci * Input:
958c2ecf20Sopenharmony_ci *    task: task_struct for the context of the translation
968c2ecf20Sopenharmony_ci *    translation_mode: whether addresses should be translated
978c2ecf20Sopenharmony_ci * Output:
988c2ecf20Sopenharmony_ci *    attr: attributes to fill up the Process Element structure from CAIA
998c2ecf20Sopenharmony_ci */
1008c2ecf20Sopenharmony_cistruct cxllib_pe_attributes {
1018c2ecf20Sopenharmony_ci	u64 sr;
1028c2ecf20Sopenharmony_ci	u32 lpid;
1038c2ecf20Sopenharmony_ci	u32 tid;
1048c2ecf20Sopenharmony_ci	u32 pid;
1058c2ecf20Sopenharmony_ci};
1068c2ecf20Sopenharmony_ci#define CXL_TRANSLATED_MODE 0
1078c2ecf20Sopenharmony_ci#define CXL_REAL_MODE 1
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciint cxllib_get_PE_attributes(struct task_struct *task,
1108c2ecf20Sopenharmony_ci	     unsigned long translation_mode, struct cxllib_pe_attributes *attr);
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_ci/*
1148c2ecf20Sopenharmony_ci * Handle memory fault.
1158c2ecf20Sopenharmony_ci * Fault in all the pages of the specified buffer for the permissions
1168c2ecf20Sopenharmony_ci * provided in ‘flags’
1178c2ecf20Sopenharmony_ci *
1188c2ecf20Sopenharmony_ci * Shouldn't be called from interrupt context
1198c2ecf20Sopenharmony_ci *
1208c2ecf20Sopenharmony_ci * Input:
1218c2ecf20Sopenharmony_ci *	mm: struct mm for the thread faulting the pages
1228c2ecf20Sopenharmony_ci *	addr: base address of the buffer to page in
1238c2ecf20Sopenharmony_ci *	size: size of the buffer to page in
1248c2ecf20Sopenharmony_ci *	flags: permission requested (DSISR_ISSTORE...)
1258c2ecf20Sopenharmony_ci */
1268c2ecf20Sopenharmony_ciint cxllib_handle_fault(struct mm_struct *mm, u64 addr, u64 size, u64 flags);
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#endif /* _MISC_CXLLIB_H */
130