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

misc: configurator need to support configurable reg width for UART #8722

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
8 changes: 6 additions & 2 deletions hypervisor/debug/uart16550.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export default {
totalMsg: "",
showTotalMessageFlag: false,
isSaved:false,
isLoaded:false
isLoaded:false,
serial_console: '',
}
},
computed: {
Expand Down Expand Up @@ -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) {
Expand Down
38 changes: 38 additions & 0 deletions misc/config_tools/configurator/pyodide/loadBoard.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
from . import convert_result, nuc11_board, scenario_json_schema, nuc11_board_path


SERIAL_CATEGORIES = ('portio', 'mmio', 'pci')


def get_dynamic_scenario(board):
"""

Expand All @@ -34,6 +37,25 @@ def get_enum(source, options, option_names, obj_type):
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 = [
Expand All @@ -50,6 +72,14 @@ def dynamic_enum(**enum_setting):
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):
Expand All @@ -61,6 +91,14 @@ def dynamic_enum_apply(obj):
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)
Expand Down
17 changes: 17 additions & 0 deletions misc/config_tools/scenario_config/jsonschema/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,22 @@ def xse2jse(self, obj) -> OrderedDict:
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)

Expand Down Expand Up @@ -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')

Expand Down
7 changes: 7 additions & 0 deletions misc/config_tools/schema/config.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
<xs:documentation>Select the host serial device used for hypervisor debugging.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="SERIAL_MMIO_REG_WIDTH" type="RegWidthType" default="1" minOccurs="0">
<xs:annotation acrn:title="Default register width for serial MMIO"
acrn:views="basic"
acrn:hidden="//TTYS_INFO/text(),mmio">
<xs:documentation>Select the default register width for serial MMIO. Value can be changed at runtime.</xs:documentation>
</xs:annotation>
</xs:element>
<xs:element name="MEM_LOGLEVEL" type="LogLevelType" default="5">
<xs:annotation acrn:title="ACRN log level" acrn:views="basic">
<xs:documentation>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.</xs:documentation>
Expand Down
14 changes: 14 additions & 0 deletions misc/config_tools/schema/types.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ higher value (lower severity) are discarded.</xs:documentation>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="RegWidthType">
<xs:annotation>
<xs:documentation>Register width should be 1 or 4.</xs:documentation>
</xs:annotation>
<xs:restriction base="xs:string">
<xs:enumeration value="1">
<xs:annotation acrn:title="1" />
</xs:enumeration>
<xs:enumeration value="4">
<xs:annotation acrn:title="4" />
</xs:enumeration>
</xs:restriction>
</xs:simpleType>

<xs:simpleType name="SchedulerType">
<xs:annotation>
<xs:documentation>A string specifying the scheduling option:
Expand Down
5 changes: 5 additions & 0 deletions misc/config_tools/xforms/config_common.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@

<xsl:template match="SERIAL_CONSOLE">
<xsl:variable name="tokens" select="concat(substring-before(substring-after(/acrn-offline-data/board-data/acrn-config/TTYS_INFO, concat('seri:', current())), '&#xa;'), ' ')" />
<xsl:variable name="mmio_reg_width" select="//config-data/acrn-config/hv/DEBUG_OPTIONS/SERIAL_MMIO_REG_WIDTH" />
<xsl:variable name="type" select="substring-before(substring-after($tokens, 'type:'), ' ')" />
<xsl:variable name="base" select="substring-before(substring-after($tokens, 'base:'), ' ')" />
<xsl:variable name="irq" select="substring-before(substring-after($tokens, 'irq:'), ' ')" />
Expand Down Expand Up @@ -262,6 +263,10 @@
<xsl:with-param name="value" select="$base" />
</xsl:call-template>
</xsl:if>
<xsl:call-template name="integer-by-key-value">
<xsl:with-param name="key" select="'SERIAL_MMIO_REG_WIDTH'" />
<xsl:with-param name="value" select="$mmio_reg_width" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Expand Down