From 18de5aeae7999253ce2e0c19bda0b773d4cafe92 Mon Sep 17 00:00:00 2001 From: dongpingx Date: Fri, 30 Aug 2024 17:57:15 +0800 Subject: [PATCH] misc: configurator need to support configurable reg width for UART We found sometime we need to configure reg width for mmio and we change the width by hand for workaround, now we can configure the width by configurator. I defined a macro named CONFIG_SERIAL_MMIO_REG_WIDTH in uart16550.c, collected mmio ports, loaded them and made a judgement whether the current serial_console was a mmio serial, it will show an option for mmio and hide for other serial ports. I tested three sorts of serials: portio, pci and mmio, built acrn and checked the content generated in build/hypervisor/include/config.h, I confirmed the results are correct. Tracked-On: #8721 Signed-off-by: dongpingx --- hypervisor/debug/uart16550.c | 8 +++- .../configurator/src/pages/Config.vue | 22 ++++++++++- .../configurator/pyodide/loadBoard.py | 38 +++++++++++++++++++ .../scenario_config/jsonschema/converter.py | 17 +++++++++ misc/config_tools/schema/config.xsd | 7 ++++ misc/config_tools/schema/types.xsd | 14 +++++++ misc/config_tools/xforms/config_common.xsl | 5 +++ 7 files changed, 108 insertions(+), 3 deletions(-) diff --git a/hypervisor/debug/uart16550.c b/hypervisor/debug/uart16550.c index c917acd6b..087835675 100644 --- a/hypervisor/debug/uart16550.c +++ b/hypervisor/debug/uart16550.c @@ -47,7 +47,7 @@ static struct console_uart uart = { .enabled = true, .type = MMIO, .mmio_base_vaddr = (void *)CONFIG_SERIAL_MMIO_BASE, - .reg_width = 1, + .reg_width = CONFIG_SERIAL_MMIO_REG_WIDTH, }; #endif @@ -292,7 +292,11 @@ void uart16550_set_property(bool enabled, enum serial_dev_type uart_type, uint64 uart.reg_width = 4; } else if (uart_type == MMIO) { uart.mmio_base_vaddr = (void *)data; - uart.reg_width = 1; + #if defined(CONFIG_SERIAL_MMIO_BASE) + uart.reg_width = CONFIG_SERIAL_MMIO_REG_WIDTH; + #else + uart.reg_width = 1; + #endif } } diff --git a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue index 83caf1089..3e05ed012 100644 --- a/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue +++ b/misc/config_tools/configurator/packages/configurator/src/pages/Config.vue @@ -141,7 +141,8 @@ export default { totalMsg: "", showTotalMessageFlag: false, isSaved:false, - isLoaded:false + isLoaded:false, + serial_console: '', } }, computed: { @@ -350,9 +351,28 @@ export default { } }) }, + getOption(serial_cat){ + return this.schemas.HV.BasicConfigType.definitions.DebugOptionsType.properties[serial_cat]['hidden'] + }, + showOption(serial_cat, show){ + this.schemas.HV.BasicConfigType.definitions.DebugOptionsType.properties[serial_cat]["ui:hidden"]=!show + }, scenarioConfigFormDataUpdate(vmid, data) { if (vmid === -1) { this.scenario.hv = data + this.serial_console = this.scenario.hv.DEBUG_OPTIONS.SERIAL_CONSOLE + let cats = this.getOption('SERIAL_MMIO_REG_WIDTH') + if(cats.length==0){ + this.showOption('SERIAL_MMIO_REG_WIDTH',false) + } + for(let c of cats){ + if(this.serial_console===c){ + this.showOption('SERIAL_MMIO_REG_WIDTH',true) + break + }else{ + this.showOption('SERIAL_MMIO_REG_WIDTH',false) + } + } } else { this.scenario.vm.map((vmConfig, vmIndex) => { if (vmConfig['@id'] === vmid) { diff --git a/misc/config_tools/configurator/pyodide/loadBoard.py b/misc/config_tools/configurator/pyodide/loadBoard.py index 6917bf652..a79fb604f 100644 --- a/misc/config_tools/configurator/pyodide/loadBoard.py +++ b/misc/config_tools/configurator/pyodide/loadBoard.py @@ -14,6 +14,9 @@ from bs4 import BeautifulSoup from . import convert_result, nuc11_board, scenario_json_schema, nuc11_board_path +SERIAL_CATEGORIES = ('portio', 'mmio', 'pci') + + def get_dynamic_scenario(board): """ @@ -34,6 +37,25 @@ def get_dynamic_scenario(board): elements = [(enum_type_convert[obj_type](x[0]), x[1]) for x in elements] return elements + def get_serial(source, options, serial_cat): + elements = [str(e) for e in elementpath.select(source, options) if e][0].strip().split('\n\t') + # seri:/dev/ttyS7 type:mmio base:0x4017000000 irq:16 bdf:"00:1e.0" + serials = {c:[] for c in SERIAL_CATEGORIES} + for el in elements: + t = {} + for e in el.split(' '): + e_ = e.split(':') + k, v = e_[0], e_[1] + t[k] = v + if t['type'] == SERIAL_CATEGORIES[0]: + serials[SERIAL_CATEGORIES[0]].append(t['seri']) + elif t['type'] == SERIAL_CATEGORIES[1] and 'bdf' in t: + serials[SERIAL_CATEGORIES[2]].append(t['seri']) + else: + serials[SERIAL_CATEGORIES[1]].append(t['seri']) + print(serials) + return serials[serial_cat] + def dynamic_enum(**enum_setting): # value from env function, source = [ @@ -50,6 +72,14 @@ def get_dynamic_scenario(board): enum = sorted(enum, key=lambda x: fn(x[0])) return zip(*enum) + def dynamic_serial(**hidden_setting): + function, source = [ + {"get_serial": get_serial, "board_xml": board_xml}[hidden_setting[key]] + for key in ['function', 'source'] + ] + selector, serial_cat = [hidden_setting[key] for key in ['selector', 'serial_cat']] + return function(source, selector, serial_cat) + def dynamic_enum_apply(obj): # get json schema enum obj if 'enum' in obj and isinstance(obj['enum'], dict): @@ -61,6 +91,14 @@ def get_dynamic_scenario(board): enum, enum_names = dynamic_enum(**enum_setting) obj['enum'] = enum obj['enumNames'] = enum_names + + # get json schema hidden + if 'hidden' in obj and isinstance(obj['hidden'], dict): + hidden_setting = obj['hidden'] + if hidden_setting['type'] == 'dynamicSerial': + hidden_setting['type'] = obj.get('type', '') + obj['hidden'] = dynamic_serial(**hidden_setting) + return obj data = json.loads(scenario_json_schema, object_hook=dynamic_enum_apply) diff --git a/misc/config_tools/scenario_config/jsonschema/converter.py b/misc/config_tools/scenario_config/jsonschema/converter.py index 96df5588e..7d89066cd 100644 --- a/misc/config_tools/scenario_config/jsonschema/converter.py +++ b/misc/config_tools/scenario_config/jsonschema/converter.py @@ -371,6 +371,22 @@ class XS2JS: else: js_ele['enum'] = dynamic_enum + # dynamic serial + if '@acrn:hidden' in annotation: + xpath, serial_cat = annotation['@acrn:hidden'].split(',') + if 'dynamicSerial' in self.features: + dynamic_serial = { + 'type': 'dynamicSerial', + 'function': 'get_serial', + 'source': 'board_xml', + 'selector': xpath.strip(), + 'serial_cat': serial_cat.strip(), + } + if 'items' in js_ele: + js_ele['items']['hidden'] = dynamic_serial + else: + js_ele['hidden'] = dynamic_serial + # widget and its options self.convert_widget_config(annotation, js_ele) @@ -424,6 +440,7 @@ def main(): features = [] if not stand_json_schema: features.append('dynamicEnum') + features.append('dynamicSerial') json_schema = XS2JS(schema_file, features).get_json_schema() json_schema = json.dumps(json_schema, indent='\t') diff --git a/misc/config_tools/schema/config.xsd b/misc/config_tools/schema/config.xsd index 2abd668c2..370b90f2e 100644 --- a/misc/config_tools/schema/config.xsd +++ b/misc/config_tools/schema/config.xsd @@ -19,6 +19,13 @@ Select the host serial device used for hypervisor debugging. + + + Select the default register width for serial MMIO. Value can be changed at runtime. + + Select the default log level for log messages stored in memory. Value can be changed at runtime. Log messages with the selected value or lower are displayed. diff --git a/misc/config_tools/schema/types.xsd b/misc/config_tools/schema/types.xsd index 94be5c620..6ed5103c9 100644 --- a/misc/config_tools/schema/types.xsd +++ b/misc/config_tools/schema/types.xsd @@ -118,6 +118,20 @@ higher value (lower severity) are discarded. + + + Register width should be 1 or 4. + + + + + + + + + + + A string specifying the scheduling option: diff --git a/misc/config_tools/xforms/config_common.xsl b/misc/config_tools/xforms/config_common.xsl index 837264cfc..17c3a2362 100644 --- a/misc/config_tools/xforms/config_common.xsl +++ b/misc/config_tools/xforms/config_common.xsl @@ -211,6 +211,7 @@ + @@ -262,6 +263,10 @@ + + + +