Re: [PATCH v3 27/29] acpi: Put table-setup code in its own function
Hi Andy, On Wed, 8 Apr 2020 at 11:11, Andy Shevchenko wrote: > > On Tue, Apr 07, 2020 at 08:57:52PM -0600, Simon Glass wrote: > > On Fri, 3 Apr 2020 at 07:32, Andy Shevchenko > > wrote: > > > > > > On Mon, Mar 30, 2020 at 05:13:03PM -0600, Simon Glass wrote: > > > > We always write three basic tables to ACPI at the start. Move this into > > > > its own function, along with acpi_fill_header(), so we can write a test > > > > for this code. > > > > > > ... > > > > > > > /* Re-calculate checksum */ > > > > rsdt->header.checksum = 0; > > > > - rsdt->header.checksum = table_compute_checksum((u8 *)rsdt, > > > > + rsdt->header.checksum = table_compute_checksum(rsdt, > > > > > > > > rsdt->header.length); > > > > Please can you keep the filenames / functions in your response? > > Fragments make it harder to find the code. > > I thought, obviously mistakenly, that git users know about git grep ... Well I'd appreciate it if you could keep them in. It is customary, and it avoids grepping as you say. > > > > Why suddenly casting is not needed in this patch? > > > Same question to the rest. > > > > > > (If it's a valid change, it should be in a separate patch) > > > > It was never needed. See the prototype for table_compute_checksum(). > > > > But I can put it back in. > > Depends on your preferences, but it's definitely not a material for this > change. Separate one? It isn't worth worrying about as a later commit drops it. Let's just leave it as you had it, with the cast. Regards, Simon
Re: [PATCH v3 27/29] acpi: Put table-setup code in its own function
On Tue, Apr 07, 2020 at 08:57:52PM -0600, Simon Glass wrote: > On Fri, 3 Apr 2020 at 07:32, Andy Shevchenko > wrote: > > > > On Mon, Mar 30, 2020 at 05:13:03PM -0600, Simon Glass wrote: > > > We always write three basic tables to ACPI at the start. Move this into > > > its own function, along with acpi_fill_header(), so we can write a test > > > for this code. > > > > ... > > > > > /* Re-calculate checksum */ > > > rsdt->header.checksum = 0; > > > - rsdt->header.checksum = table_compute_checksum((u8 *)rsdt, > > > + rsdt->header.checksum = table_compute_checksum(rsdt, > > > rsdt->header.length); > > Please can you keep the filenames / functions in your response? > Fragments make it harder to find the code. I thought, obviously mistakenly, that git users know about git grep ... > > Why suddenly casting is not needed in this patch? > > Same question to the rest. > > > > (If it's a valid change, it should be in a separate patch) > > It was never needed. See the prototype for table_compute_checksum(). > > But I can put it back in. Depends on your preferences, but it's definitely not a material for this change. Separate one? -- With Best Regards, Andy Shevchenko
Re: [PATCH v3 27/29] acpi: Put table-setup code in its own function
Hi Andy, On Fri, 3 Apr 2020 at 07:32, Andy Shevchenko wrote: > > On Mon, Mar 30, 2020 at 05:13:03PM -0600, Simon Glass wrote: > > We always write three basic tables to ACPI at the start. Move this into > > its own function, along with acpi_fill_header(), so we can write a test > > for this code. > > ... > > > /* Re-calculate checksum */ > > rsdt->header.checksum = 0; > > - rsdt->header.checksum = table_compute_checksum((u8 *)rsdt, > > + rsdt->header.checksum = table_compute_checksum(rsdt, > > rsdt->header.length); Please can you keep the filenames / functions in your response? Fragments make it harder to find the code. > > Why suddenly casting is not needed in this patch? > Same question to the rest. > > (If it's a valid change, it should be in a separate patch) It was never needed. See the prototype for table_compute_checksum(). But I can put it back in. Regards, Simon
Re: [PATCH v3 27/29] acpi: Put table-setup code in its own function
On Mon, Mar 30, 2020 at 05:13:03PM -0600, Simon Glass wrote: > We always write three basic tables to ACPI at the start. Move this into > its own function, along with acpi_fill_header(), so we can write a test > for this code. ... > /* Re-calculate checksum */ > rsdt->header.checksum = 0; > - rsdt->header.checksum = table_compute_checksum((u8 *)rsdt, > + rsdt->header.checksum = table_compute_checksum(rsdt, > rsdt->header.length); Why suddenly casting is not needed in this patch? Same question to the rest. (If it's a valid change, it should be in a separate patch) -- With Best Regards, Andy Shevchenko
[PATCH v3 27/29] acpi: Put table-setup code in its own function
We always write three basic tables to ACPI at the start. Move this into its own function, along with acpi_fill_header(), so we can write a test for this code. Signed-off-by: Simon Glass --- Changes in v3: - Beef up the comment explaining how the unaligned address is used - Fix 'XDST' typo - Move acpi_align_large() out of dm_test_acpi_setup_base_tables() Changes in v2: None arch/x86/lib/acpi_table.c | 72 +-- include/acpi/acpi_table.h | 10 + lib/acpi/acpi_table.c | 79 ++- test/dm/acpi.c| 58 +++- 4 files changed, 145 insertions(+), 74 deletions(-) diff --git a/arch/x86/lib/acpi_table.c b/arch/x86/lib/acpi_table.c index d4af56eabf4..4a7b0739394 100644 --- a/arch/x86/lib/acpi_table.c +++ b/arch/x86/lib/acpi_table.c @@ -31,58 +31,6 @@ extern const unsigned char AmlCode[]; /* ACPI RSDP address to be used in boot parameters */ static ulong acpi_rsdp_addr; -static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, - struct acpi_xsdt *xsdt) -{ - memset(rsdp, 0, sizeof(struct acpi_rsdp)); - - memcpy(rsdp->signature, RSDP_SIG, 8); - memcpy(rsdp->oem_id, OEM_ID, 6); - - rsdp->length = sizeof(struct acpi_rsdp); - rsdp->rsdt_address = (u32)rsdt; - - rsdp->xsdt_address = (u64)(u32)xsdt; - rsdp->revision = ACPI_RSDP_REV_ACPI_2_0; - - /* Calculate checksums */ - rsdp->checksum = table_compute_checksum((void *)rsdp, 20); - rsdp->ext_checksum = table_compute_checksum((void *)rsdp, - sizeof(struct acpi_rsdp)); -} - -static void acpi_write_rsdt(struct acpi_rsdt *rsdt) -{ - struct acpi_table_header *header = &(rsdt->header); - - /* Fill out header fields */ - acpi_fill_header(header, "RSDT"); - header->length = sizeof(struct acpi_rsdt); - header->revision = 1; - - /* Entries are filled in later, we come with an empty set */ - - /* Fix checksum */ - header->checksum = table_compute_checksum((void *)rsdt, - sizeof(struct acpi_rsdt)); -} - -static void acpi_write_xsdt(struct acpi_xsdt *xsdt) -{ - struct acpi_table_header *header = &(xsdt->header); - - /* Fill out header fields */ - acpi_fill_header(header, "XSDT"); - header->length = sizeof(struct acpi_xsdt); - header->revision = 1; - - /* Entries are filled in later, we come with an empty set */ - - /* Fix checksum */ - header->checksum = table_compute_checksum((void *)xsdt, - sizeof(struct acpi_xsdt)); -} - static void acpi_create_facs(struct acpi_facs *facs) { memset((void *)facs, 0, sizeof(struct acpi_facs)); @@ -402,7 +350,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr) ulong write_acpi_tables(ulong start_addr) { struct acpi_ctx sctx, *ctx = - struct acpi_xsdt *xsdt; struct acpi_facs *facs; struct acpi_table_header *dsdt; struct acpi_fadt *fadt; @@ -415,33 +362,16 @@ ulong write_acpi_tables(ulong start_addr) int i; start = map_sysmem(start_addr, 0); - ctx->current = start; - - /* Align ACPI tables to 16 byte */ - acpi_align(ctx); debug("ACPI: Writing ACPI tables at %lx\n", start_addr); - /* We need at least an RSDP and an RSDT Table */ - ctx->rsdp = ctx->current; - acpi_inc_align(ctx, sizeof(struct acpi_rsdp)); - ctx->rsdt = ctx->current; - acpi_inc_align(ctx, sizeof(struct acpi_rsdt)); - xsdt = ctx->current; - acpi_inc_align(ctx, sizeof(struct acpi_xsdt)); + acpi_setup_base_tables(ctx, start); /* * Per ACPI spec, the FACS table address must be aligned to a 64 byte * boundary (Windows checks this, but Linux does not). */ acpi_align64(ctx); - /* clear all table memory */ - memset((void *)start, 0, ctx->current - start); - - acpi_write_rsdp(ctx->rsdp, ctx->rsdt, xsdt); - acpi_write_rsdt(ctx->rsdt); - acpi_write_xsdt(xsdt); - debug("ACPI:* FACS\n"); facs = ctx->current; acpi_inc_align(ctx, sizeof(struct acpi_facs)); diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index b86800fdfa4..05b0948b6f6 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -564,6 +564,16 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount); */ int acpi_add_table(struct acpi_ctx *ctx, void *table); +/** + * acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XSDT + * + * Set up the context with the given start position. Some basic tables are + * always needed, so set them up as well. + * + * @ctx: Context to set up + */ +void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start); + #endif /* !__ACPI__*/ #include diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index