Problem Description:
Unable to observe updated values in PORTSC[0~3] registers of Fresco Logic FL1100 USB host controller using Python mmap on a Linux machine.
Observed Behavior:
Using setpci, BAR[0~3] addresses obtained successfully. PORTSC[0~3] offsets defined in datasheet. Mmap created to access registers. Register values remain constant (0xa0002a0) despite device connection/disconnection.
The code is the following:
def read_mmio_reg(bar_address, offset):
# Extract the base address from the BAR value (Bits 31:4)
base_address = (bar_address & 0xFFFFFFF0) >> 4
# The size of the memory region you want to map
region_size = 4096 # Adjust this based on your requirements
# Open /dev/mem for memory mapping (requires elevated permissions)
with open('/dev/mem', 'r+b') as mem_file:
# Map the memory region into the process's address space
mmapped_data = mmap.mmap(mem_file.fileno(), region_size, offset=base_address)
# Now, you can access the Host Controller Operational registers within the mapped memory
# For example, read a 32-bit value from offset 0x10 within the mapped region
#offset = 0x10
register_value = int.from_bytes(mmapped_data[offset:offset + 4], byteorder='little')
# Print the value
print("Value at offset {0} = {1}:".format(offset,hex(register_value)))
# Don't forget to unmap the memory when you're done
mmapped_data.close()
return register_value
- The offsets are correct per datasheet.
- mmap function can open with read/write permissions (PROT_READ | PROT_WRITE).