mm-driver: Refactor to separate modules into packages

Currently, all of the modules are built from a single Bazel package.
This complicates integration with the vendor build because the
Android build system builds the modules individually.

Split the modules into their own Bazel packages to align more closely
with the Android build system's expectations and easy to hook bazel build.

Change-Id: I100e9ec9edbe96212089a5944cbba4d6677ff83a
Signed-off-by: Varsha Suresh <quic_varssure@quicinc.com>
This commit is contained in:
Varsha Suresh
2023-05-04 15:46:47 -07:00
parent 07a41b0f00
commit 508cc02147
16 changed files with 176 additions and 186 deletions

View File

@@ -2,35 +2,21 @@ load("//build/kernel/kleaf:kernel.bzl", "ddk_headers")
package( package(
default_visibility = [ default_visibility = [
"//visibility:public"], "//visibility:public",
],
) )
ddk_headers( ddk_headers(
name = "mm_drivers_configs", name = "mm_drivers_configs",
hdrs = glob([ hdrs = glob(["config/*.h"]),
"config/*.h"]), includes = ["config"],
includes = ["config"]
)
ddk_headers(
name = "hw_fence_headers",
hdrs = glob([
"hw_fence/include/*.h"]),
includes = ["hw_fence/include"]
)
ddk_headers(
name = "sync_fence_uapi_headers",
hdrs = glob([
"sync_fence/include/uapi/sync_fence/*.h",
"sync_fence/include/*.h"]),
includes = ["sync_fence/include"]
) )
ddk_headers( ddk_headers(
name = "mm_drivers_headers", name = "mm_drivers_headers",
hdrs = [":mm_drivers_configs", ":hw_fence_headers", ":sync_fence_uapi_headers"] hdrs = [
":mm_drivers_configs",
"//vendor/qcom/opensource/mm-drivers/hw_fence:hw_fence_headers",
"//vendor/qcom/opensource/mm-drivers/sync_fence:sync_fence_uapi_headers",
],
) )
load(":target.bzl", "define_pineapple")
define_pineapple()

16
hw_fence/BUILD.bazel Normal file
View File

@@ -0,0 +1,16 @@
load("//build/kernel/kleaf:kernel.bzl", "ddk_headers")
load(":define_hw_fence.bzl", "define_hw_fence")
package(
default_visibility = [
"//visibility:public"
],
)
ddk_headers(
name = "hw_fence_headers",
hdrs = glob(["include/*.h"]),
includes = ["include"]
)
define_hw_fence()

4
hw_fence/Kconfig Normal file
View File

@@ -0,0 +1,4 @@
config QTI_HW_FENCE
bool "HW Fence"
help
Enable the hw_fence module

1
hw_fence/defconfig Normal file
View File

@@ -0,0 +1 @@
CONFIG_QTI_HW_FENCE=y

View File

