diff options
Diffstat (limited to 'rsnix/src/pci.rs')
| -rw-r--r-- | rsnix/src/pci.rs | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/rsnix/src/pci.rs b/rsnix/src/pci.rs index 21d7536..b9c2265 100644 --- a/rsnix/src/pci.rs +++ b/rsnix/src/pci.rs | |||
| @@ -46,25 +46,25 @@ fn inl(port: u16) -> u32 { | |||
| 46 | val | 46 | val |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | /// Read a dword from a device's config space (`reg` must be dword-aligned). | 49 | /// Encode the PCI config-space port address for (bus, dev, fn, reg); |
| 50 | pub fn config_read(bus: u8, device: u8, func: u8, reg: u8) -> u32 { | 50 | /// `reg` must be dword-aligned. |
| 51 | let addr = 0x8000_0000 | 51 | fn config_addr(bus: u8, device: u8, func: u8, reg: u8) -> u32 { |
| 52 | 0x8000_0000 | ||
| 52 | | ((bus as u32) << 16) | 53 | | ((bus as u32) << 16) |
| 53 | | ((device as u32) << 11) | 54 | | ((device as u32) << 11) |
| 54 | | ((func as u32) << 8) | 55 | | ((func as u32) << 8) |
| 55 | | ((reg as u32) & 0xFC); | 56 | | ((reg as u32) & 0xFC) |
| 56 | outl(CONFIG_ADDRESS, addr); | 57 | } |
| 58 | |||
| 59 | /// Read a dword from a device's config space (`reg` must be dword-aligned). | ||
| 60 | pub fn config_read(bus: u8, device: u8, func: u8, reg: u8) -> u32 { | ||
| 61 | outl(CONFIG_ADDRESS, config_addr(bus, device, func, reg)); | ||
| 57 | inl(CONFIG_DATA) | 62 | inl(CONFIG_DATA) |
| 58 | } | 63 | } |
| 59 | 64 | ||
| 60 | /// Write a dword to a device's config space (`reg` must be dword-aligned). | 65 | /// Write a dword to a device's config space (`reg` must be dword-aligned). |
| 61 | pub fn config_write(bus: u8, device: u8, func: u8, reg: u8, val: u32) { | 66 | pub fn config_write(bus: u8, device: u8, func: u8, reg: u8, val: u32) { |
| 62 | let addr = 0x8000_0000 | 67 | outl(CONFIG_ADDRESS, config_addr(bus, device, func, reg)); |
| 63 | | ((bus as u32) << 16) | ||
| 64 | | ((device as u32) << 11) | ||
| 65 | | ((func as u32) << 8) | ||
| 66 | | ((reg as u32) & 0xFC); | ||
| 67 | outl(CONFIG_ADDRESS, addr); | ||
| 68 | outl(CONFIG_DATA, val) | 68 | outl(CONFIG_DATA, val) |
| 69 | } | 69 | } |
| 70 | 70 | ||
| @@ -83,7 +83,11 @@ pub fn bar64(bus: u8, device: u8, func: u8, bar_index: u8) -> Option<u64> { | |||
| 83 | 0 | 83 | 0 |
| 84 | }; | 84 | }; |
| 85 | let base = ((hi as u64) << 32) | (lo as u64 & 0xFFFF_FFF0); | 85 | let base = ((hi as u64) << 32) | (lo as u64 & 0xFFFF_FFF0); |
| 86 | if base == 0 { None } else { Some(base) } | 86 | if base == 0 { |
| 87 | None | ||
| 88 | } else { | ||
| 89 | Some(base) | ||
| 90 | } | ||
| 87 | } | 91 | } |
| 88 | 92 | ||
| 89 | /// Enumerate every device/function present on all buses. | 93 | /// Enumerate every device/function present on all buses. |
