ok I'm sorry but please bear with me; I'm a little bit stupid. I try to read the BAR with this function
Code:
fn pci_config_read_word(bus: u16, slot: u16, func: u16, offset: u16) -> u16 {
let lbus = bus as u32;
let lslot = slot as u32;
let lfunc = func as u32;
let loffset = offset as u32;
// create config address
let address = ((lbus << 16) | (lslot << 11)) as u32 | (lfunc << 8) | (loffset & 0xfc) | 0x80000000 as u32;
dbgln!("pci address: {}", address);
// write the address
unsafe { u32::io_out(0xCF8, address) };
// read the data
unsafe { ((u32::io_in(0xCFC) >> ((offset & 2) * 8)) & 0xffff) as u16 }
}
invoked like this
Code:
let bar_addr = (pci_config_read_word(bus, slot, 0, (0x3c | 0x0)) & 0x000000000000ff00) as u64;
When I do and I attempt to cast the address to an HBA_MEM structure, it's filled in with all zeros like this
Code:
tagHBA_MEM {
cap: 0,
ghc: 0,
is: 0,
pi: 0,
vs: 0,
ccc_ctl: 0,
ccc_pts: 0,
em_loc: 0,
em_ctl: 0,
cap2: 0,
bohc: 0,
rsv: [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
vendor: [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
ports: [
tagHBA_PORT {
clb: 0,
clbu: 0,
fb: 0,
fbu: 0,
is: 0,
ie: 0,
cmd: 0,
rsv0: 0,
tfd: 0,
sig: 0,
ssts: 0,
sctl: 0,
serr: 0,
sact: 0,
ci: 0,
sntf: 0,
fbs: 0,
rsv1: [
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
],
vendor: [
0,
0,
0,
0,
],
},
],
}
Am I doing this right? I know that this is rust but it should(??) be readable even if you don't know it