Adds rom expansion BAR.
(&mut self, config: &PciBarConfiguration, active: u32)
| 796 | |
| 797 | /// Adds rom expansion BAR. |
| 798 | pub fn add_pci_rom_bar(&mut self, config: &PciBarConfiguration, active: u32) -> Result<()> { |
| 799 | let bar_idx = config.idx; |
| 800 | let reg_idx = ROM_BAR_REG; |
| 801 | |
| 802 | if self.rom_bar_used { |
| 803 | return Err(Error::RomBarInUse(bar_idx)); |
| 804 | } |
| 805 | |
| 806 | if !config.size.is_power_of_two() { |
| 807 | return Err(Error::RomBarSizeInvalid(config.size)); |
| 808 | } |
| 809 | |
| 810 | if bar_idx != ROM_BAR_IDX { |
| 811 | return Err(Error::RomBarInvalid(bar_idx)); |
| 812 | } |
| 813 | |
| 814 | let end_addr = config |
| 815 | .addr |
| 816 | .checked_add(config.size - 1) |
| 817 | .ok_or(Error::RomBarAddressInvalid(config.addr, config.size))?; |
| 818 | |
| 819 | if end_addr > u64::from(u32::MAX) { |
| 820 | return Err(Error::RomBarAddressInvalid(config.addr, config.size)); |
| 821 | } |
| 822 | |
| 823 | self.registers[reg_idx] = (config.addr as u32) | active; |
| 824 | self.writable_bits[reg_idx] = ROM_BAR_ADDR_MASK; |
| 825 | self.rom_bar_addr = self.registers[reg_idx]; |
| 826 | self.rom_bar_size = |
| 827 | encode_32_bits_bar_size(config.size as u32).ok_or(Error::Encode32BarSize)?; |
| 828 | self.rom_bar_used = true; |
| 829 | |
| 830 | Ok(()) |
| 831 | } |
| 832 | |
| 833 | /// Returns the address of the given BAR region. |
| 834 | pub fn get_bar_addr(&self, bar_num: usize) -> u64 { |
no test coverage detected