Skip to content

Commit

Permalink
ACPICA: iasl: add ASL conversion tool
Browse files Browse the repository at this point in the history
ACPICA commit c04d310039d3e0ed1cb62876fe7e596fbc75ab01
ACPICA commit a65c1df7e6b4bad8e37df822018c40c6c446add9

The key feature of this utility is that the original comments within
the input ASL files are preserved during the conversion process, and
included within the converted ASL+ file -- thus creating a transparent
conversion of existing ASL files to ASL+ (ASL 2.0)

This patch is an automatic generation of the ASL converter commit,
Linux kernel isn't affected by the functionality provided in this
commit, but requires the linuxized changes to support future ACPICA
release automation.

Link: https://github.com/acpica/acpica/commit/c04d3100
Link: https://github.com/acpica/acpica/commit/a65c1df7
Signed-off-by: Bob Moore <robert.moore@intel.com>
Signed-off-by: Jung-uk Kim <jkim@FreeBSD.org>
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
  • Loading branch information
Bob Moore authored and Rafael J. Wysocki committed Apr 28, 2017
1 parent c8e8ab1 commit 9cf7ade
Show file tree
Hide file tree
Showing 17 changed files with 490 additions and 18 deletions.
144 changes: 144 additions & 0 deletions drivers/acpi/acpica/acconvert.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/******************************************************************************
*
* Module Name: acapps - common include for ACPI applications/tools
*
*****************************************************************************/

/*
* Copyright (C) 2000 - 2017, Intel Corp.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions, and the following disclaimer,
* without modification.
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
* substantially similar to the "NO WARRANTY" disclaimer below
* ("Disclaimer") and any redistribution must be conditioned upon
* including a substantially similar Disclaimer requirement for further
* binary redistribution.
* 3. Neither the names of the above-listed copyright holders nor the names
* of any contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* Alternatively, this software may be distributed under the terms of the
* GNU General Public License ("GPL") version 2 as published by the Free
* Software Foundation.
*
* NO WARRANTY
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGES.
*/

#ifndef _ACCONVERT
#define _ACCONVERT

/* Definitions for comment state */

#define ASL_COMMENT_STANDARD 1
#define ASLCOMMENT_INLINE 2
#define ASL_COMMENT_OPEN_PAREN 3
#define ASL_COMMENT_CLOSE_PAREN 4
#define ASL_COMMENT_CLOSE_BRACE 5

/* Definitions for comment print function*/

#define AML_COMMENT_STANDARD 1
#define AMLCOMMENT_INLINE 2
#define AML_COMMENT_END_NODE 3
#define AML_NAMECOMMENT 4
#define AML_COMMENT_CLOSE_BRACE 5
#define AML_COMMENT_ENDBLK 6
#define AML_COMMENT_INCLUDE 7

#ifdef ACPI_ASL_COMPILER
/*
* cvcompiler
*/
void
cv_process_comment(struct asl_comment_state current_state,
char *string_buffer, int c1);

void
cv_process_comment_type2(struct asl_comment_state current_state,
char *string_buffer);

u32 cv_calculate_comment_lengths(union acpi_parse_object *op);

void cv_process_comment_state(char input);

char *cv_append_inline_comment(char *inline_comment, char *to_add);

void cv_add_to_comment_list(char *to_add);

void cv_place_comment(u8 type, char *comment_string);

u32 cv_parse_op_block_type(union acpi_parse_object *op);

struct acpi_comment_node *cv_comment_node_calloc(void);

void cg_write_aml_def_block_comment(union acpi_parse_object *op);

void
cg_write_one_aml_comment(union acpi_parse_object *op,
char *comment_to_print, u8 input_option);

void cg_write_aml_comment(union acpi_parse_object *op);

/*
* cvparser
*/
void
cv_init_file_tree(struct acpi_table_header *table,
u8 *aml_start, u32 aml_length);

void cv_clear_op_comments(union acpi_parse_object *op);

struct acpi_file_node *cv_filename_exists(char *filename,
struct acpi_file_node *head);

void cv_label_file_node(union acpi_parse_object *op);

void
cv_capture_list_comments(struct acpi_parse_state *parser_state,
struct acpi_comment_node *list_head,
struct acpi_comment_node *list_tail);

void cv_capture_comments_only(struct acpi_parse_state *parser_state);

void cv_capture_comments(struct acpi_walk_state *walk_state);

void cv_transfer_comments(union acpi_parse_object *op);

/*
* cvdisasm
*/
void cv_switch_files(u32 level, union acpi_parse_object *op);

