Created
September 24, 2022 19:48
-
-
Save patrickschur/b0feaaea79595c4d632bc7fffb2774c6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import struct | |
SMN_INDEX_REG = 0x60 | |
SMN_DATA_REG = 0x64 | |
SMN_MSG_REG = 0x3b10a20 | |
SMN_RSP_REG = 0x3b10a80 | |
SMN_ARG_REG = 0x3b10a88 | |
SMN_STATUS_OK = 1 | |
SKIP_COMMANDS = [] | |
config = os.open('/sys/devices/pci0000:00/0000:00:00.0/config', os.O_RDWR) | |
def smn_read(address): | |
os.pwrite(config, struct.pack('I', address), SMN_INDEX_REG) | |
return struct.unpack('I', os.pread(config, 4, SMN_DATA_REG))[0] | |
def smn_write(address, data): | |
os.pwrite(config, struct.pack('I', address), SMN_INDEX_REG) | |
os.pwrite(config, struct.pack('I', data), SMN_DATA_REG) | |
def smn_send_msg(msg, *args): | |
status = 0 | |
smn_write(SMN_RSP_REG, status) | |
for j, arg in enumerate(args): | |
smn_write(SMN_ARG_REG + (j << 2), arg) | |
smn_write(SMN_MSG_REG, msg) | |
while (status := smn_read(SMN_RSP_REG)) == 0: | |
pass | |
if status != SMN_STATUS_OK: | |
return [status] | |
return [smn_read(SMN_ARG_REG + (k << 2)) for k in range(5)] | |
for i in range(1, 192): | |
if i not in SKIP_COMMANDS: | |
r = [hex(v) for v in smn_send_msg(i, 0, 0)] | |
print(f'{i:02x}: {r}') | |
os.close(config) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment