Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated auto-gen script to accept cache for policy values #244

Merged
merged 6 commits into from
Sep 20, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 59 additions & 21 deletions SetupDataPkg/Tools/KnobService.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,15 +184,20 @@ def write_uefi_getter_implementations(efi_type, out, schema):
if knob.help != "":
out.write("// {}".format(knob.help) + get_line_ending(efi_type))

out.write("// Get the current value of the {} knob".format(knob.name) + get_line_ending(efi_type))
out.write("EFI_STATUS {}{} (".format(
kuqin12 marked this conversation as resolved.
Show resolved Hide resolved
# Implement the cached getter function
out.write("// Get the current value of the {} knob from supplied cache".format(
knob.name
) + get_line_ending(efi_type))
out.write("EFI_STATUS {}{}FromCache (".format(
naming_convention_filter("config_get_", False, efi_type),
knob.name
) + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type))
out.write("{} *Knob".format(
out.write("{} *Knob,".format(
get_type_string(knob.format.c_type, efi_type)
) + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type) + "UINT8 *Cache," + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type) + "UINT16 CacheSize" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type) + ")" + get_line_ending(efi_type))
out.write("{" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type) + "EFI_STATUS Status;")
Expand All @@ -202,7 +207,7 @@ def write_uefi_getter_implementations(efi_type, out, schema):
# minus the data size and CRC32, which comes after the data
offset += get_variable_list_size(knob)
offset -= 4 + knob.format.size_in_bytes()
out.write("CONST UINTN Offset = {};".format(
out.write("CONST UINTN Offset = CACHED_POLICY_HEADER_SIZE + {};".format(
offset
) + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))
Expand All @@ -211,17 +216,17 @@ def write_uefi_getter_implementations(efi_type, out, schema):
offset += 4 + knob.format.size_in_bytes()

out.write(get_spacing_string(efi_type))
out.write("if (Knob == NULL) {" + get_line_ending(efi_type))
out.write("if ((Knob == NULL) || (Cache == NULL)) {" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type, num=2))
out.write("return EFI_INVALID_PARAMETER;" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type))
out.write("}" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))

out.write(get_spacing_string(efi_type))
out.write("if (!CachedPolicyInitialized) {" + get_line_ending(efi_type))
out.write("if (((CACHED_POLICY_HEADER*)Cache)->Signature != CACHED_POLICY_SINGATURE) {" + get_line_ending(efi_type))
kuqin12 marked this conversation as resolved.
Show resolved Hide resolved
out.write(get_spacing_string(efi_type, num=2))
out.write("Status = InitConfigPolicyCache ();" + get_line_ending(efi_type))
out.write("Status = InitConfigPolicyCache (Cache, CacheSize);" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type, num=2))
out.write("if (EFI_ERROR (Status)) {" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type, num=3))
Expand All @@ -235,7 +240,7 @@ def write_uefi_getter_implementations(efi_type, out, schema):
out.write(get_line_ending(efi_type))

out.write(get_spacing_string(efi_type))
out.write("if (Offset + sizeof({}) > CachedPolicySize) {{".format(
out.write("if (Offset + sizeof({}) > CacheSize) {{".format(
get_type_string(knob.format.c_type, efi_type)
) + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type, num=2))
Expand All @@ -247,14 +252,34 @@ def write_uefi_getter_implementations(efi_type, out, schema):
out.write(get_line_ending(efi_type))

out.write(get_spacing_string(efi_type))
out.write("CopyMem(Knob, CachedPolicy + Offset, sizeof ({}));".format(
out.write("CopyMem(Knob, Cache + Offset, sizeof ({}));".format(
get_type_string(knob.format.c_type, efi_type)
) + get_line_ending(efi_type))

out.write(get_spacing_string(efi_type))
out.write("return EFI_SUCCESS;" + get_line_ending(efi_type))
out.write("}" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))

# Implement the normal getter function, from the global cache
out.write("// Get the current value of the {} knob from cache".format(knob.name) + get_line_ending(efi_type))
out.write("EFI_STATUS {}{} (".format(
naming_convention_filter("config_get_", False, efi_type),
knob.name
) + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type))
out.write("{} *Knob".format(
get_type_string(knob.format.c_type, efi_type)
) + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type) + ")" + get_line_ending(efi_type))
out.write("{" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type))
out.write("return {}{}FromCache (Knob, CachedPolicy, sizeof (CachedPolicy));".format(
naming_convention_filter("config_get_", False, efi_type),
knob.name
) + get_line_ending(efi_type))
out.write("}" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))
pass


Expand Down Expand Up @@ -927,17 +952,29 @@ def generate_getter_implementation(schema, header_path, efi_type):
out.write(get_line_ending(efi_type))

policy_size = hex(get_conf_policy_size(schema))
out.write("STATIC CONST UINT16 CachedPolicySize = {};".format(
policy_size
) + get_line_ending(efi_type))
out.write("STATIC CHAR8 CachedPolicy[{}];".format(
out.write("#define CACHED_POLICY_SINGATURE SIGNATURE_32 ('C', 'P', 'O', 'L')" + get_line_ending(efi_type))
kuqin12 marked this conversation as resolved.
Show resolved Hide resolved
out.write("#define CACHED_POLICY_HEADER_SIZE sizeof (CACHED_POLICY_HEADER)" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))

out.write("#define CACHED_POLICY_SIZE {}".format(
policy_size
) + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))

out.write("// Cached policy header, used to validate the cache internally" + get_line_ending(efi_type))
out.write("#pragma pack (1)" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))
out.write("typedef struct {" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type) + "UINT32 Signature;" + get_line_ending(efi_type))
out.write("} CACHED_POLICY_HEADER;" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))
out.write("#pragma pack ()" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))

out.write("STATIC CHAR8 CachedPolicy[CACHED_POLICY_SIZE + CACHED_POLICY_HEADER_SIZE];" + get_line_ending(efi_type))
out.write("STATIC BOOLEAN CachedPolicyInitialized = FALSE;")
out.write(get_line_ending(efi_type))
out.write(get_assert_style(efi_type, "({} <= MAX_UINT16".format(
policy_size
), '"Config too large!"'))
out.write(get_assert_style(efi_type, "(CACHED_POLICY_SIZE + CACHED_POLICY_HEADER_SIZE <= MAX_UINT16", '"Config too large!"'))
out.write(get_line_ending(efi_type))
out.write(get_line_ending(efi_type))

Expand All @@ -946,21 +983,22 @@ def generate_getter_implementation(schema, header_path, efi_type):
out.write("EFI_STATUS" + get_line_ending(efi_type))
out.write(naming_convention_filter("init_config_policy_cache (", False, efi_type))
out.write(get_line_ending(efi_type))
out.write(get_spacing_string(efi_type) + get_type_string("void", efi_type))
out.write(get_spacing_string(efi_type) + "UINT8 *Cache," + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type) + "UINT16 CacheSize")
out.write(get_line_ending(efi_type) + ")" + get_line_ending(efi_type) + "{")
out.write(get_line_ending(efi_type))
out.write(get_spacing_string(efi_type))
out.write("EFI_STATUS Status;" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type))
out.write("UINT16 ConfPolSize = CachedPolicySize;" + get_line_ending(efi_type))
out.write("UINT16 ConfPolSize = CacheSize;" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))

out.write(get_spacing_string(efi_type))
out.write("Status = GetPolicy (")
out.write("PcdGetPtr (PcdConfigurationPolicyGuid), NULL,")
out.write(" CachedPolicy, &ConfPolSize);" + get_line_ending(efi_type))
out.write(" Cache + CACHED_POLICY_HEADER_SIZE, &ConfPolSize);" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type))
out.write("if ((EFI_ERROR (Status)) || (ConfPolSize != CachedPolicySize)) {" + get_line_ending(efi_type))
out.write("if ((EFI_ERROR (Status)) || (ConfPolSize != CACHED_POLICY_SIZE)) {" + get_line_ending(efi_type))
out.write(get_spacing_string(efi_type, num=2) + "ASSERT (FALSE);")
out.write(get_line_ending(efi_type))
out.write(get_spacing_string(efi_type, num=2))
Expand All @@ -969,7 +1007,7 @@ def generate_getter_implementation(schema, header_path, efi_type):
out.write("}" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))
out.write(get_spacing_string(efi_type))
out.write("CachedPolicyInitialized = TRUE;" + get_line_ending(efi_type))
out.write("((CACHED_POLICY_HEADER*)Cache)->Signature = CACHED_POLICY_SINGATURE;" + get_line_ending(efi_type))
out.write(get_line_ending(efi_type))
out.write(get_spacing_string(efi_type))
out.write("return Status;" + get_line_ending(efi_type))
Expand Down
Loading