0x000000000000c000 0x000000000000c03f 0x0000000000040101
0x00000000febd1000 0x00000000febd1fff 0x0000000000040200
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000380000004000 0x0000380000007fff 0x000000000014220c
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x00000000feb80000 0x00000000febbffff 0x0000000000046200
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
0x0000000000000000 0x0000000000000000 0x0000000000000000
  *   !ˆl–Ü4ý( ©³( 	Å€fàB¦-ÿÇƒ}×_†I|¥�+ÅÊ &!    !/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
 * Copyright 2015 IBM Corp.
 */

#ifndef _MISC_CXL_H
#define _MISC_CXL_H

#include <linux/pci.h>
#include <linux/poll.h>
#include <linux/interrupt.h>
#include <uapi/misc/cxl.h>

/*
 * This documents the in kernel API for driver to use CXL. It allows kernel
 * drivers to bind to AFUs using an AFU configuration record exposed as a PCI
 * configuration record.
 *
 * This API enables control over AFU and contexts which can't be part of the
 * generic PCI API. This API is agnostic to the actual AFU.
 */

/* Get the AFU associated with a pci_dev */
struct cxl_afu *cxl_pci_to_afu(struct pci_dev *dev);

/* Get the AFU conf record number associated with a pci_dev */
unsigned int cxl_pci_to_cfg_record(struct pci_dev *dev);


/*
 * Context lifetime overview:
 *
 * An AFU context may be inited and then started and stoppped multiple times
 * before it's released. ie.
 *    - cxl_dev_context_init()
 *      - cxl_start_context()
 *      - cxl_stop_context()
 *      - cxl_start_context()
 *      - cxl_stop_context()
 *     ...repeat...
 *    - cxl_release_context()
 * Once released, a context can't be started again.
 *
 * One context is inited by the cxl driver for every pci_dev. This is to be
 * used as a default kernel context. cxl_get_context() will get this
 * context. This context will be released by PCI hot unplug, so doesn't need to
 * be released explicitly by drivers.
 *
 * Additional kernel contexts may be inited using cxl_dev_context_init().
 * These must be released using cxl_context_detach().
 *
 * Once a context has been inited, IRQs may be configured. Firstly these IRQs
 * must be allocated (cxl_allocate_afu_irqs()), then individually mapped to
 * specific handlers (cxl_map_afu_irq()).
 *
 * These IRQs can be unmapped (cxl_unmap_afu_irq()) and finally released
 * (cxl_free_afu_irqs()).
 *
 * The AFU can be reset (cxl_afu_reset()). This will cause the PSL/AFU
 * hardware to lose track of all contexts. It's upto the caller of
 * cxl_afu_reset() to restart these contexts.
 */

/*
 * On pci_enabled_device(), the cxl driver will init a single cxl context for
 * use by the driver. It doesn't start this context (as that will likely
 * generate DMA traffic for most AFUs).
 *
 * This gets the default context associated with this pci_dev.  This context
 * doesn't need to be released as this will be done by the PCI subsystem on hot
 * unplug.
 */
struct cxl_context *cxl_get_context(struct pci_dev *dev);
/*
 * Allocate and initalise a context associated with a AFU PCI device. This
 * doesn't start the context in the AFU.
 */
struct cxl_context *cxl_dev_context_init(struct pci_dev *dev);
/*
 * Release and free a context. Context should be stopped before calling.
 */
int cxl_release_context(struct cxl_context *ctx);

/*
 * Set and get private data associated with a context. Allows drivers to have a
 * back pointer to some useful structure.
 */
int cxl_set_priv(struct cxl_context *ctx, void *priv);
void *cxl_get_priv(struct cxl_context *ctx);

/*
 * Allocate AFU interrupts for this context. num=0 will allocate the default
 * for this AFU as given in the AFU descriptor. This number doesn't include the
 * interrupt 0 (CAIA defines AFU IRQ 0 for page faults). Each interrupt to be
 * used must map a handl