@@ -0,0 +1,46 @@
load("//build/kernel/kleaf:kernel.bzl", "ddk_module", "ddk_submodule")
load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
load("//msm-kernel:target_variants.bzl", "get_all_variants")
def _define_module(target, variant):
tv = "{}_{}".format(target, variant)
ddk_module(
name = "{}_msm_hw_fence".format(tv),
srcs = [
"src/hw_fence_drv_debug.c",
"src/hw_fence_drv_ipc.c",
"src/hw_fence_drv_priv.c",
"src/hw_fence_drv_utils.c",
"src/msm_hw_fence.c",
"src/msm_hw_fence_synx_translation.c",
],
out = "msm_hw_fence.ko",
defconfig = "defconfig",
kconfig = "Kconfig",
conditional_srcs = {
"CONFIG_DEBUG_FS": {
True: ["src/hw_fence_ioctl.c"],
},
},
deps = [
"//msm-kernel:all_headers",
"//vendor/qcom/opensource/synx-kernel:synx_headers",
"//vendor/qcom/opensource/mm-drivers:mm_drivers_headers",
],
kernel_build = "//msm-kernel:{}".format(tv),
)
copy_to_dist_dir(
name = "{}_msm_hw_fence_dist".format(tv),
data = [":{}_msm_hw_fence".format(tv)],
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_hw_fence():
for (t, v) in get_all_variants():
_define_module(t, v)

View File

@@ -1,103 +0,0 @@
load("//build/kernel/kleaf:kernel.bzl", "ddk_module","ddk_submodule")
load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
load("//msm-kernel:target_variants.bzl", "get_all_variants")
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,
srcs = srcs,
config_srcs = processed_config_srcs,
config_option = config_option,
deps = deps,
)
module_map[name] = module
def _get_config_choices(map, options):
choices = []
for option in map:
choices.extend(map[option].get(option in options,[]))
return choices
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_srcs(module, options, formatter):
srcs = module.srcs + _get_config_choices(module.config_srcs, options)
print("-",module.name,",",module.config_option,",srcs =",srcs)
module_path = "{}/".format(module.path) if module.path else ""
return ["{}{}".format(module_path, formatter(src)) for src in srcs]
def _get_kernel_build_module_deps(module, options, formatter):
return [formatter(dep) for dep in module.deps]
def mm_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)
build_print = lambda message : print("{}: {}".format(kernel_build, message))
formatter = lambda s : s.replace("%b", kernel_build).replace("%t", target)
headers = ["//msm-kernel:all_headers"] + registry.hdrs
all_module_rules = []
for module in modules:
rule_name = "{}_{}".format(kernel_build, module.name)
module_srcs = _get_kernel_build_module_srcs(module, options, formatter)
if not module_srcs:
continue
ddk_submodule(
name = rule_name,
srcs = module_srcs,
out = "{}.ko".format(module.name),
deps = headers + _get_kernel_build_module_deps(module, options, formatter),
local_defines = options.keys(),
)
all_module_rules.append(rule_name)
ddk_module(
name = "{}_mm_drivers".format(kernel_build),
kernel_build = kernel_build_label,
deps = all_module_rules,
)
copy_to_dist_dir(
name = "{}_mm_drivers_dist".format(kernel_build),
data = [":{}_mm_drivers".format(kernel_build)],
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_consolidate_gki_modules(target, registry, modules, config_options = []):
for (targets, variant) in get_all_variants():
define_target_variant_modules(targets, variant, registry, modules, config_options)

View File

@@ -1,44 +0,0 @@
load(":mm_module_build.bzl", "mm_driver_module_entry")
HW_FENCE_PATH = "hw_fence"
MSM_EXT_DISPLAY_PATH = "msm_ext_display"
SYNC_FENCE_PATH = "sync_fence"
mm_driver_modules = mm_driver_module_entry([":mm_drivers_headers"])
module_entry = mm_driver_modules.register
#--------------- MM-DRIVERS MODULES ------------------
module_entry(
name = "hw_fence",
path = HW_FENCE_PATH + "/src",
config_option = "CONFIG_QTI_HW_FENCE",
config_srcs = {
"CONFIG_DEBUG_FS" : [
"hw_fence_ioctl.c",
]
},
srcs = ["hw_fence_drv_debug.c",
"hw_fence_drv_ipc.c",
"hw_fence_drv_priv.c",
"hw_fence_drv_utils.c",
"msm_hw_fence.c",
"msm_hw_fence_synx_translation.c"],
deps =[
"//vendor/qcom/opensource/synx-kernel:synx_headers"
]
)
module_entry(
name = "msm_ext_display",
path = MSM_EXT_DISPLAY_PATH + "/src",
config_option = "CONFIG_MSM_EXT_DISPLAY",
srcs = ["msm_ext_display.c"],
)
module_entry(
name = "sync_fence",
path = SYNC_FENCE_PATH + "/src",
config_option = "CONFIG_QCOM_SPEC_SYNC",
srcs = ["qcom_sync_file.c"],
)

View File

@@ -0,0 +1,10 @@
load("//build/kernel/kleaf:kernel.bzl", "ddk_headers")
load(":define_msm_ext_display.bzl", "define_msm_ext_display")
package(
default_visibility = [
"//visibility:public"
],
)
define_msm_ext_display()

4
msm_ext_display/Kconfig Normal file
View File

@@ -0,0 +1,4 @@
config MSM_EXT_DISPLAY
bool "Enable msm_ext_display"
help
Enable msm_ext_display driver

View File

@@ -0,0 +1 @@
CONFIG_MSM_EXT_DISPLAY=y

View File

@@ -0,0 +1,31 @@
load("//build/kernel/kleaf:kernel.bzl", "ddk_module", "ddk_submodule")
load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
load("//msm-kernel:target_variants.bzl", "get_all_variants")
def _define_module(target, variant):
tv = "{}_{}".format(target, variant)
ddk_module(
name = "{}_msm_ext_display".format(tv),
srcs = ["src/msm_ext_display.c"],
out = "msm_ext_display.ko",
defconfig = "defconfig",
kconfig = "Kconfig",
deps = ["//msm-kernel:all_headers",
"//vendor/qcom/opensource/mm-drivers:mm_drivers_headers"],
kernel_build = "//msm-kernel:{}".format(tv),
)
copy_to_dist_dir(
name = "{}_msm_ext_display_dist".format(tv),
data = [":{}_msm_ext_display".format(tv)],
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_msm_ext_display():
for (t, v) in get_all_variants():
_define_module(t, v)

16
sync_fence/BUILD.bazel Normal file
View File

@@ -0,0 +1,16 @@
load("//build/kernel/kleaf:kernel.bzl", "ddk_headers")
load(":define_sync_fence.bzl", "define_sync_fence")
package(
default_visibility = [
"//visibility:public"
],
)
ddk_headers(
name = "sync_fence_uapi_headers",
hdrs = glob(["include/uapi/sync_fence/*.h"]),
includes = ["include"]
)
define_sync_fence()

4
sync_fence/Kconfig Normal file
View File

@@ -0,0 +1,4 @@
config QCOM_SPEC_SYNC
bool "Enable spec fence"
help
Enable sync_fence driver

1
sync_fence/defconfig Normal file
View File

@@ -0,0 +1 @@
CONFIG_QCOM_SPEC_SYNC=y

View File

@@ -0,0 +1,33 @@
load("//build/kernel/kleaf:kernel.bzl", "ddk_module")
load("//build/bazel_common_rules/dist:dist.bzl", "copy_to_dist_dir")
load("//msm-kernel:target_variants.bzl", "get_all_variants")
def _define_module(target, variant):
tv = "{}_{}".format(target, variant)
ddk_module(
name = "{}_sync_fence".format(tv),
srcs = ["src/qcom_sync_file.c"],
out = "sync_fence.ko",
kconfig = "Kconfig",
defconfig = "defconfig",
deps = [
"//msm-kernel:all_headers",
"//vendor/qcom/opensource/mm-drivers:mm_drivers_headers",
],
kernel_build = "//msm-kernel:{}".format(tv),
)
copy_to_dist_dir(
name = "{}_sync_fence_dist".format(tv),
data = [":{}_sync_fence".format(tv)],
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_sync_fence():
for (t, v) in get_all_variants():
_define_module(t, v)

View File

@@ -1,16 +0,0 @@
load(":mm_modules.bzl", "mm_driver_modules")
load(":mm_module_build.bzl", "define_consolidate_gki_modules")
def define_pineapple():
define_consolidate_gki_modules(
target = "pineapple",
registry = mm_driver_modules,
modules = [
"hw_fence",
"msm_ext_display",
"sync_fence",
],
config_options = [
"CONFIG_DEBUG_FS",
],
)