Skip to content

Commit

Permalink
Add device address parameter for s390x
Browse files Browse the repository at this point in the history
Signed-off-by: Xujun Ma <[email protected]>
  • Loading branch information
maxujun committed Dec 20, 2024
1 parent 80ca89f commit e6f0fc6
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 4 deletions.
6 changes: 2 additions & 4 deletions virttest/qemu_devices/qcontainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1699,9 +1699,7 @@ def machine_s390_virtio(machine_params):
# can't be used.
LOG.warning("Support for s390x is highly experimental!")
bus = (
qdevices.QNoAddrCustomBus(
"bus",
[["addr"], [32]],
qdevices.QCSSBus(
"virtual-css",
"virtual-css",
"virtual-css",
Expand Down Expand Up @@ -2475,7 +2473,7 @@ def define_hbas(
if scsi_hba == "virtio-scsi-device":
pci_bus = {"type": "virtio-bus"}
elif scsi_hba == "virtio-scsi-ccw":
pci_bus = None
pci_bus = {"type": "virtual-css"}
elif scsi_hba == "spapr-vscsi":
addr_spec = [64, 32]
pci_bus = None
Expand Down
54 changes: 54 additions & 0 deletions virttest/qemu_devices/qdevices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3983,3 +3983,57 @@ def _cmdline_raw(self):
# -machine allows empty line
return ""
return super()._cmdline_raw()


class QCSSBus(QSparseBus):

"""
CSS Bus representation (bus&ssid&devno, uses hex digits)
"""

def __init__(self, busid, bus_type, aobject):
"""bus&ssid&devno, 4 ssid and 65536 device numbers"""
super(QCSSBus, self).__init__(
"bus", [["ssid", "devno"], [4, 65536]], busid, bus_type, aobject
)

@staticmethod
def _addr2stor(addr):
"""
Converts internal addr to storable/hashable address
:param addr: internal address [addr1, addr2, ...]
:return: storable address "addr1-addr2-..."
"""
out = ""
for value in addr:
if value is None:
out += "*-"
else:
out += "%s-" % value
if out:
return out[:-1]
else:
return "*"

def _dev2addr(self, device):
"""Read the values in base of 16 (hex)"""
addr = device.get_param("addr")
if isinstance(addr, int): # only addr
return [0, addr]
elif not addr: # not defined
return [0, None]
elif isinstance(addr, six.string_types): # addr or ssid.addr
addr = [int(_, 16) for _ in addr.split(".", 1)]
if len(addr) < 2: # only addr
addr.insert(0, 0)
return addr

def _set_device_props(self, device, addr):
"""Convert addr to the format used by qtree"""
if device.get_param("addr"):
del device.params["addr"]
device.set_param("devno", "fe.%s.%s" % (hex(addr[0])[2:], f"{addr[1]:04x}"))

def _update_device_props(self, device, addr):
"""Always set properties"""
self._set_device_props(device, addr)

0 comments on commit e6f0fc6

Please sign in to comment.