Skip to content

Commit

Permalink
cxl: Add guest-specific code
Browse files Browse the repository at this point in the history
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: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: Frederic Barrat <fbarrat@linux.vnet.ibm.com>
Signed-off-by: Christophe Lombard <clombard@linux.vnet.ibm.com>
Reviewed-by: Manoj Kumar <manoj@linux.vnet.ibm.com>
Acked-by: Ian Munsie <imunsie@au1.ibm.com>
[mpe: Fix SMP=n build, fix PSERIES=n build, minor whitespace fixes]
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
  • Loading branch information
2 people authored and Michael Ellerman committed Mar 9, 2016
1 parent cbffa3a commit 14baf4d
Show file tree
Hide file tree
Showing 10 changed files with 1,525 additions and 11 deletions.
1 change: 1 addition & 0 deletions drivers/misc/cxl/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ ccflags-$(CONFIG_PPC_WERROR) += -Werror
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 += vphb.o api.o
cxl-$(CONFIG_PPC_PSERIES) += guest.o of.o hcalls.o
obj-$(CONFIG_CXL) += cxl.o
obj-$(CONFIG_CXL_BASE) += base.o

Expand Down
2 changes: 1 addition & 1 deletion drivers/misc/cxl/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ EXPORT_SYMBOL_GPL(cxl_start_context);

int cxl_process_element(struct cxl_context *ctx)
{
return ctx->pe;
return ctx->external_pe;
}
EXPORT_SYMBOL_GPL(cxl_process_element);

Expand Down
6 changes: 5 additions & 1 deletion drivers/misc/cxl/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,12 @@ int cxl_context_init(struct cxl_context *ctx, struct cxl_afu *afu, bool master,
return 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->external_pe = ctx->pe;
} else {
ctx->external_pe = -1; /* assigned when attaching */
}
ctx->pe_inserted = false;

/*
Expand Down
37 changes: 36 additions & 1 deletion drivers/misc/cxl/cxl.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ struct cxl_irq_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
* of these per AFU. If in AFU directed there can be lots of these.
Expand Down Expand Up @@ -488,7 +494,19 @@ struct cxl_context {

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;
bool pe_inserted;
bool master;
Expand Down Expand Up @@ -782,6 +800,7 @@ void cxl_pci_vphb_reconfigure(struct cxl_afu *afu);
void cxl_pci_vphb_remove(struct cxl_afu *afu);

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_open(struct inode *inode, struct file *file);
Expand All @@ -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);
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 module *module;
int (*adapter_reset)(struct cxl *adapter);
Expand Down Expand Up @@ -824,6 +858,7 @@ struct cxl_backend_ops {
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_guest_ops;
extern const struct cxl_backend_ops *cxl_ops;

#endif
2 changes: 1 addition & 1 deletion drivers/misc/cxl/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ static long afu_ioctl_process_element(struct cxl_context *ctx,
{
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 0;
Expand Down
Loading

0 comments on commit 14baf4d

Please sign in to comment.