Jelajahi Sumber

spu-kernel: Bazel compilation for spu-kernel drivers

Signed-off-by: Nurit Lichtenstein <[email protected]>
Change-Id: I051f02f650b734644e92d4c0bd13239487d4bfb5
Nurit Lichtenstein 2 tahun lalu
induk
melakukan
e4e3733a5a
4 mengubah file dengan 190 tambahan dan 0 penghapusan
  1. 55 0
      BUILD.bazel
  2. 100 0
      spu_module_build.bzl
  3. 23 0
      spu_modules.bzl
  4. 12 0
      target.bzl

+ 55 - 0
BUILD.bazel

@@ -0,0 +1,55 @@
+load("//build/kernel/kleaf:kernel.bzl", "ddk_headers")
+
+package(
+    default_visibility = [
+        "//visibility:public",
+    ],
+)
+
+ddk_headers(
+    name = "spu_kernel_configs",
+    hdrs  = glob([
+      "config/*.h"]),
+    includes = ["config"]
+)
+
+ddk_headers(
+    name = "spu_uapi_headers",
+    hdrs = glob(["include/uapi/linux/*.h"]),
+    includes = [
+        "include/uapi/linux",
+    ],
+)
+
+# Generated list with: find drivers -maxdepth 1 -mindepth 1 -type d -printf '"%p/**/*.h",\n'
+driver_header_globs = [
+    "include/uapi/linux/*.h",
+]
+
+# Generated list with: find drivers -type f -name '*.h' -printf '"%h",\n' | sort -u
+driver_includes = [
+    "include",
+    "include/uapi/linux",
+]
+
+ddk_headers(
+    name = "spu_src_headers",
+    hdrs = glob(driver_header_globs),
+    includes = driver_includes + [
+        ".",
+    ],
+)
+
+ddk_headers(
+    name = "spu_headers",
+    hdrs = [
+        ":spu_src_headers",
+        ":spu_uapi_headers",
+        ":spu_kernel_configs",
+    ],
+)
+
+load(":target.bzl", "define_pineapple")
+
+define_pineapple()
+

+ 100 - 0
spu_module_build.bzl

@@ -0,0 +1,100 @@
+load("//build/kernel/kleaf:kernel.bzl", "kernel_module",
+                                        "kernel_modules_install",
+                                        "ddk_module",
+                                        "ddk_submodule")
+load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
+
+def _register_module_to_map(module_map, name, path, config_option, srcs, config_srcs, deps):
+    processed_config_srcs = {}
+
+    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
+
+    module = struct(
+        name = name,
+        path = path if path else ".",
+        srcs = srcs,
+        config_srcs = processed_config_srcs,
+        config_option = config_option,
+        deps = deps,
+    )
+
+    module_map[name] = module
+
+def _get_kernel_build_module_srcs(kernel_build, module, formatter):
+    src_formatter = lambda srcs: native.glob(formatter(["{}/{}".format(module.path, src) for src in srcs]))
+    srcs = [] + src_formatter(module.srcs)
+
+    return srcs
+
+def _get_kernel_build_options(modules, config_options):
+    all_options = {option: True for option in config_options}
+    all_options = all_options | {module.config_option: True for module in modules if module.config_option}
+    return all_options
+
+def _get_kernel_build_module_deps(module, options, formatter):
+    deps = [formatter(dep) for dep in deps]
+
+    return deps
+
+def spu_driver_module_entry(hdrs = []):
+    module_map = {}
+
+    def register(name, path = None, config_option = None, srcs = [], config_srcs = {}, deps = []):
+        _register_module_to_map(module_map, name, path, config_option, srcs, config_srcs, deps)
+
+    return struct(
+        register = register,
+        get = module_map.get,
+        hdrs = hdrs,
+        module_map = module_map
+    )
+
+def define_target_variant_modules(target, variant, registry, modules, config_options = []):
+    kernel_build = "{}_{}".format(target, variant)
+    kernel_build_label = "//msm-kernel:{}".format(kernel_build)
+    modules = [registry.get(module_name) for module_name in modules]
+    options = _get_kernel_build_options(modules, config_options)
+    formatter = lambda strs : [s.replace("%b", kernel_build).replace("%t", target) for s in strs]
+    headers = ["//msm-kernel:all_headers"] + registry.hdrs
+    all_module_rules = []
+
+    for module in modules:
+        rule_name = "{}_{}".format(kernel_build, module.name)
+        srcs = _get_kernel_build_module_srcs(kernel_build, module, formatter)
+
+        ddk_submodule(
+            name = rule_name,
+            srcs = srcs,
+            out = "{}.ko".format(module.name),
+            deps = headers + formatter(module.deps),
+            local_defines = options.keys()
+        )
+
+        all_module_rules.append(rule_name)
+
+    ddk_module(
+        name = "{}_spu-drivers".format(kernel_build),
+        kernel_build = kernel_build_label,
+        deps = all_module_rules
+    )
+
+    copy_to_dist_dir(
+        name = "{}_spu-drivers_dist".format(kernel_build),
+        data = [":{}_spu-drivers".format(kernel_build)],
+        dist_dir = "../vendor/qcom/opensource/spu-drivers/out", ## TODO
+        flat = True,
+        wipe_dist_dir = False,
+        allow_duplicate_filenames = False,
+        mode_overrides = {"**/*": "644"},
+        log = "info",
+    )
+
+def define_consolidate_gki_modules(target, registry, modules, config_options = []):
+    define_target_variant_modules(target, "consolidate", registry, modules, config_options)
+    define_target_variant_modules(target, "gki", registry, modules, config_options)

+ 23 - 0
spu_modules.bzl

@@ -0,0 +1,23 @@
+load(":spu_module_build.bzl", "spu_driver_module_entry")
+
+
+spu_driver_modules = spu_driver_module_entry([":spu_headers"])
+module_entry = spu_driver_modules.register
+
+#--------------- SPU-DRIVERS MODULES ------------------
+
+module_entry(
+    name = "spcom",
+    config_option = "CONFIG_MSM_SPCOM",
+    srcs = ["spcom.c"],
+    path = "drivers"
+)
+
+module_entry(
+    name = "spss_utils",
+    config_option = "CONFIG_MSM_SPSS_UTILS",
+    srcs = ["spss_utils.c"],
+    path = "drivers"
+)
+
+

+ 12 - 0
target.bzl

@@ -0,0 +1,12 @@
+load(":spu_modules.bzl", "spu_driver_modules")
+load(":spu_module_build.bzl", "define_consolidate_gki_modules")
+
+def define_pineapple():
+    define_consolidate_gki_modules(
+        target = "pineapple",
+        registry = spu_driver_modules,
+        modules = [
+            "spcom",
+            "spss_utils",
+        ],
+)