ostd/bus/pci/capability/vendor.rs
1// SPDX-License-Identifier: MPL-2.0
2//! Vendor-specific capability support.
3use vstd::prelude::*;
4
5use crate::{
6 /*Error, Result,*/
7 bus::pci::{/*common_device::PciCommonDevice,*/ device_info::PciDeviceLocation},
8};
9
10/// Vendor specific capability. Users can access this capability area at will,
11/// except for the PCI configuration space which cannot be accessed at will through this structure.
12#[verus_verify]
13#[derive(Debug, Copy, Clone, PartialEq, Eq)]
14pub struct CapabilityVndrData {
15 location: PciDeviceLocation,
16 cap_ptr: u16,
17 length: u16,
18}
19/*
20impl CapabilityVndrData {
21 pub(super) fn new(dev: &PciCommonDevice, cap_ptr: u16, length: u16) -> Self {
22 Self {
23 location: *dev.location(),
24 cap_ptr,
25 length,
26 }
27 }
28}
29
30*/
31
32#[verus_verify]
33impl CapabilityVndrData {
34 /// The length of this capability
35 #[expect(clippy::len_without_is_empty)]
36 #[verus_verify(dual_spec)]
37 #[verus_spec(returns self.len())]
38 pub fn len(&self) -> u16 {
39 self.length
40 }
41}
42
43/*
44impl CapabilityVndrData {
45 /// Reads u8 from the capability.
46 pub fn read8(&self, offset: u16) -> Result<u8> {
47 self.check_range(offset)?;
48 Ok(self.location.read8(self.cap_ptr + offset))
49 }
50
51 /// Writes u8 to the capability.
52 pub fn write8(&self, offset: u16, value: u8) -> Result<()> {
53 self.check_range(offset)?;
54 self.location.write8(self.cap_ptr + offset, value);
55 Ok(())
56 }
57
58 /// Reads u16 from the capability.
59 pub fn read16(&self, offset: u16) -> Result<u16> {
60 self.check_range(offset)?;
61 Ok(self.location.read16(self.cap_ptr + offset))
62 }
63
64 /// Writes u16 to the capability.
65 pub fn write16(&self, offset: u16, value: u16) -> Result<()> {
66 self.check_range(offset)?;
67 self.location.write16(self.cap_ptr + offset, value);
68 Ok(())
69 }
70
71 /// Reads u32 from the capability.
72 pub fn read32(&self, offset: u16) -> Result<u32> {
73 self.check_range(offset)?;
74 Ok(self.location.read32(self.cap_ptr + offset))
75 }
76
77 /// Writes u32 to the capability.
78 pub fn write32(&self, offset: u16, value: u32) -> Result<()> {
79 self.check_range(offset)?;
80 self.location.write32(self.cap_ptr + offset, value);
81 Ok(())
82 }
83
84 fn check_range(&self, offset: u16) -> Result<()> {
85 if self.length < offset {
86 return Err(Error::InvalidArgs);
87 }
88 Ok(())
89 }
90}
91*/