1280b983cSFrederic Barrat // SPDX-License-Identifier: GPL-2.0+ 2280b983cSFrederic Barrat // Copyright 2017 IBM Corp. 3280b983cSFrederic Barrat #ifndef _MISC_OCXL_H_ 4280b983cSFrederic Barrat #define _MISC_OCXL_H_ 5280b983cSFrederic Barrat 6280b983cSFrederic Barrat #include <linux/pci.h> 7280b983cSFrederic Barrat 8280b983cSFrederic Barrat /* 9280b983cSFrederic Barrat * Opencapi drivers all need some common facilities, like parsing the 10280b983cSFrederic Barrat * device configuration space, adding a Process Element to the Shared 11280b983cSFrederic Barrat * Process Area, etc... 12280b983cSFrederic Barrat * 13280b983cSFrederic Barrat * The ocxl module provides a kernel API, to allow other drivers to 14280b983cSFrederic Barrat * reuse common code. A bit like a in-kernel library. 15280b983cSFrederic Barrat */ 16280b983cSFrederic Barrat 17280b983cSFrederic Barrat #define OCXL_AFU_NAME_SZ (24+1) /* add 1 for NULL termination */ 18280b983cSFrederic Barrat 1975ca758aSAlastair D'Silva 20280b983cSFrederic Barrat struct ocxl_afu_config { 21280b983cSFrederic Barrat u8 idx; 22280b983cSFrederic Barrat int dvsec_afu_control_pos; /* offset of AFU control DVSEC */ 23280b983cSFrederic Barrat char name[OCXL_AFU_NAME_SZ]; 24280b983cSFrederic Barrat u8 version_major; 25280b983cSFrederic Barrat u8 version_minor; 26280b983cSFrederic Barrat u8 afuc_type; 27280b983cSFrederic Barrat u8 afum_type; 28280b983cSFrederic Barrat u8 profile; 29280b983cSFrederic Barrat u8 global_mmio_bar; /* global MMIO area */ 30280b983cSFrederic Barrat u64 global_mmio_offset; 31280b983cSFrederic Barrat u32 global_mmio_size; 32280b983cSFrederic Barrat u8 pp_mmio_bar; /* per-process MMIO area */ 33280b983cSFrederic Barrat u64 pp_mmio_offset; 34280b983cSFrederic Barrat u32 pp_mmio_stride; 3573a2b047SAlastair D'Silva u64 lpc_mem_offset; 3673a2b047SAlastair D'Silva u64 lpc_mem_size; 3773a2b047SAlastair D'Silva u64 special_purpose_mem_offset; 3873a2b047SAlastair D'Silva u64 special_purpose_mem_size; 39280b983cSFrederic Barrat u8 pasid_supported_log; 40280b983cSFrederic Barrat u16 actag_supported; 41280b983cSFrederic Barrat }; 42280b983cSFrederic Barrat 43280b983cSFrederic Barrat struct ocxl_fn_config { 44280b983cSFrederic Barrat int dvsec_tl_pos; /* offset of the Transaction Layer DVSEC */ 45280b983cSFrederic Barrat int dvsec_function_pos; /* offset of the Function DVSEC */ 46280b983cSFrederic Barrat int dvsec_afu_info_pos; /* offset of the AFU information DVSEC */ 47280b983cSFrederic Barrat s8 max_pasid_log; 48280b983cSFrederic Barrat s8 max_afu_index; 49280b983cSFrederic Barrat }; 50280b983cSFrederic Barrat 517e462c2aSAlastair D'Silva enum ocxl_endian { 527e462c2aSAlastair D'Silva OCXL_BIG_ENDIAN = 0, /**< AFU data is big-endian */ 537e462c2aSAlastair D'Silva OCXL_LITTLE_ENDIAN = 1, /**< AFU data is little-endian */ 547e462c2aSAlastair D'Silva OCXL_HOST_ENDIAN = 2, /**< AFU data is the same endianness as the host */ 557e462c2aSAlastair D'Silva }; 567e462c2aSAlastair D'Silva 5775ca758aSAlastair D'Silva // These are opaque outside the ocxl driver 5875ca758aSAlastair D'Silva struct ocxl_afu; 5975ca758aSAlastair D'Silva struct ocxl_fn; 60b9721d27SAlastair D'Silva struct ocxl_context; 6175ca758aSAlastair D'Silva 6275ca758aSAlastair D'Silva // Device detection & initialisation 6375ca758aSAlastair D'Silva 6475ca758aSAlastair D'Silva /** 653591538aSAlastair D'Silva * ocxl_function_open() - Open an OpenCAPI function on an OpenCAPI device 6675ca758aSAlastair D'Silva * @dev: The PCI device that contains the function 6775ca758aSAlastair D'Silva * 6875ca758aSAlastair D'Silva * Returns an opaque pointer to the function, or an error pointer (check with IS_ERR) 69280b983cSFrederic Barrat */ 7075ca758aSAlastair D'Silva struct ocxl_fn *ocxl_function_open(struct pci_dev *dev); 7175ca758aSAlastair D'Silva 7275ca758aSAlastair D'Silva /** 733591538aSAlastair D'Silva * ocxl_function_afu_list() - Get the list of AFUs associated with a PCI function device 7475ca758aSAlastair D'Silva * Returns a list of struct ocxl_afu * 7575ca758aSAlastair D'Silva * 7675ca758aSAlastair D'Silva * @fn: The OpenCAPI function containing the AFUs 7775ca758aSAlastair D'Silva */ 7875ca758aSAlastair D'Silva struct list_head *ocxl_function_afu_list(struct ocxl_fn *fn); 7975ca758aSAlastair D'Silva 8075ca758aSAlastair D'Silva /** 813591538aSAlastair D'Silva * ocxl_function_fetch_afu() - Fetch an AFU instance from an OpenCAPI function 8275ca758aSAlastair D'Silva * @fn: The OpenCAPI function to get the AFU from 8375ca758aSAlastair D'Silva * @afu_idx: The index of the AFU to get 8475ca758aSAlastair D'Silva * 8575ca758aSAlastair D'Silva * If successful, the AFU should be released with ocxl_afu_put() 8675ca758aSAlastair D'Silva * 8775ca758aSAlastair D'Silva * Returns a pointer to the AFU, or NULL on error 8875ca758aSAlastair D'Silva */ 8975ca758aSAlastair D'Silva struct ocxl_afu *ocxl_function_fetch_afu(struct ocxl_fn *fn, u8 afu_idx); 9075ca758aSAlastair D'Silva 9175ca758aSAlastair D'Silva /** 923591538aSAlastair D'Silva * ocxl_afu_get() - Take a reference to an AFU 9375ca758aSAlastair D'Silva * @afu: The AFU to increment the reference count on 9475ca758aSAlastair D'Silva */ 9575ca758aSAlastair D'Silva void ocxl_afu_get(struct ocxl_afu *afu); 9675ca758aSAlastair D'Silva 9775ca758aSAlastair D'Silva /** 983591538aSAlastair D'Silva * ocxl_afu_put() - Release a reference to an AFU 9975ca758aSAlastair D'Silva * @afu: The AFU to decrement the reference count on 10075ca758aSAlastair D'Silva */ 10175ca758aSAlastair D'Silva void ocxl_afu_put(struct ocxl_afu *afu); 10275ca758aSAlastair D'Silva 10375ca758aSAlastair D'Silva 10475ca758aSAlastair D'Silva /** 1053591538aSAlastair D'Silva * ocxl_function_config() - Get the configuration information for an OpenCAPI function 10675ca758aSAlastair D'Silva * @fn: The OpenCAPI function to get the config for 10775ca758aSAlastair D'Silva * 10875ca758aSAlastair D'Silva * Returns the function config, or NULL on error 10975ca758aSAlastair D'Silva */ 11075ca758aSAlastair D'Silva const struct ocxl_fn_config *ocxl_function_config(struct ocxl_fn *fn); 11175ca758aSAlastair D'Silva 11275ca758aSAlastair D'Silva /** 1133591538aSAlastair D'Silva * ocxl_function_close() - Close an OpenCAPI function 11475ca758aSAlastair D'Silva * This will free any AFUs previously retrieved from the function, and 11575ca758aSAlastair D'Silva * detach and associated contexts. The contexts must by freed by the caller. 11675ca758aSAlastair D'Silva * 11775ca758aSAlastair D'Silva * @fn: The OpenCAPI function to close 11875ca758aSAlastair D'Silva * 11975ca758aSAlastair D'Silva */ 12075ca758aSAlastair D'Silva void ocxl_function_close(struct ocxl_fn *fn); 12175ca758aSAlastair D'Silva 122b9721d27SAlastair D'Silva // Context allocation 123b9721d27SAlastair D'Silva 124b9721d27SAlastair D'Silva /** 1253591538aSAlastair D'Silva * ocxl_context_alloc() - Allocate an OpenCAPI context 126b9721d27SAlastair D'Silva * @context: The OpenCAPI context to allocate, must be freed with ocxl_context_free 127b9721d27SAlastair D'Silva * @afu: The AFU the context belongs to 128b9721d27SAlastair D'Silva * @mapping: The mapping to unmap when the context is closed (may be NULL) 129b9721d27SAlastair D'Silva */ 130b9721d27SAlastair D'Silva int ocxl_context_alloc(struct ocxl_context **context, struct ocxl_afu *afu, 131b9721d27SAlastair D'Silva struct address_space *mapping); 132b9721d27SAlastair D'Silva 133b9721d27SAlastair D'Silva /** 1343591538aSAlastair D'Silva * ocxl_context_free() - Free an OpenCAPI context 135b9721d27SAlastair D'Silva * @ctx: The OpenCAPI context to free 136b9721d27SAlastair D'Silva */ 137b9721d27SAlastair D'Silva void ocxl_context_free(struct ocxl_context *ctx); 138b9721d27SAlastair D'Silva 139b9721d27SAlastair D'Silva /** 1403591538aSAlastair D'Silva * ocxl_context_attach() - Grant access to an MM to an OpenCAPI context 141b9721d27SAlastair D'Silva * @ctx: The OpenCAPI context to attach 142b9721d27SAlastair D'Silva * @amr: The value of the AMR register to restrict access 143b9721d27SAlastair D'Silva * @mm: The mm to attach to the context 144b9721d27SAlastair D'Silva * 145b9721d27SAlastair D'Silva * Returns 0 on success, negative on failure 146b9721d27SAlastair D'Silva */ 147b9721d27SAlastair D'Silva int ocxl_context_attach(struct ocxl_context *ctx, u64 amr, 148b9721d27SAlastair D'Silva struct mm_struct *mm); 149b9721d27SAlastair D'Silva 150b9721d27SAlastair D'Silva /** 1513591538aSAlastair D'Silva * ocxl_context_detach() - Detach an MM from an OpenCAPI context 152b9721d27SAlastair D'Silva * @ctx: The OpenCAPI context to attach 153b9721d27SAlastair D'Silva * 154b9721d27SAlastair D'Silva * Returns 0 on success, negative on failure 155b9721d27SAlastair D'Silva */ 156b9721d27SAlastair D'Silva int ocxl_context_detach(struct ocxl_context *ctx); 157b9721d27SAlastair D'Silva 15806014661SAlastair D'Silva // AFU IRQs 15906014661SAlastair D'Silva 16006014661SAlastair D'Silva /** 1613591538aSAlastair D'Silva * ocxl_afu_irq_alloc() - Allocate an IRQ associated with an AFU context 16206014661SAlastair D'Silva * @ctx: the AFU context 16306014661SAlastair D'Silva * @irq_id: out, the IRQ ID 16406014661SAlastair D'Silva * 16506014661SAlastair D'Silva * Returns 0 on success, negative on failure 16606014661SAlastair D'Silva */ 167c75d42e4SAlastair D'Silva int ocxl_afu_irq_alloc(struct ocxl_context *ctx, int *irq_id); 16806014661SAlastair D'Silva 16906014661SAlastair D'Silva /** 1703591538aSAlastair D'Silva * ocxl_afu_irq_free() - Frees an IRQ associated with an AFU context 17106014661SAlastair D'Silva * @ctx: the AFU context 17206014661SAlastair D'Silva * @irq_id: the IRQ ID 17306014661SAlastair D'Silva * 17406014661SAlastair D'Silva * Returns 0 on success, negative on failure 17506014661SAlastair D'Silva */ 176c75d42e4SAlastair D'Silva int ocxl_afu_irq_free(struct ocxl_context *ctx, int irq_id); 17706014661SAlastair D'Silva 17806014661SAlastair D'Silva /** 1793591538aSAlastair D'Silva * ocxl_afu_irq_get_addr() - Gets the address of the trigger page for an IRQ 18006014661SAlastair D'Silva * This can then be provided to an AFU which will write to that 18106014661SAlastair D'Silva * page to trigger the IRQ. 18206014661SAlastair D'Silva * @ctx: The AFU context that the IRQ is associated with 18306014661SAlastair D'Silva * @irq_id: The IRQ ID 18406014661SAlastair D'Silva * 18506014661SAlastair D'Silva * returns the trigger page address, or 0 if the IRQ is not valid 18606014661SAlastair D'Silva */ 187c75d42e4SAlastair D'Silva u64 ocxl_afu_irq_get_addr(struct ocxl_context *ctx, int irq_id); 18806014661SAlastair D'Silva 18906014661SAlastair D'Silva /** 1903591538aSAlastair D'Silva * ocxl_irq_set_handler() - Provide a callback to be called when an IRQ is triggered 19106014661SAlastair D'Silva * @ctx: The AFU context that the IRQ is associated with 19206014661SAlastair D'Silva * @irq_id: The IRQ ID 19306014661SAlastair D'Silva * @handler: the callback to be called when the IRQ is triggered 19406014661SAlastair D'Silva * @free_private: the callback to be called when the IRQ is freed (may be NULL) 19506014661SAlastair D'Silva * @private: Private data to be passed to the callbacks 19606014661SAlastair D'Silva * 19706014661SAlastair D'Silva * Returns 0 on success, negative on failure 19806014661SAlastair D'Silva */ 19906014661SAlastair D'Silva int ocxl_irq_set_handler(struct ocxl_context *ctx, int irq_id, 20006014661SAlastair D'Silva irqreturn_t (*handler)(void *private), 20106014661SAlastair D'Silva void (*free_private)(void *private), 20206014661SAlastair D'Silva void *private); 20306014661SAlastair D'Silva 20475ca758aSAlastair D'Silva // AFU Metadata 20575ca758aSAlastair D'Silva 20675ca758aSAlastair D'Silva /** 2073591538aSAlastair D'Silva * ocxl_afu_config() - Get a pointer to the config for an AFU 20875ca758aSAlastair D'Silva * @afu: a pointer to the AFU to get the config for 20975ca758aSAlastair D'Silva * 21075ca758aSAlastair D'Silva * Returns a pointer to the AFU config 21175ca758aSAlastair D'Silva */ 21275ca758aSAlastair D'Silva struct ocxl_afu_config *ocxl_afu_config(struct ocxl_afu *afu); 21375ca758aSAlastair D'Silva 21475ca758aSAlastair D'Silva /** 2153591538aSAlastair D'Silva * ocxl_afu_set_private() - Assign opaque hardware specific information to an OpenCAPI AFU. 2163591538aSAlastair D'Silva * @afu: The OpenCAPI AFU 21775ca758aSAlastair D'Silva * @private: the opaque hardware specific information to assign to the driver 21875ca758aSAlastair D'Silva */ 21975ca758aSAlastair D'Silva void ocxl_afu_set_private(struct ocxl_afu *afu, void *private); 22075ca758aSAlastair D'Silva 22175ca758aSAlastair D'Silva /** 2223591538aSAlastair D'Silva * ocxl_afu_get_private() - Fetch the hardware specific information associated with 2233591538aSAlastair D'Silva * an external OpenCAPI AFU. This may be consumed by an external OpenCAPI driver. 2243591538aSAlastair D'Silva * @afu: The OpenCAPI AFU 22575ca758aSAlastair D'Silva * 22675ca758aSAlastair D'Silva * Returns the opaque pointer associated with the device, or NULL if not set 22775ca758aSAlastair D'Silva */ 2283591538aSAlastair D'Silva void *ocxl_afu_get_private(struct ocxl_afu *afu); 22975ca758aSAlastair D'Silva 2307e462c2aSAlastair D'Silva // Global MMIO 2317e462c2aSAlastair D'Silva /** 2323591538aSAlastair D'Silva * ocxl_global_mmio_read32() - Read a 32 bit value from global MMIO 2337e462c2aSAlastair D'Silva * @afu: The AFU 2347e462c2aSAlastair D'Silva * @offset: The Offset from the start of MMIO 2357e462c2aSAlastair D'Silva * @endian: the endianness that the MMIO data is in 2367e462c2aSAlastair D'Silva * @val: returns the value 2377e462c2aSAlastair D'Silva * 2387e462c2aSAlastair D'Silva * Returns 0 for success, negative on error 2397e462c2aSAlastair D'Silva */ 2407e462c2aSAlastair D'Silva int ocxl_global_mmio_read32(struct ocxl_afu *afu, size_t offset, 2417e462c2aSAlastair D'Silva enum ocxl_endian endian, u32 *val); 2427e462c2aSAlastair D'Silva 2437e462c2aSAlastair D'Silva /** 2443591538aSAlastair D'Silva * ocxl_global_mmio_read64() - Read a 64 bit value from global MMIO 2457e462c2aSAlastair D'Silva * @afu: The AFU 2467e462c2aSAlastair D'Silva * @offset: The Offset from the start of MMIO 2477e462c2aSAlastair D'Silva * @endian: the endianness that the MMIO data is in 2487e462c2aSAlastair D'Silva * @val: returns the value 2497e462c2aSAlastair D'Silva * 2507e462c2aSAlastair D'Silva * Returns 0 for success, negative on error 2517e462c2aSAlastair D'Silva */ 2527e462c2aSAlastair D'Silva int ocxl_global_mmio_read64(struct ocxl_afu *afu, size_t offset, 2537e462c2aSAlastair D'Silva enum ocxl_endian endian, u64 *val); 2547e462c2aSAlastair D'Silva 2557e462c2aSAlastair D'Silva /** 2563591538aSAlastair D'Silva * ocxl_global_mmio_write32() - Write a 32 bit value to global MMIO 2577e462c2aSAlastair D'Silva * @afu: The AFU 2587e462c2aSAlastair D'Silva * @offset: The Offset from the start of MMIO 2597e462c2aSAlastair D'Silva * @endian: the endianness that the MMIO data is in 2607e462c2aSAlastair D'Silva * @val: The value to write 2617e462c2aSAlastair D'Silva * 2627e462c2aSAlastair D'Silva * Returns 0 for success, negative on error 2637e462c2aSAlastair D'Silva */ 2647e462c2aSAlastair D'Silva int ocxl_global_mmio_write32(struct ocxl_afu *afu, size_t offset, 2657e462c2aSAlastair D'Silva enum ocxl_endian endian, u32 val); 2667e462c2aSAlastair D'Silva 2677e462c2aSAlastair D'Silva /** 2683591538aSAlastair D'Silva * ocxl_global_mmio_write64() - Write a 64 bit value to global MMIO 2697e462c2aSAlastair D'Silva * @afu: The AFU 2707e462c2aSAlastair D'Silva * @offset: The Offset from the start of MMIO 2717e462c2aSAlastair D'Silva * @endian: the endianness that the MMIO data is in 2727e462c2aSAlastair D'Silva * @val: The value to write 2737e462c2aSAlastair D'Silva * 2747e462c2aSAlastair D'Silva * Returns 0 for success, negative on error 2757e462c2aSAlastair D'Silva */ 2767e462c2aSAlastair D'Silva int ocxl_global_mmio_write64(struct ocxl_afu *afu, size_t offset, 2777e462c2aSAlastair D'Silva enum ocxl_endian endian, u64 val); 2787e462c2aSAlastair D'Silva 2797e462c2aSAlastair D'Silva /** 2803591538aSAlastair D'Silva * ocxl_global_mmio_set32() - Set bits in a 32 bit global MMIO register 2817e462c2aSAlastair D'Silva * @afu: The AFU 2827e462c2aSAlastair D'Silva * @offset: The Offset from the start of MMIO 2837e462c2aSAlastair D'Silva * @endian: the endianness that the MMIO data is in 2847e462c2aSAlastair D'Silva * @mask: a mask of the bits to set 2857e462c2aSAlastair D'Silva * 2867e462c2aSAlastair D'Silva * Returns 0 for success, negative on error 2877e462c2aSAlastair D'Silva */ 2887e462c2aSAlastair D'Silva int ocxl_global_mmio_set32(struct ocxl_afu *afu, size_t offset, 2897e462c2aSAlastair D'Silva enum ocxl_endian endian, u32 mask); 2907e462c2aSAlastair D'Silva 2917e462c2aSAlastair D'Silva /** 2923591538aSAlastair D'Silva * ocxl_global_mmio_set64() - Set bits in a 64 bit global MMIO register 2937e462c2aSAlastair D'Silva * @afu: The AFU 2947e462c2aSAlastair D'Silva * @offset: The Offset from the start of MMIO 2957e462c2aSAlastair D'Silva * @endian: the endianness that the MMIO data is in 2967e462c2aSAlastair D'Silva * @mask: a mask of the bits to set 2977e462c2aSAlastair D'Silva * 2987e462c2aSAlastair D'Silva * Returns 0 for success, negative on error 2997e462c2aSAlastair D'Silva */ 3007e462c2aSAlastair D'Silva int ocxl_global_mmio_set64(struct ocxl_afu *afu, size_t offset, 3017e462c2aSAlastair D'Silva enum ocxl_endian endian, u64 mask); 3027e462c2aSAlastair D'Silva 3037e462c2aSAlastair D'Silva /** 3043591538aSAlastair D'Silva * ocxl_global_mmio_clear32() - Set bits in a 32 bit global MMIO register 3057e462c2aSAlastair D'Silva * @afu: The AFU 3067e462c2aSAlastair D'Silva * @offset: The Offset from the start of MMIO 3077e462c2aSAlastair D'Silva * @endian: the endianness that the MMIO data is in 3087e462c2aSAlastair D'Silva * @mask: a mask of the bits to set 3097e462c2aSAlastair D'Silva * 3107e462c2aSAlastair D'Silva * Returns 0 for success, negative on error 3117e462c2aSAlastair D'Silva */ 3127e462c2aSAlastair D'Silva int ocxl_global_mmio_clear32(struct ocxl_afu *afu, size_t offset, 3137e462c2aSAlastair D'Silva enum ocxl_endian endian, u32 mask); 3147e462c2aSAlastair D'Silva 3157e462c2aSAlastair D'Silva /** 3163591538aSAlastair D'Silva * ocxl_global_mmio_clear64() - Set bits in a 64 bit global MMIO register 3177e462c2aSAlastair D'Silva * @afu: The AFU 3187e462c2aSAlastair D'Silva * @offset: The Offset from the start of MMIO 3197e462c2aSAlastair D'Silva * @endian: the endianness that the MMIO data is in 3207e462c2aSAlastair D'Silva * @mask: a mask of the bits to set 3217e462c2aSAlastair D'Silva * 3227e462c2aSAlastair D'Silva * Returns 0 for success, negative on error 3237e462c2aSAlastair D'Silva */ 3247e462c2aSAlastair D'Silva int ocxl_global_mmio_clear64(struct ocxl_afu *afu, size_t offset, 3257e462c2aSAlastair D'Silva enum ocxl_endian endian, u64 mask); 32675ca758aSAlastair D'Silva 32775ca758aSAlastair D'Silva // Functions left here are for compatibility with the cxlflash driver 328280b983cSFrederic Barrat 329280b983cSFrederic Barrat /* 330280b983cSFrederic Barrat * Read the configuration space of a function for the AFU specified by 331280b983cSFrederic Barrat * the index 'afu_idx'. Fills in a ocxl_afu_config structure 332280b983cSFrederic Barrat */ 33353e3e745SAlastair D'Silva int ocxl_config_read_afu(struct pci_dev *dev, 334280b983cSFrederic Barrat struct ocxl_fn_config *fn, 335280b983cSFrederic Barrat struct ocxl_afu_config *afu, 336280b983cSFrederic Barrat u8 afu_idx); 337280b983cSFrederic Barrat 338280b983cSFrederic Barrat /* 339280b983cSFrederic Barrat * Tell an AFU, by writing in the configuration space, the PASIDs that 340280b983cSFrederic Barrat * it can use. Range starts at 'pasid_base' and its size is a multiple 341280b983cSFrederic Barrat * of 2 342280b983cSFrederic Barrat * 343280b983cSFrederic Barrat * 'afu_control_offset' is the offset of the AFU control DVSEC which 344280b983cSFrederic Barrat * can be found in the function configuration 345280b983cSFrederic Barrat */ 34653e3e745SAlastair D'Silva void ocxl_config_set_afu_pasid(struct pci_dev *dev, 347280b983cSFrederic Barrat int afu_control_offset, 348280b983cSFrederic Barrat int pasid_base, u32 pasid_count_log); 349280b983cSFrederic Barrat 350280b983cSFrederic Barrat /* 351280b983cSFrederic Barrat * Get the actag configuration for the function: 352280b983cSFrederic Barrat * 'base' is the first actag value that can be used. 353280b983cSFrederic Barrat * 'enabled' it the number of actags available, starting from base. 354280b983cSFrederic Barrat * 'supported' is the total number of actags desired by all the AFUs 355280b983cSFrederic Barrat * of the function. 356280b983cSFrederic Barrat */ 35753e3e745SAlastair D'Silva int ocxl_config_get_actag_info(struct pci_dev *dev, 358280b983cSFrederic Barrat u16 *base, u16 *enabled, u16 *supported); 359280b983cSFrederic Barrat 360280b983cSFrederic Barrat /* 361280b983cSFrederic Barrat * Tell a function, by writing in the configuration space, the actags 362280b983cSFrederic Barrat * it can use. 363280b983cSFrederic Barrat * 364280b983cSFrederic Barrat * 'func_offset' is the offset of the Function DVSEC that can found in 365280b983cSFrederic Barrat * the function configuration 366280b983cSFrederic Barrat */ 36753e3e745SAlastair D'Silva void ocxl_config_set_actag(struct pci_dev *dev, int func_offset, 368280b983cSFrederic Barrat u32 actag_base, u32 actag_count); 369280b983cSFrederic Barrat 370280b983cSFrederic Barrat /* 371280b983cSFrederic Barrat * Tell an AFU, by writing in the configuration space, the actags it 372280b983cSFrederic Barrat * can use. 373280b983cSFrederic Barrat * 374280b983cSFrederic Barrat * 'afu_control_offset' is the offset of the AFU control DVSEC for the 375280b983cSFrederic Barrat * desired AFU. It can be found in the AFU configuration 376280b983cSFrederic Barrat */ 37753e3e745SAlastair D'Silva void ocxl_config_set_afu_actag(struct pci_dev *dev, 378280b983cSFrederic Barrat int afu_control_offset, 379280b983cSFrederic Barrat int actag_base, int actag_count); 380280b983cSFrederic Barrat 381280b983cSFrederic Barrat /* 382280b983cSFrederic Barrat * Enable/disable an AFU, by writing in the configuration space. 383280b983cSFrederic Barrat * 384280b983cSFrederic Barrat * 'afu_control_offset' is the offset of the AFU control DVSEC for the 385280b983cSFrederic Barrat * desired AFU. It can be found in the AFU configuration 386280b983cSFrederic Barrat */ 38753e3e745SAlastair D'Silva void ocxl_config_set_afu_state(struct pci_dev *dev, 388280b983cSFrederic Barrat int afu_control_offset, int enable); 389280b983cSFrederic Barrat 390280b983cSFrederic Barrat /* 391280b983cSFrederic Barrat * Set the Transaction Layer configuration in the configuration space. 392280b983cSFrederic Barrat * Only needed for function 0. 393280b983cSFrederic Barrat * 394280b983cSFrederic Barrat * It queries the host TL capabilities, find some common ground 395280b983cSFrederic Barrat * between the host and device, and set the Transaction Layer on both 396280b983cSFrederic Barrat * accordingly. 397280b983cSFrederic Barrat */ 39853e3e745SAlastair D'Silva int ocxl_config_set_TL(struct pci_dev *dev, int tl_dvsec); 399280b983cSFrederic Barrat 400280b983cSFrederic Barrat /* 401280b983cSFrederic Barrat * Request an AFU to terminate a PASID. 402280b983cSFrederic Barrat * Will return once the AFU has acked the request, or an error in case 403280b983cSFrederic Barrat * of timeout. 404280b983cSFrederic Barrat * 405280b983cSFrederic Barrat * The hardware can only terminate one PASID at a time, so caller must 406280b983cSFrederic Barrat * guarantee some kind of serialization. 407280b983cSFrederic Barrat * 408280b983cSFrederic Barrat * 'afu_control_offset' is the offset of the AFU control DVSEC for the 409280b983cSFrederic Barrat * desired AFU. It can be found in the AFU configuration 410280b983cSFrederic Barrat */ 41153e3e745SAlastair D'Silva int ocxl_config_terminate_pasid(struct pci_dev *dev, 412280b983cSFrederic Barrat int afu_control_offset, int pasid); 413280b983cSFrederic Barrat 414280b983cSFrederic Barrat /* 41575ca758aSAlastair D'Silva * Read the configuration space of a function and fill in a 41675ca758aSAlastair D'Silva * ocxl_fn_config structure with all the function details 41775ca758aSAlastair D'Silva */ 41875ca758aSAlastair D'Silva int ocxl_config_read_function(struct pci_dev *dev, 41975ca758aSAlastair D'Silva struct ocxl_fn_config *fn); 42075ca758aSAlastair D'Silva 42175ca758aSAlastair D'Silva /* 422280b983cSFrederic Barrat * Set up the opencapi link for the function. 423280b983cSFrederic Barrat * 424280b983cSFrederic Barrat * When called for the first time for a link, it sets up the Shared 425280b983cSFrederic Barrat * Process Area for the link and the interrupt handler to process 426280b983cSFrederic Barrat * translation faults. 427280b983cSFrederic Barrat * 428280b983cSFrederic Barrat * Returns a 'link handle' that should be used for further calls for 429280b983cSFrederic Barrat * the link 430280b983cSFrederic Barrat */ 43153e3e745SAlastair D'Silva int ocxl_link_setup(struct pci_dev *dev, int PE_mask, 432280b983cSFrederic Barrat void **link_handle); 433280b983cSFrederic Barrat 434280b983cSFrederic Barrat /* 435280b983cSFrederic Barrat * Remove the association between the function and its link. 436280b983cSFrederic Barrat */ 43753e3e745SAlastair D'Silva void ocxl_link_release(struct pci_dev *dev, void *link_handle); 438280b983cSFrederic Barrat 439280b983cSFrederic Barrat /* 440280b983cSFrederic Barrat * Add a Process Element to the Shared Process Area for a link. 441280b983cSFrederic Barrat * The process is defined by its PASID, pid, tid and its mm_struct. 442280b983cSFrederic Barrat * 443280b983cSFrederic Barrat * 'xsl_err_cb' is an optional callback if the driver wants to be 444280b983cSFrederic Barrat * notified when the translation fault interrupt handler detects an 445280b983cSFrederic Barrat * address error. 446280b983cSFrederic Barrat * 'xsl_err_data' is an argument passed to the above callback, if 447280b983cSFrederic Barrat * defined 448280b983cSFrederic Barrat */ 44953e3e745SAlastair D'Silva int ocxl_link_add_pe(void *link_handle, int pasid, u32 pidr, u32 tidr, 450*d731feeaSChristophe Lombard u64 amr, u16 bdf, struct mm_struct *mm, 451280b983cSFrederic Barrat void (*xsl_err_cb)(void *data, u64 addr, u64 dsisr), 452280b983cSFrederic Barrat void *xsl_err_data); 453280b983cSFrederic Barrat 454280b983cSFrederic Barrat /* 455280b983cSFrederic Barrat * Remove a Process Element from the Shared Process Area for a link 456280b983cSFrederic Barrat */ 45753e3e745SAlastair D'Silva int ocxl_link_remove_pe(void *link_handle, int pasid); 458280b983cSFrederic Barrat 459280b983cSFrederic Barrat /* 460280b983cSFrederic Barrat * Allocate an AFU interrupt associated to the link. 461280b983cSFrederic Barrat * 462280b983cSFrederic Barrat * 'hw_irq' is the hardware interrupt number 463280b983cSFrederic Barrat */ 464dde6f18aSFrederic Barrat int ocxl_link_irq_alloc(void *link_handle, int *hw_irq); 465280b983cSFrederic Barrat 466280b983cSFrederic Barrat /* 467280b983cSFrederic Barrat * Free a previously allocated AFU interrupt 468280b983cSFrederic Barrat */ 46953e3e745SAlastair D'Silva void ocxl_link_free_irq(void *link_handle, int hw_irq); 470280b983cSFrederic Barrat 471280b983cSFrederic Barrat #endif /* _MISC_OCXL_H_ */ 472