From c64cff5b57fe8521c459eb65dd12e968b8a3b0f2 Mon Sep 17 00:00:00 2001 From: Anirudh Raghavendra Date: Sun, 4 Sep 2022 08:16:38 -0700 Subject: [PATCH] adsprpc: msm: Add rules for compilation Adding rules for compiling frpc_adsprpc ko and cdsploader ko. Change-Id: Ie0d13018fea971ffa20f0183c17a299ca47f29c7 Signed-off-by: Anirudh Raghavendra --- Android.mk | 41 +++++++++++ Kbuild | 39 ++++++++++ Makefile | 14 ++++ config/pineappledsp.conf | 6 ++ config/pineappledspconf.h | 6 ++ dsp/adsprpc.c | 2 +- dsp_kernel_board.mk | 5 ++ dsp_kernel_product.mk | 3 + include/linux/fastrpc.h | 149 ++++++++++++++++++++++++++++++++++++++ product.mk | 2 + 10 files changed, 266 insertions(+), 1 deletion(-) create mode 100644 Android.mk create mode 100644 Kbuild create mode 100644 Makefile create mode 100644 config/pineappledsp.conf create mode 100644 config/pineappledspconf.h create mode 100644 dsp_kernel_board.mk create mode 100644 dsp_kernel_product.mk create mode 100644 include/linux/fastrpc.h create mode 100644 product.mk diff --git a/Android.mk b/Android.mk new file mode 100644 index 0000000000..dfddf359fd --- /dev/null +++ b/Android.mk @@ -0,0 +1,41 @@ +DLKM_DIR := device/qcom/common/dlkm + +LOCAL_PATH := $(call my-dir) + +DSP_BLD_DIR := $(abspath .)/vendor/qcom/opensource/dsp-kernel + +include $(CLEAR_VARS) +$(info DLKM_DIR = $(DLKM_DIR)) +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/**/*) $(wildcard $(LOCAL_PATH)/*) +LOCAL_MODULE := dsp-module-symvers +LOCAL_MODULE_STEM := Module.symvers +LOCAL_MODULE_KBUILD_NAME := Module.symvers +LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT) +include $(DLKM_DIR)/Build_external_kernelmodule.mk + +include $(CLEAR_VARS) +$(info DLKM_DIR = $(DLKM_DIR)) +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/**/*) $(wildcard $(LOCAL_PATH)/*) +LOCAL_MODULE := frpc-adsprpc.ko +LOCAL_EXPORT_KO_INCLUDE_DIRS := $(LOCAL_PATH)/include/linux +LOCAL_MODULE_KBUILD_NAME := frpc-adsprpc.ko +LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT) +KBUILD_OPTIONS += DSP_ROOT=$(DSP_BLD_DIR) +KBUILD_OPTIONS += BOARD_PLATFORM=$(TARGET_BOARD_PLATFORM) +include $(DLKM_DIR)/Build_external_kernelmodule.mk + +#include $(CLEAR_VARS) +#$(info DLKM_DIR = $(DLKM_DIR)) +#LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/**/*) $(wildcard $(LOCAL_PATH)/*) +#LOCAL_MODULE := cdsp-loader.ko +#LOCAL_MODULE_KBUILD_NAME := cdsp-loader.ko +#LOCAL_MODULE_PATH := $(KERNEL_MODULES_OUT) +#KBUILD_OPTIONS += DSP_ROOT=$(DSP_BLD_DIR) +#KBUILD_OPTIONS += BOARD_PLATFORM=$(TARGET_BOARD_PLATFORM) +#include $(DLKM_DIR)/Build_external_kernelmodule.mk + +# print out variables +$(info KBUILD_OPTIONS = $(KBUILD_OPTIONS)) +$(info intermediates dsp symvers path = $(call intermediates-dir-for,DLKM,dsp-module-symvers)) +$(info DLKM_DIR = $(DLKM_DIR)) + diff --git a/Kbuild b/Kbuild new file mode 100644 index 0000000000..868bfd5ede --- /dev/null +++ b/Kbuild @@ -0,0 +1,39 @@ +# ported from Android.mk +$(info within KBUILD file KBUILD_EXTRA_SYMBOLS = $(KBUILD_EXTRA_SYMBOLS)) + +ifeq ($(CONFIG_ARCH_WAIPIO), y) +$(info within KBUILD file CONFIG_ARCH_WAIPIO = $(CONFIG_ARCH_WAIPIO)) +KBUILD_CPPFLAGS += -DCONFIG_DSP_WAIPIO=1 +ccflags-y += -DCONFIG_DSP_WAIPIO=1 +endif + +ifeq ($(CONFIG_ARCH_KALAMA), y) +$(info within KBUILD file CONFIG_ARCH_KALAMA = $(CONFIG_ARCH_KALAMA)) +KBUILD_CPPFLAGS += -DCONFIG_DSP_KALAMA=1 +ccflags-y += -DCONFIG_DSP_KALAMA=1 +endif + +ifeq ($(CONFIG_ARCH_PINEAPPLE), y) +$(info within KBUILD file CONFIG_ARCH_PINEAPPLE = $(CONFIG_ARCH_PINEAPPLE)) +KBUILD_CPPFLAGS += -DCONFIG_DSP_PINEAPPLE=1 +ccflags-y += -DCONFIG_DSP_PINEAPPLE=1 +endif + +LINUXINCLUDE += -I$(DSP_ROOT)/include/linux + +frpc-adsprpc-y := dsp/adsprpc.o \ + dsp/adsprpc_rpmsg.o \ + +frpc-adsprpc-$(CONFIG_COMPAT) += dsp/adsprpc_compat.o \ + +frpc_trusted-adsprpc-y := dsp/adsprpc.o \ + dsp/adsprpc_compat.o \ + dsp/adsprpc_socket.o \ + +#cdsp-loader-y := dsp/cdsp-loader.o + +#obj-m := frpc-adsprpc.o cdsp-loader.o +obj-m := frpc-adsprpc.o + +BOARD_VENDOR_KERNEL_MODULES += $(KERNEL_MODULES_OUT)/frpc-adsprpc.ko +#BOARD_VENDOR_KERNEL_MODULES += $(KERNEL_MODULES_OUT)/cdsp-loader.ko diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..b35c11f27b --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +KBUILD_OPTIONS += DSP_ROOT=$(KERNEL_SRC)/$(M) V=1 + +all: + $(MAKE) -C $(KERNEL_SRC) M=$(M) modules $(KBUILD_OPTIONS) + +modules_install: + $(MAKE) M=$(M) -C $(KERNEL_SRC) modules_install + +%: + $(MAKE) -C $(KERNEL_SRC) M=$(M) $@ $(KBUILD_OPTIONS) + +clean: + rm -f *.o *.ko *.mod.c *.mod.o *~ .*.cmd Module.symvers + rm -rf .tmp_versions diff --git a/config/pineappledsp.conf b/config/pineappledsp.conf new file mode 100644 index 0000000000..9cb6a359e8 --- /dev/null +++ b/config/pineappledsp.conf @@ -0,0 +1,6 @@ +ifeq ($(CONFIG_QGKI),y) +export CONFIG_MSM_ADSPRPC =y +else +export CONFIG_MSM_ADSPRPC =m +endif +#export CONFIG_MSM_DSP=y \ No newline at end of file diff --git a/config/pineappledspconf.h b/config/pineappledspconf.h new file mode 100644 index 0000000000..5bcc9fd1db --- /dev/null +++ b/config/pineappledspconf.h @@ -0,0 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2020, The Linux Foundation. All rights reserved. + */ + +#define CONFIG_MSM_ADSPRPC 1 diff --git a/dsp/adsprpc.c b/dsp/adsprpc.c index 7471e4e2ce..8b4d70fefa 100644 --- a/dsp/adsprpc.c +++ b/dsp/adsprpc.c @@ -41,7 +41,7 @@ #include #include "adsprpc_compat.h" #include "adsprpc_shared.h" -#include +#include "fastrpc.h" #include #include #include diff --git a/dsp_kernel_board.mk b/dsp_kernel_board.mk new file mode 100644 index 0000000000..d5d3dc0d14 --- /dev/null +++ b/dsp_kernel_board.mk @@ -0,0 +1,5 @@ +ifeq ($(call is-board-platform-in-list,$(TARGET_BOARD_PLATFORM)),true) +BOARD_VENDOR_KERNEL_MODULES += $(KERNEL_MODULES_OUT)/frpc-adsprpc.ko +#BOARD_VENDOR_KERNEL_MODULES += $(KERNEL_MODULES_OUT)/frpc-trusted-adsprpc.ko +#BOARD_VENDOR_KERNEL_MODULES += $(KERNEL_MODULES_OUT)/cdsp-loader.ko +endif diff --git a/dsp_kernel_product.mk b/dsp_kernel_product.mk new file mode 100644 index 0000000000..0f18b541d9 --- /dev/null +++ b/dsp_kernel_product.mk @@ -0,0 +1,3 @@ +PRODUCT_PACKAGES += frpc-adsprpc.ko +#PRODUCT_PACKAGES += frpc_trusted-adsprpc.ko +#PRODUCT_PACKAGES += cdsp-loader.ko diff --git a/include/linux/fastrpc.h b/include/linux/fastrpc.h new file mode 100644 index 0000000000..b828d9d8a7 --- /dev/null +++ b/include/linux/fastrpc.h @@ -0,0 +1,149 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2021, The Linux Foundation. All rights reserved. + */ + +#ifndef __LINUX_fastrpc_H +#define __LINUX_fastrpc_H + +#include +#include +#include + +#define FASTRPC_DRV_NAME_SIZE 32 + +enum fastrpc_driver_status { + FASTRPC_PROC_DOWN = 0, +}; +enum fastrpc_driver_invoke_nums { + FASTRPC_DEV_MAP_DMA = 1, + FASTRPC_DEV_UNMAP_DMA, +}; + +/** + * struct fastrpc_dev_map_dma - fastrpc dma buffer map structure + * @buf : Shared DMA buf object + * @attrs : Attributes to map buffer on IOMMU + * @size : Size of DMA buffer + * @v_dsp_addr : Virtual addr of DSP after mapping the buffer on DSP + */ +struct fastrpc_dev_map_dma { + struct dma_buf *buf; + uint32_t attrs; + size_t size; + uint64_t v_dsp_addr; +}; + +/** + * struct fastrpc_dev_unmap_dma - fastrpc dma buffer unmap structure + * @buf : Shared DMA buf object + * @size : Size of DMA buffer + */ +struct fastrpc_dev_unmap_dma { + struct dma_buf *buf; + size_t size; +}; + +/** + * fastrpc_device - device that belong to the fastrpc bus + * @hn: Head node to add to fastrpc device list + * @dev: the device struct + * @handle: handle of the process + * @fl: process file of fastrpc device + * @dev_close: flag to determine if device is closed + * @refs: reference count of drivers using the device + */ +struct fastrpc_device { + struct hlist_node hn; + struct device dev; + int handle; + struct fastrpc_file *fl; + bool dev_close; + unsigned int refs; +}; + +#define to_fastrpc_device(d) container_of(d, struct fastrpc_device, dev) + +/** + * struct fastrpc_driver - fastrpc driver struct + * @hn: Node to add to fastrpc driver list + * @driver: underlying device driver + * @device: device that is matching to driver + * @handle: handle of the process + * @create: 0 to attach, 1 to create process + * @probe: invoked when a matching fastrpc device (i.e. device) is found + * @callback: invoked when there is a status change in the process + */ +struct fastrpc_driver { + struct hlist_node hn; + struct device_driver driver; + struct device *device; + int handle; + int create; + int (*probe)(struct fastrpc_device *dev); + int (*callback)(struct fastrpc_device *dev, + enum fastrpc_driver_status status); +}; + +#define to_fastrpc_driver(x) container_of((x), struct fastrpc_driver, driver) + +//#if IS_ENABLED(CONFIG_MSM_ADSPRPC) || IS_ENABLED(CONFIG_MSM_ADSPRPC_TRUSTED) +/** + * function fastrpc_driver_register - Register fastrpc driver + * @drv: Initialized fastrpc driver structure pointer + */ +int fastrpc_driver_register(struct fastrpc_driver *drv); + +/** + * function fastrpc_driver_unregister - Un-register fastrpc driver + * @drv: fastrpc driver structure pointer + */ +void fastrpc_driver_unregister(struct fastrpc_driver *drv); + +/** + * function fastrpc_driver_invoke - fastrpc driver invocation function + * Invoke fastrpc driver using fastrpc_device received in probe of registration + * @dev : Device received in probe of registration. + * @invoke_num : Invocation number of operation, + * one of "fastrpc_driver_invoke_nums" + * @invoke_param: Address of invocation structure corresponding to invoke_num + * (struct fastrpc_dev_map_dma *) for FASTRPC_DEV_MAP_DMA + * (struct fastrpc_dev_unmap_dma *) for FASTRPC_DEV_UNMAP_DMA. + */ +long fastrpc_driver_invoke(struct fastrpc_device *dev, + enum fastrpc_driver_invoke_nums invoke_num, unsigned long invoke_param); + +/* +#else +static inline int fastrpc_driver_register(struct fastrpc_driver *drv) +{ return 0; } + +static inline void fastrpc_driver_unregister(struct fastrpc_driver *drv) +{ return; } + +static inline long fastrpc_driver_invoke(struct fastrpc_device *dev, + enum fastrpc_driver_invoke_nums invoke_num, unsigned long invoke_param) +{ return 0; } +#endif +*/ +/** + * module_fastrpc_driver() - Helper macro for registering a fastrpc driver + * @__fastrpc_driver: fastrpc_driver struct + * + * Helper macro for fastrpc drivers which do not do anything special in module + * init/exit. This eliminates a lot of boilerplate code. Each module may only + * use this macro once, and calling it replaces module_init and module_exit. + */ +#define module_fastrpc_driver(__fastrpc_driver) \ +static int __init __fastrpc_driver##_init(void) \ +{ \ + return fastrpc_driver_register(&(__fastrpc_driver)); \ +} \ +module_init(__fastrpc_driver##_init); \ +static void __exit __fastrpc_driver##_exit(void) \ +{ \ + fastrpc_driver_unregister(&(__fastrpc_driver)); \ +} \ +module_exit(__fastrpc_driver##_exit) + +#endif /* __LINUX_fastrpc_H */ diff --git a/product.mk b/product.mk new file mode 100644 index 0000000000..34d12e010c --- /dev/null +++ b/product.mk @@ -0,0 +1,2 @@ +PRODUCT_PACKAGES += frpc-adsprpc.ko +#PRODUCT_PACKAGES += cdsp-loader.ko