u8 cv_file_has_switched(union acpi_parse_object *op);

void cv_close_paren_write_comment(union acpi_parse_object *op, u32 level);

void cv_close_brace_write_comment(union acpi_parse_object *op, u32 level);

void
cv_print_one_comment_list(struct acpi_comment_node *comment_list, u32 level);

void
cv_print_one_comment_type(union acpi_parse_object *op,
u8 comment_type, char *end_str, u32 level);

#endif

#endif /* _ACCONVERT */
53 changes: 53 additions & 0 deletions drivers/acpi/acpica/acglobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,59 @@ ACPI_GLOBAL(const char, *acpi_gbl_pld_shape_list[]);

#endif

/*
* Meant for the -ca option.
*/
ACPI_INIT_GLOBAL(char *, acpi_gbl_current_inline_comment, NULL);
ACPI_INIT_GLOBAL(char *, acpi_gbl_current_end_node_comment, NULL);
ACPI_INIT_GLOBAL(char *, acpi_gbl_current_open_brace_comment, NULL);
ACPI_INIT_GLOBAL(char *, acpi_gbl_current_close_brace_comment, NULL);

ACPI_INIT_GLOBAL(char *, acpi_gbl_root_filename, NULL);
ACPI_INIT_GLOBAL(char *, acpi_gbl_current_filename, NULL);
ACPI_INIT_GLOBAL(char *, acpi_gbl_current_parent_filename, NULL);
ACPI_INIT_GLOBAL(char *, acpi_gbl_current_include_filename, NULL);

ACPI_INIT_GLOBAL(struct acpi_comment_node, *acpi_gbl_last_list_head, NULL);

ACPI_INIT_GLOBAL(struct acpi_comment_node, *acpi_gbl_def_blk_comment_list_head,
NULL);
ACPI_INIT_GLOBAL(struct acpi_comment_node, *acpi_gbl_def_blk_comment_list_tail,
NULL);

ACPI_INIT_GLOBAL(struct acpi_comment_node, *acpi_gbl_reg_comment_list_head,
NULL);
ACPI_INIT_GLOBAL(struct acpi_comment_node, *acpi_gbl_reg_comment_list_tail,
NULL);

ACPI_INIT_GLOBAL(struct acpi_comment_node, *acpi_gbl_inc_comment_list_head,
NULL);
ACPI_INIT_GLOBAL(struct acpi_comment_node, *acpi_gbl_inc_comment_list_tail,
NULL);

ACPI_INIT_GLOBAL(struct acpi_comment_node, *acpi_gbl_end_blk_comment_list_head,
NULL);
ACPI_INIT_GLOBAL(struct acpi_comment_node, *acpi_gbl_end_blk_comment_list_tail,
NULL);

ACPI_INIT_GLOBAL(struct acpi_comment_addr_node,
*acpi_gbl_comment_addr_list_head, NULL);

ACPI_INIT_GLOBAL(union acpi_parse_object, *acpi_gbl_current_scope, NULL);

ACPI_INIT_GLOBAL(struct acpi_file_node, *acpi_gbl_file_tree_root, NULL);

ACPI_GLOBAL(acpi_cache_t *, acpi_gbl_reg_comment_cache);
ACPI_GLOBAL(acpi_cache_t *, acpi_gbl_comment_addr_cache);
ACPI_GLOBAL(acpi_cache_t *, acpi_gbl_file_cache);

ACPI_INIT_GLOBAL(u8, gbl_capture_comments, FALSE);

ACPI_INIT_GLOBAL(u8, acpi_gbl_debug_asl_conversion, FALSE);
ACPI_INIT_GLOBAL(ACPI_FILE, acpi_gbl_conv_debug_file, NULL);

ACPI_GLOBAL(char, acpi_gbl_table_sig[4]);

/*****************************************************************************
*
* Application globals
Expand Down
99 changes: 84 additions & 15 deletions drivers/acpi/acpica/aclocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ typedef u32 acpi_mutex_handle;

/* Total number of aml opcodes defined */

#define AML_NUM_OPCODES 0x82
#define AML_NUM_OPCODES 0x83

/* Forward declarations */

