Subject: Re: [v6,12/20] cxl: Add guest-specific code

From: Michael Ellerman <[email-masked]>
Date: Wed, 9 Mar 2016 23:42:38 +1100 (AEDT)

On Fri, 2016-04-03 at 11:26:36 UTC, Frederic Barrat wrote:
> From: Christophe Lombard <[email-masked]>
> 
> 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 <[email-masked]>
> Signed-off-by: Frederic Barrat <[email-masked]>
> Signed-off-by: Christophe Lombard <[email-masked]>
> Reviewed-by: Manoj Kumar <[email-masked]>
> Acked-by: Ian Munsie <[email-masked]>
> ---
>  drivers/misc/cxl/Makefile  |   1 +
>  drivers/misc/cxl/api.c     |   2 +-
>  drivers/misc/cxl/context.c |   6 +-
>  drivers/misc/cxl/cxl.h     |  37 +-
>  drivers/misc/cxl/file.c    |   2 +-
>  drivers/misc/cxl/guest.c   | 950 +++++++++++++++++++++++++++++++++++++++++++++
>  drivers/misc/cxl/main.c    |  18 +-
>  drivers/misc/cxl/of.c      | 513 ++++++++++++++++++++++++
>  8 files changed, 1519 insertions(+), 10 deletions(-)
>  create mode 100644 drivers/misc/cxl/guest.c
>  create mode 100644 drivers/misc/cxl/of.c
> 
> diff --git a/drivers/misc/cxl/Makefile b/drivers/misc/cxl/Makefile
> index be2ac5c..a3d4bef 100644
> --- a/drivers/misc/cxl/Makefile
> +++ b/drivers/misc/cxl/Makefile
> @@ -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-y				+= guest.o of.o hcalls.o
>  obj-$(CONFIG_CXL)		+= cxl.o
>  obj-$(CONFIG_CXL_BASE)		+= base.o

This breaks the (newly added[1]) powernv_defconfig. ie. CONFIG_POWERNV=y, CONFIG_PPC_PSERIES=n.

  ERROR: "plpar_hcall" [drivers/misc/cxl/cxl.ko] undefined!
  ERROR: "rtas_call" [drivers/misc/cxl/cxl.ko] undefined!
  ERROR: "rtas_data_buf" [drivers/misc/cxl/cxl.ko] undefined!
  ERROR: "rtas_token" [drivers/misc/cxl/cxl.ko] undefined!
  ERROR: "plpar_hcall9" [drivers/misc/cxl/cxl.ko] undefined!
  ERROR: "rtas_data_buf_lock" [drivers/misc/cxl/cxl.ko] undefined!

Which is a show-stopper.

I've applied the following patch, let me know if there's anything wrong with
it. It would be great if we could do something cleaner.

cheers

diff --git a/drivers/misc/cxl/Makefile b/drivers/misc/cxl/Makefile
index 9ab874f83df0..8a55c1aa11aa 100644
--- a/drivers/misc/cxl/Makefile
+++ b/drivers/misc/cxl/Makefile
@@ -4,7 +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-y				+= flash.o guest.o of.o hcalls.o
+cxl-$(CONFIG_PPC_PSERIES)	+= flash.o guest.o of.o hcalls.o
 obj-$(CONFIG_CXL)		+= cxl.o
 obj-$(CONFIG_CXL_BASE)		+= base.o
 
diff --git a/drivers/misc/cxl/main.c b/drivers/misc/cxl/main.c
index b5eeb71f6a9e..ae68c3201156 100644
--- a/drivers/misc/cxl/main.c
+++ b/drivers/misc/cxl/main.c
@@ -296,10 +296,13 @@ static int __init init_cxl(void)
 	if (cpu_has_feature(CPU_FTR_HVMODE)) {
 		cxl_ops = &cxl_native_ops;
 		rc = pci_register_driver(&cxl_pci_driver);
-	} else {
+	}
+#ifdef CONFIG_PPC_PSERIES
+	else {
 		cxl_ops = &cxl_guest_ops;
 		rc = platform_driver_register(&cxl_of_driver);
 	}
+#endif
 	if (rc)
 		goto err1;
 
@@ -317,8 +320,10 @@ static void exit_cxl(void)
 {
 	if (cpu_has_feature(CPU_FTR_HVMODE))
 		pci_unregister_driver(&cxl_pci_driver);
+#ifdef CONFIG_PPC_PSERIES
 	else
 		platform_driver_unregister(&cxl_of_driver);
+#endif
 
 	cxl_debugfs_exit();
 	cxl_file_exit();