Пример #1
0
def pci_read_helper(bus, dev, fn, reg, pci_read_func, bytes=None, mask=~0, shift=0, **extra_args):
    size = bits.addr_alignment(reg)
    if bytes is not None:
        size = bytes

    value = pci_read_func(bus, dev, fn, reg, bytes=size, **extra_args)
    value = (value >> shift) & mask

    desc = "PCI {:#04x}:{:#04x}.{:#03x} ".format(bus, dev, fn)
    if mask == ~0:
        if shift == 0:
            desc += "reg {:#04x} = {:#x}".format(reg, value)
        else:
            desc += "(reg {:#04x}) >> {} = {:#x}".format(reg, shift, value)
    else:
        desc += "((reg {:#04x}) >> {}) & {:#x} = {:#x}".format(reg, shift, mask, value)

    return value, desc
Пример #2
0
def do_pci_write(args, pci_read_func, pci_write_func, **extra_args):
    size = bits.addr_alignment(args.reg)
    if args.bytes is not None:
        size = args.bytes

    args.adj_value = value = (args.value & args.mask) << args.shift
    if args.rmw:
        value = value | (pci_read_func(args.bus, args.dev, args.fn, args.reg, bytes=size, **extra_args) & ~(args.mask << args.shift))
    pci_write_func(args.bus, args.dev, args.fn, args.reg, value, bytes=size, **extra_args)

    args.op = '='
    if args.rmw:
        args.op = '|='
    prefix = "PCI {bus:#04x}:{dev:#04x}.{fn:#03x} reg {reg:#04x} {op}".format(**vars(args))
    if args.mask == ~0:
        if args.shift == 0:
            print prefix, "{value:#x}".format(**vars(args))
        else:
            print prefix, "{value:#x} << {shift} ({adj_value:#x})".format(**vars(args))
    else:
        print prefix, "({value:#x} & {mask}) << {shift} ({adj_value:#x})".format(**vars(args))

    return True