Expand Down Expand Up @@ -754,21 +754,52 @@ union acpi_parse_value {
#define ACPI_DISASM_ONLY_MEMBERS(a)
#endif

#if defined(ACPI_ASL_COMPILER)
#define ACPI_CONVERTER_ONLY_MEMBERS(a) a;
#else
#define ACPI_CONVERTER_ONLY_MEMBERS(a)
#endif

#define ACPI_PARSE_COMMON \
union acpi_parse_object *parent; /* Parent op */\
u8 descriptor_type; /* To differentiate various internal objs */\
u8 flags; /* Type of Op */\
u16 aml_opcode; /* AML opcode */\
u8 *aml; /* Address of declaration in AML */\
union acpi_parse_object *next; /* Next op */\
struct acpi_namespace_node *node; /* For use by interpreter */\
union acpi_parse_value value; /* Value or args associated with the opcode */\
u8 arg_list_length; /* Number of elements in the arg list */\
ACPI_DISASM_ONLY_MEMBERS (\
u16 disasm_flags; /* Used during AML disassembly */\
u8 disasm_opcode; /* Subtype used for disassembly */\
char *operator_symbol;/* Used for C-style operator name strings */\
char aml_op_name[16]) /* Op name (debug only) */
union acpi_parse_object *parent; /* Parent op */\
u8 descriptor_type; /* To differentiate various internal objs */\
u8 flags; /* Type of Op */\
u16 aml_opcode; /* AML opcode */\
u8 *aml; /* Address of declaration in AML */\
union acpi_parse_object *next; /* Next op */\
struct acpi_namespace_node *node; /* For use by interpreter */\
union acpi_parse_value value; /* Value or args associated with the opcode */\
u8 arg_list_length; /* Number of elements in the arg list */\
ACPI_DISASM_ONLY_MEMBERS (\
u16 disasm_flags; /* Used during AML disassembly */\
u8 disasm_opcode; /* Subtype used for disassembly */\
char *operator_symbol; /* Used for C-style operator name strings */\
char aml_op_name[16]) /* Op name (debug only) */\
ACPI_CONVERTER_ONLY_MEMBERS (\
char *inline_comment; /* Inline comment */\
char *end_node_comment; /* End of node comment */\
char *name_comment; /* Comment associated with the first parameter of the name node */\
char *close_brace_comment; /* Comments that come after } on the same as } */\
struct acpi_comment_node *comment_list; /* comments that appears before this node */\
struct acpi_comment_node *end_blk_comment; /* comments that at the end of a block but before ) or } */\
char *cv_filename; /* Filename associated with this node. Used for ASL/ASL+ converter */\
char *cv_parent_filename) /* Parent filename associated with this node. Used for ASL/ASL+ converter */

/* categories of comments */

typedef enum {
STANDARD_COMMENT = 1,
INLINE_COMMENT,
ENDNODE_COMMENT,
OPENBRACE_COMMENT,
CLOSE_BRACE_COMMENT,
STD_DEFBLK_COMMENT,
END_DEFBLK_COMMENT,
FILENAME_COMMENT,
PARENTFILENAME_COMMENT,
ENDBLK_COMMENT,
INCLUDE_COMMENT
} asl_comment_types;

/* Internal opcodes for disasm_opcode field above */

Expand All @@ -789,6 +820,34 @@ union acpi_parse_value {
#define ACPI_DASM_CASE 0x0E /* If/Else is a Case in a Switch/Case block */
#define ACPI_DASM_DEFAULT 0x0F /* Else is a Default in a Switch/Case block */

/*
* List struct used in the -ca option
*/
struct acpi_comment_node {
char *comment;
struct acpi_comment_node *next;
};

struct acpi_comment_addr_node {
u8 *addr;
struct acpi_comment_addr_node *next;
};

/*
* File node - used for "Include" operator file stack and
* depdendency tree for the -ca option
*/
struct acpi_file_node {
void *file;
char *filename;
char *file_start; /* Points to AML and indicates when the AML for this particular file starts. */
char *file_end; /* Points to AML and indicates when the AML for this particular file ends. */
struct acpi_file_node *next;
struct acpi_file_node *parent;
u8 include_written;
struct acpi_comment_node *include_comment;
};

/*
* Generic operation (for example: If, While, Store)
*/
Expand All @@ -814,6 +873,8 @@ struct acpi_parse_obj_asl {
ACPI_PARSE_COMMON union acpi_parse_object *child;
union acpi_parse_object *parent_method;
char *filename;
u8 file_changed;
char *parent_filename;
char *external_name;
char *namepath;
char name_seg[4];
Expand Down Expand Up @@ -843,6 +904,14 @@ union acpi_parse_object {
struct acpi_parse_obj_asl asl;
};

struct asl_comment_state {
u8 comment_type;
u32 spaces_before;
union acpi_parse_object *latest_parse_node;
union acpi_parse_object *parsing_paren_brace_node;
u8 capture_comments;
};

/*
* Parse state - one state per parser invocation and each control
* method.
Expand Down
35 changes: 35 additions & 0 deletions drivers/acpi/acpica/acmacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,39 @@

#define ACPI_IS_OCTAL_DIGIT(d) (((char)(d) >= '0') && ((char)(d) <= '7'))

/*
* Macors used for the ASL-/ASL+ converter utility
*/
#ifdef ACPI_ASL_COMPILER

#define ASL_CV_LABEL_FILENODE(a) cv_label_file_node(a);
#define ASL_CV_CAPTURE_COMMENTS_ONLY(a) cv_capture_comments_only (a);
#define ASL_CV_CAPTURE_COMMENTS(a) cv_capture_comments (a);
#define ASL_CV_TRANSFER_COMMENTS(a) cv_transfer_comments (a);
#define ASL_CV_CLOSE_PAREN(a,b) cv_close_paren_write_comment(a,b);
#define ASL_CV_CLOSE_BRACE(a,b) cv_close_brace_write_comment(a,b);
#define ASL_CV_SWITCH_FILES(a,b) cv_switch_files(a,b);
#define ASL_CV_CLEAR_OP_COMMENTS(a) cv_clear_op_comments(a);
#define ASL_CV_PRINT_ONE_COMMENT(a,b,c,d) cv_print_one_comment_type (a,b,c,d);
#define ASL_CV_PRINT_ONE_COMMENT_LIST(a,b) cv_print_one_comment_list (a,b);
#define ASL_CV_FILE_HAS_SWITCHED(a) cv_file_has_switched(a)
#define ASL_CV_INIT_FILETREE(a,b,c) cv_init_file_tree(a,b,c);

#else

#define ASL_CV_LABEL_FILENODE(a)
#define ASL_CV_CAPTURE_COMMENTS_ONLY(a)
#define ASL_CV_CAPTURE_COMMENTS(a)
#define ASL_CV_TRANSFER_COMMENTS(a)
#define ASL_CV_CLOSE_PAREN(a,b) acpi_os_printf (")");
#define ASL_CV_CLOSE_BRACE(a,b) acpi_os_printf ("}");
#define ASL_CV_SWITCH_FILES(a,b)
#define ASL_CV_CLEAR_OP_COMMENTS(a)
#define ASL_CV_PRINT_ONE_COMMENT(a,b,c,d)
#define ASL_CV_PRINT_ONE_COMMENT_LIST(a,b)
#define ASL_CV_FILE_HAS_SWITCHED(a) 0
#define ASL_CV_INIT_FILETREE(a,b,c)

#endif

#endif /* ACMACROS_H */
2 changes: 2 additions & 0 deletions drivers/acpi/acpica/acopcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
#define ARGP_BUFFER_OP ARGP_LIST3 (ARGP_PKGLENGTH, ARGP_TERMARG, ARGP_BYTELIST)
#define ARGP_BYTE_OP ARGP_LIST1 (ARGP_BYTEDATA)
#define ARGP_BYTELIST_OP ARGP_LIST1 (ARGP_NAMESTRING)
#define ARGP_COMMENT_OP ARGP_LIST2 (ARGP_BYTEDATA, ARGP_COMMENT)
#define ARGP_CONCAT_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
#define ARGP_CONCAT_RES_OP ARGP_LIST3 (ARGP_TERMARG, ARGP_TERMARG, ARGP_TARGET)
#define ARGP_COND_REF_OF_OP ARGP_LIST2 (ARGP_SIMPLENAME, ARGP_TARGET)
Expand Down Expand Up @@ -223,6 +224,7 @@
#define ARGI_BUFFER_OP ARGI_LIST1 (ARGI_INTEGER)
#define ARGI_BYTE_OP ARGI_INVALID_OPCODE
#define ARGI_BYTELIST_OP ARGI_INVALID_OPCODE
#define ARGI_COMMENT_OP ARGI_INVALID_OPCODE
#define ARGI_CONCAT_OP ARGI_LIST3 (ARGI_ANYTYPE, ARGI_ANYTYPE, ARGI_TARGETREF)
#define ARGI_CONCAT_RES_OP ARGI_LIST3 (ARGI_BUFFER, ARGI_BUFFER, ARGI_TARGETREF)
#define ARGI_COND_REF_OF_OP ARGI_LIST2 (ARGI_OBJECT_REF, ARGI_TARGETREF)
Expand Down
Loading

0 comments on commit 9cf7ade

Please sign in to comment.