Commit 14baf4d9 authored by Christophe Lombard's avatar Christophe Lombard Committed by Michael Ellerman

cxl: Add guest-specific code

The new of.c file contains code to parse the device tree to find out
about cxl adapters and AFUs.

guest.c implements the guest-specific callbacks for the backend API.

The process element ID is not known until the context is attached, so
we have to separate the context ID assigned by the cxl driver from the
process element ID visible to the user applications. In bare-metal,
the 2 IDs match.
Co-authored-by: default avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: default avatarFrederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: default avatarChristophe Lombard <clombard@linux.vnet.ibm.com>
Reviewed-by: default avatarManoj Kumar <manoj@linux.vnet.ibm.com>
Acked-by: default avatarIan Munsie <imunsie@au1.ibm.com>
[mpe: Fix SMP=n build, fix PSERIES=n build, minor whitespace fixes]
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent cbffa3a5
...@@ -4,6 +4,7 @@ ccflags-$(CONFIG_PPC_WERROR) += -Werror ...@@ -4,6 +4,7 @@ ccflags-$(CONFIG_PPC_WERROR) += -Werror
cxl-y += main.o file.o irq.o fault.o native.o cxl-y += main.o file.o irq.o fault.o native.o
cxl-y += context.o sysfs.o debugfs.o pci.o trace.o cxl-y += context.o sysfs.o debugfs.o pci.o trace.o
cxl-y += vphb.o api.o cxl-y += vphb.o api.o
cxl-$(CONFIG_PPC_PSERIES) += guest.o of.o hcalls.o
obj-$(CONFIG_CXL) += cxl.o obj-$(CONFIG_CXL) += cxl.o
obj-$(CONFIG_CXL_BASE) += base.o obj-$(CONFIG_CXL_BASE) += base.o
......
...@@ -191,7 +191,7 @@ EXPORT_SYMBOL_GPL(cxl_start_context); ...@@ -191,7 +191,7 @@ EXPORT_SYMBOL_GPL(cxl_start_context);
int cxl_process_element(struct cxl_context *ctx) int cxl_process_element(struct cxl_context *ctx)
{ {
return ctx->pe; return ctx->external_pe;
} }
EXPORT_SYMBOL_GPL(cxl_process_element); EXPORT_SYMBOL_GPL(cxl_process_element);
......
...@@ -95,8 +95,12 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master, ...@@ -95,8 +95,12 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,
return i; return i;
ctx->pe = i; ctx->pe = i;
if (cpu_has_feature(CPU_FTR_HVMODE)) if (cpu_has_feature(CPU_FTR_HVMODE)) {
ctx->elem = &ctx->afu->native->spa[i]; ctx->elem = &ctx->afu->native->spa[i];
ctx->external_pe = ctx->pe;
} else {
ctx->external_pe = -1; /* assigned when attaching */
}
ctx->pe_inserted = false; ctx->pe_inserted = false;
/* /*
......
...@@ -433,6 +433,12 @@ struct cxl_irq_name { ...@@ -433,6 +433,12 @@ struct cxl_irq_name {
char *name; char *name;
}; };
struct irq_avail {
irq_hw_number_t offset;
irq_hw_number_t range;
unsigned long *bitmap;
};
/* /*
* This is a cxl context. If the PSL is in dedicated mode, there will be one * This is a cxl context. If the PSL is in dedicated mode, there will be one
* of these per AFU. If in AFU directed there can be lots of these. * of these per AFU. If in AFU directed there can be lots of these.
...@@ -488,7 +494,19 @@ struct cxl_context { ...@@ -488,7 +494,19 @@ struct cxl_context {
struct cxl_process_element *elem; struct cxl_process_element *elem;
int pe; /* process element handle */ /*
* pe is the process element handle, assigned by this driver when the
* context is initialized.
*
* external_pe is the PE shown outside of cxl.
* On bare-metal, pe=external_pe, because we decide what the handle is.
* In a guest, we only find out about the pe used by pHyp when the
* context is attached, and that's the value we want to report outside
* of cxl.
*/
int pe;
int external_pe;
u32 irq_count; u32 irq_count;
bool pe_inserted; bool pe_inserted;
bool master; bool master;
...@@ -782,6 +800,7 @@ void cxl_pci_vphb_reconfigure(struct cxl_afu *afu); ...@@ -782,6 +800,7 @@ void cxl_pci_vphb_reconfigure(struct cxl_afu *afu);
void cxl_pci_vphb_remove(struct cxl_afu *afu); void cxl_pci_vphb_remove(struct cxl_afu *afu);
extern struct pci_driver cxl_pci_driver; extern struct pci_driver cxl_pci_driver;
extern struct platform_driver cxl_of_driver;
int afu_allocate_irqs(struct cxl_context *ctx, u32 count); int afu_allocate_irqs(struct cxl_context *ctx, u32 count);
int afu_open(struct inode *inode, struct file *file); int afu_open(struct inode *inode, struct file *file);
...@@ -792,6 +811,21 @@ unsigned int afu_poll(struct file *file, struct poll_table_struct *poll); ...@@ -792,6 +811,21 @@ unsigned int afu_poll(struct file *file, struct poll_table_struct *poll);
ssize_t afu_read(struct file *file, char __user *buf, size_t count, loff_t *off); ssize_t afu_read(struct file *file, char __user *buf, size_t count, loff_t *off);
extern const struct file_operations afu_fops; extern const struct file_operations afu_fops;
struct cxl *cxl_guest_init_adapter(struct device_node *np, struct platform_device *dev);
void cxl_guest_remove_adapter(struct cxl *adapter);
int cxl_of_read_adapter_handle(struct cxl *adapter, struct device_node *np);
int cxl_of_read_adapter_properties(struct cxl *adapter, struct device_node *np);
ssize_t cxl_guest_read_adapter_vpd(struct cxl *adapter, void *buf, size_t len);
ssize_t cxl_guest_read_afu_vpd(struct cxl_afu *afu, void *buf, size_t len);
int cxl_guest_init_afu(struct cxl *adapter, int slice, struct device_node *afu_np);
void cxl_guest_remove_afu(struct cxl_afu *afu);
int cxl_of_read_afu_handle(struct cxl_afu *afu, struct device_node *afu_np);
int cxl_of_read_afu_properties(struct cxl_afu *afu, struct device_node *afu_np);
int cxl_guest_add_chardev(struct cxl *adapter);
void cxl_guest_remove_chardev(struct cxl *adapter);
void cxl_guest_reload_module(struct cxl *adapter);
int cxl_of_probe(struct platform_device *pdev);
struct cxl_backend_ops { struct cxl_backend_ops {
struct module *module; struct module *module;
int (*adapter_reset)(struct cxl *adapter); int (*adapter_reset)(struct cxl *adapter);
...@@ -824,6 +858,7 @@ struct cxl_backend_ops { ...@@ -824,6 +858,7 @@ struct cxl_backend_ops {
int (*afu_cr_read64)(struct cxl_afu *afu, int cr_idx, u64 offset, u64 *val); int (*afu_cr_read64)(struct cxl_afu *afu, int cr_idx, u64 offset, u64 *val);
}; };
extern const struct cxl_backend_ops cxl_native_ops; extern const struct cxl_backend_ops cxl_native_ops;
extern const struct cxl_backend_ops cxl_guest_ops;
extern const struct cxl_backend_ops *cxl_ops; extern const struct cxl_backend_ops *cxl_ops;
#endif #endif
...@@ -228,7 +228,7 @@ static long afu_ioctl_process_element(struct cxl_context *ctx, ...@@ -228,7 +228,7 @@ static long afu_ioctl_process_element(struct cxl_context *ctx,
{ {
pr_devel("%s: pe: %i\n", __func__, ctx->pe); pr_devel("%s: pe: %i\n", __func__, ctx->pe);
if (copy_to_user(upe, &ctx->pe, sizeof(__u32))) if (copy_to_user(upe, &ctx->external_pe, sizeof(__u32)))
return -EFAULT; return -EFAULT;
return 0; return 0;
......
This diff is collapsed.
...@@ -11,7 +11,6 @@ ...@@ -11,7 +11,6 @@
#include <linux/compiler.h> #include <linux/compiler.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <asm/hvcall.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include "hcalls.h" #include "hcalls.h"
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <asm/byteorder.h> #include <asm/byteorder.h>
#include <asm/hvcall.h>
#include "cxl.h" #include "cxl.h"
#define SG_BUFFER_SIZE 4096 #define SG_BUFFER_SIZE 4096
......
...@@ -285,9 +285,6 @@ static int __init init_cxl(void) ...@@ -285,9 +285,6 @@ static int __init init_cxl(void)
{ {
int rc = 0; int rc = 0;
if (!cpu_has_feature(CPU_FTR_HVMODE))
return -EPERM;
if ((rc = cxl_file_init())) if ((rc = cxl_file_init()))
return rc; return rc;
...@@ -296,8 +293,17 @@ static int __init init_cxl(void) ...@@ -296,8 +293,17 @@ static int __init init_cxl(void)
if ((rc = register_cxl_calls(&cxl_calls))) if ((rc = register_cxl_calls(&cxl_calls)))
goto err; goto err;
if (cpu_has_feature(CPU_FTR_HVMODE)) {
cxl_ops = &cxl_native_ops; cxl_ops = &cxl_native_ops;
if ((rc = pci_register_driver(&cxl_pci_driver))) rc = pci_register_driver(&cxl_pci_driver);
}
#ifdef CONFIG_PPC_PSERIES
else {
cxl_ops = &cxl_guest_ops;
rc = platform_driver_register(&cxl_of_driver);
}
#endif
if (rc)
goto err1; goto err1;
return 0; return 0;
...@@ -312,7 +318,12 @@ static int __init init_cxl(void) ...@@ -312,7 +318,12 @@ static int __init init_cxl(void)
static void exit_cxl(void) static void exit_cxl(void)
{ {
if (cpu_has_feature(CPU_FTR_HVMODE))
pci_unregister_driver(&cxl_pci_driver); pci_unregister_driver(&cxl_pci_driver);
#ifdef CONFIG_PPC_PSERIES
else
platform_driver_unregister(&cxl_of_driver);
#endif
cxl_debugfs_exit(); cxl_debugfs_exit();
cxl_file_exit(); cxl_file_exit();
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment