Browse Source

bt-kernel: Additional bazel configuration

- add support to copy *.ko to out dir
- enable conditional compilation with config flags
- enable CONFIG_BT_HW_SECURE_DISABLE with dependency on securemsm-kernel
- re-enable compilation of bt_fm_slim with new headers
- add fallthrough attribute btfm_slim_hw_interface.c
- move BTFMSLIM_DEV_NAME to btfm_slim.h
- add target.bzl file to define specific targets

Change-Id: I7f7920870d81125f95b020ef33df77df3f937682
Signed-off-by: Franklin Abreu Bueno <[email protected]>
Franklin Abreu Bueno 2 years ago
parent
commit
176b51aefa
8 changed files with 139 additions and 33 deletions
  1. 11 3
      BUILD.bazel
  2. 50 16
      bt_kernel.bzl
  3. 51 7
      bt_modules.bzl
  4. 2 0
      slimbus/btfm_slim.c
  5. 5 1
      slimbus/btfm_slim.h
  6. 1 0
      slimbus/btfm_slim_hw_interface.c
  7. 0 6
      slimbus/btfm_slim_hw_interface.h
  8. 19 0
      target.bzl

+ 11 - 3
BUILD.bazel

@@ -1,5 +1,13 @@
-load(":bt_kernel.bzl", "define_bt_modules")
+load("//build/kernel/kleaf:kernel.bzl", "ddk_headers")
 
 
-targets = ["pineapple"]
+ddk_headers(
+    name = "btfmcodec_headers",
+    hdrs = glob([
+        "btfmcodec/include/*.h"
+    ]),
+    includes = ["btfmcodec/include"]
+)
 
 
-define_bt_modules(targets)
+load(":target.bzl", "define_pineapple")
+
+define_pineapple()

+ 50 - 16
bt_kernel.bzl

@@ -1,24 +1,34 @@
 load("//msm-kernel:target_variants.bzl", "get_all_variants")
 load("//msm-kernel:target_variants.bzl", "get_all_variants")
 load("//build/kernel/kleaf:kernel.bzl", "ddk_module")
 load("//build/kernel/kleaf:kernel.bzl", "ddk_module")
-
+load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
 load(":bt_modules.bzl", "bt_modules")
 load(":bt_modules.bzl", "bt_modules")
 
 
-def _get_module_srcs(module):
+def _get_config_choices(config_srcs, options):
+    choices = []
+
+    for option in config_srcs:
+        choices.extend(config_srcs[option].get(option in options, []))
+
+    return choices
+
+def _get_module_srcs(module, options):
     """
     """
     Gets all the module sources, formats them with the path for that module
     Gets all the module sources, formats them with the path for that module
     and then groups them together
     and then groups them together
     It also includes all the headers within the `include` directory
     It also includes all the headers within the `include` directory
     `native.glob()` returns a new list with every file need for the current package
     `native.glob()` returns a new list with every file need for the current package
     """
     """
+    srcs = module.srcs + _get_config_choices(module.config_srcs, options)
     return native.glob(
     return native.glob(
-        ["{}/{}".format(module.path, src) for src in module.srcs] + ["include/*.h"]
+        ["{}/{}".format(module.path, src) for src in srcs] + ["include/*.h"]
     )
     )
 
 
-def _get_module_deps(module, formatter):
+def _get_module_deps(module, options, formatter):
     """
     """
     Formats the dependent targets with the necessary prefix
     Formats the dependent targets with the necessary prefix
     Args:
     Args:
         module: kernel module
         module: kernel module
+        options: dependencies that rely on a config option
         formatter: function that will replace the format string within `deps`
         formatter: function that will replace the format string within `deps`
     Example:
     Example:
         kernel build = "pineapple_gki"
         kernel build = "pineapple_gki"
@@ -26,36 +36,60 @@ def _get_module_deps(module, formatter):
         The formatted string will look as follow
         The formatted string will look as follow
         formatted_dep = formatter(dep) = "pineapple_gki_btpower"
         formatted_dep = formatter(dep) = "pineapple_gki_btpower"
     """
     """
-    return [formatter(dep) for dep in module.deps]
+    deps = module.deps + _get_config_choices(module.config_deps, options)
+    return [formatter(dep) for dep in deps]
+
+def _get_build_options(modules, config_options):
+    all_options = {option: True for option in config_options}
+    all_options = all_options | {module.config_opt: True for module in modules if module.config_opt}
 
 
-def define_target_variant_modules(target, variant, modules):
+    return all_options
+
+def define_target_variant_modules(target, variant, modules, config_options = []):
     """
     """
     Generates the ddk_module for each of our kernel modules
     Generates the ddk_module for each of our kernel modules
     Args:
     Args:
         target: either `pineapple` or `kalama`
         target: either `pineapple` or `kalama`
         variant: either `gki` or `consolidate`
         variant: either `gki` or `consolidate`
-        modules: bt_modules dict defined in `bt_modules.bzl`
+        modules: bt_modules dictionary defined in `bt_modules.bzl`
+        config_options: decides which kernel modules to build
     """
     """
     kernel_build = "{}_{}".format(target, variant)
     kernel_build = "{}_{}".format(target, variant)
-    modules = [modules.get(module_name) for module_name in modules]
+    kernel_build_label = "//msm-kernel:{}".format(kernel_build)
+    modules = [bt_modules.get(module_name) for module_name in modules]
+    options = _get_build_options(modules, config_options)
     formatter = lambda s : s.replace("%b", kernel_build)
     formatter = lambda s : s.replace("%b", kernel_build)
 
 
+    all_modules = []
     for module in modules:
     for module in modules:
         rule_name = "{}_{}".format(kernel_build, module.name)
         rule_name = "{}_{}".format(kernel_build, module.name)
-        module_srcs = _get_module_srcs(module)
+        module_srcs = _get_module_srcs(module, options)
 
 
         ddk_module(
         ddk_module(
             name = rule_name,
             name = rule_name,
-            kernel_build = "//msm-kernel:{}".format(kernel_build),
+            kernel_build = kernel_build_label,
             srcs = module_srcs,
             srcs = module_srcs,
             out = "{}.ko".format(module.name),
             out = "{}.ko".format(module.name),
-            deps = ["//msm-kernel:all_headers"] + _get_module_deps(module, formatter),
+            deps = ["//msm-kernel:all_headers"] + _get_module_deps(module, options, formatter),
             includes = ["include"],
             includes = ["include"],
+            local_defines = options.keys(),
             visibility = ["//visibility:public"],
             visibility = ["//visibility:public"],
         )
         )
 
 
-def define_bt_modules(targets):
-    for target in targets:
-        for (t, v) in get_all_variants():
-            if t == target:
-                define_target_variant_modules(t, v, bt_modules)
+        all_modules.append(rule_name)
+
+    copy_to_dist_dir(
+        name = "{}_bt-kernel_dist".format(kernel_build),
+        data = all_modules,
+        dist_dir = "out/target/product/{}/dlkm/lib/modules".format(target),
+        flat = True,
+        wipe_dist_dir = False,
+        allow_duplicate_filenames = False,
+        mode_overrides = {"**/*": "644"},
+        log = "info",
+    )
+
+def define_bt_modules(target, modules, config_options = []):
+    for (t, v) in get_all_variants():
+        if t == target:
+            define_target_variant_modules(t, v, modules, config_options)

+ 51 - 7
bt_modules.bzl

@@ -5,7 +5,7 @@ FMRTC_PATH = "rtc6226"
 # This dictionary holds all the BT modules included in the bt-kernel
 # This dictionary holds all the BT modules included in the bt-kernel
 bt_modules = {}
 bt_modules = {}
 
 
-def register_bt_modules(name, path = None, config_opt = None, srcs = {}, deps = []):
+def register_bt_modules(name, path = None, config_opt = None, srcs = [], config_srcs = {}, deps = [], config_deps = {}):
     """
     """
     Register modules
     Register modules
     Args:
     Args:
@@ -13,14 +13,37 @@ def register_bt_modules(name, path = None, config_opt = None, srcs = {}, deps =
         path: Path in which the source files can be found
         path: Path in which the source files can be found
         config_opt: Config name used in Kconfig (not needed currently)
         config_opt: Config name used in Kconfig (not needed currently)
         srcs: source files and local headers
         srcs: source files and local headers
+        config_srcs: source files and local headers that depend on a config define being enabled.
         deps: a list of dependent targets
         deps: a list of dependent targets
+        config_deps: a list of dependent targets that depend on a config define being enabled.
     """
     """
+    processed_config_srcs = {}
+    processed_config_deps = {}
+
+    for config_src_name in config_srcs:
+        config_src = config_srcs[config_src_name]
+
+        if type(config_src) == "list":
+            processed_config_srcs[config_src_name] = {True: config_src}
+        else:
+            processed_config_srcs[config_src_name] = config_src
+
+    for config_deps_name in config_deps:
+        config_dep = config_deps[config_deps_name]
+
+        if type(config_dep) == "list":
+            processed_config_deps[config_deps_name] = {True: config_dep}
+        else:
+            processed_config_deps[config_deps_name] = config_dep
+
     module = struct(
     module = struct(
         name = name,
         name = name,
         path = path,
         path = path,
         srcs = srcs,
         srcs = srcs,
+        config_srcs = processed_config_srcs,
         config_opt = config_opt,
         config_opt = config_opt,
-        deps =  deps
+        deps = deps,
+        config_deps = processed_config_deps,
     )
     )
     bt_modules[name] = module
     bt_modules[name] = module
 
 
@@ -29,22 +52,43 @@ def register_bt_modules(name, path = None, config_opt = None, srcs = {}, deps =
 register_bt_modules(
 register_bt_modules(
     name = "btpower",
     name = "btpower",
     path = PWR_PATH,
     path = PWR_PATH,
-    config_opt = "CONFIG_MSM_BT_PWR",
-    srcs = ["btpower.c"]
+    config_opt = "CONFIG_MSM_BT_POWER",
+    srcs = ["btpower.c"],
+    config_deps = {
+        "CONFIG_BT_HW_SECURE_DISABLE": [
+            "//vendor/qcom/opensource/securemsm-kernel:%b_smcinvoke_dlkm",
+        ]
+    },
 )
 )
 
 
 register_bt_modules(
 register_bt_modules(
     name = "bt_fm_slim",
     name = "bt_fm_slim",
     path = SLIMBUS_PATH,
     path = SLIMBUS_PATH,
-    config_opt = "CONFIG_BTFM_SLIM",
+    # config_opt = "CONFIG_BTFM_SLIM",
     srcs = [
     srcs = [
         "btfm_slim.c",
         "btfm_slim.c",
         "btfm_slim.h",
         "btfm_slim.h",
+        "btfm_slim_slave.c",
+        "btfm_slim_slave.h",
         "btfm_slim_codec.c",
         "btfm_slim_codec.c",
+    ],
+    deps = [":%b_btpower"],
+)
+
+# Not enabled/compiling until btfmcodec is enabled
+register_bt_modules(
+    name = "btfm_slim_codec",
+    path = SLIMBUS_PATH,
+    # config_opt = "CONFIG_SLIM_BTFM_CODEC",
+    srcs = [
+        "btfm_slim.c",
+        "btfm_slim.h",
         "btfm_slim_slave.c",
         "btfm_slim_slave.c",
         "btfm_slim_slave.h",
         "btfm_slim_slave.h",
+        "btfm_slim_hw_interface.c",
+        "btfm_slim_hw_interface.h",
     ],
     ],
-    deps = [":%b_btpower"]
+    deps = [":%b_btpower", ":btfmcodec_headers"],
 )
 )
 
 
 register_bt_modules(
 register_bt_modules(
@@ -55,5 +99,5 @@ register_bt_modules(
         "radio-rtc6226-common.c",
         "radio-rtc6226-common.c",
         "radio-rtc6226-i2c.c",
         "radio-rtc6226-i2c.c",
         "radio-rtc6226.h",
         "radio-rtc6226.h",
-    ]
+    ],
 )
 )

+ 2 - 0
slimbus/btfm_slim.c

@@ -22,7 +22,9 @@
 #include "btpower.h"
 #include "btpower.h"
 #include "btfm_slim.h"
 #include "btfm_slim.h"
 #include "btfm_slim_slave.h"
 #include "btfm_slim_slave.h"
+#if IS_ENABLED(CONFIG_SLIM_BTFM_CODEC)
 #include "btfm_slim_hw_interface.h"
 #include "btfm_slim_hw_interface.h"
+#endif
 
 
 #define DELAY_FOR_PORT_OPEN_MS (200)
 #define DELAY_FOR_PORT_OPEN_MS (200)
 #define SLIM_MANF_ID_QCOM	0x217
 #define SLIM_MANF_ID_QCOM	0x217

+ 5 - 1
slimbus/btfm_slim.h

@@ -29,7 +29,11 @@
 #define PGD	1
 #define PGD	1
 #define IFD	0
 #define IFD	0
 
 
-
+#if IS_ENABLED(CONFIG_BTFM_SLIM)
+#define BTFMSLIM_DEV_NAME "btfmslim_slave"
+#else
+#define BTFMSLIM_DEV_NAME "btfmslim"
+#endif
 
 
 /* Codec driver defines */
 /* Codec driver defines */
 enum {
 enum {

+ 1 - 0
slimbus/btfm_slim_hw_interface.c

@@ -329,6 +329,7 @@ static int btfm_slim_dai_get_channel_map(void *dai,
 	switch (id) {
 	switch (id) {
 	case BTFM_FM_SLIM_TX:
 	case BTFM_FM_SLIM_TX:
 		num = 2;
 		num = 2;
+		fallthrough;
 	case BTFM_BT_SCO_SLIM_TX:
 	case BTFM_BT_SCO_SLIM_TX:
 		if (!tx_slot || !tx_num) {
 		if (!tx_slot || !tx_num) {
 			BTFMSLIM_ERR("Invalid tx_slot %p or tx_num %p",
 			BTFMSLIM_ERR("Invalid tx_slot %p or tx_num %p",

+ 0 - 6
slimbus/btfm_slim_hw_interface.h

@@ -6,12 +6,6 @@
 #ifndef __LINUX_BTFM_SLIM_HW_INTERFACE_H
 #ifndef __LINUX_BTFM_SLIM_HW_INTERFACE_H
 #define __LINUX_BTFM_SLIM_HW_INTERFACE_H
 #define __LINUX_BTFM_SLIM_HW_INTERFACE_H
 
 
-#if IS_ENABLED(CONFIG_BTFM_SLIM)
-#define BTFMSLIM_DEV_NAME "btfmslim_slave"
-#else
-#define BTFMSLIM_DEV_NAME "btfmslim"
-#endif
-
 // Todo protect with flags
 // Todo protect with flags
 int btfm_slim_register_hw_ep(struct btfmslim *btfm_slim);
 int btfm_slim_register_hw_ep(struct btfmslim *btfm_slim);
 void btfm_slim_unregister_hwep(void);
 void btfm_slim_unregister_hwep(void);

+ 19 - 0
target.bzl

@@ -0,0 +1,19 @@
+load(":bt_kernel.bzl", "define_bt_modules")
+
+def define_pineapple():
+    define_bt_modules(
+        target = "pineapple",
+        modules = [
+            "btpower",
+            "bt_fm_slim",
+            "radio-i2c-rtc6226-qca",
+            # "btfm_slim_codec",
+        ],
+        config_options = [
+            "CONFIG_MSM_BT_POWER",
+            "CONFIG_BTFM_SLIM",
+            "CONFIG_I2C_RTC6226_QCA",
+            # "CONFIG_SLIM_BTFM_CODEC",
+            "CONFIG_BT_HW_SECURE_DISABLE",
+        ]
+    )