blob: f3c9e6ea40808ca1b1e6066c881a26007f56b5db [file] [log] [blame]
Benjamin Fair20a18092020-06-08 11:12:21 -07001/*
2 * Copyright 2020 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "pciaccess.hpp"
18
19#include <cstdio>
20#include <cstring>
21#include <system_error>
22
23namespace host_tool
24{
25
26struct pci_device_iterator* PciAccessImpl::pci_id_match_iterator_create(
27 const struct pci_id_match* match) const
28{
29 return ::pci_id_match_iterator_create(match);
30}
31
32void PciAccessImpl::pci_iterator_destroy(struct pci_device_iterator* iter) const
33{
34 return ::pci_iterator_destroy(iter);
35}
36
Vivekanand Veeracholan55b1a712021-02-18 12:06:37 -080037void PciAccessImpl::pci_device_enable(struct pci_device* dev) const
38{
39 return ::pci_device_enable(dev);
40}
41
Benjamin Fair20a18092020-06-08 11:12:21 -070042struct pci_device*
43 PciAccessImpl::pci_device_next(struct pci_device_iterator* iter) const
44{
45 return ::pci_device_next(iter);
46}
47
48int PciAccessImpl::pci_device_probe(struct pci_device* dev) const
49{
50 return ::pci_device_probe(dev);
51}
52
Patrick Williams42a44c22024-08-16 15:21:32 -040053int PciAccessImpl::pci_device_cfg_read_u8(
54 struct pci_device* dev, std::uint8_t* data, pciaddr_t offset) const
Benjamin Fairc1a30c02020-06-09 11:46:34 -070055{
56 return ::pci_device_cfg_read_u8(dev, data, offset);
57}
58
Patrick Williams42a44c22024-08-16 15:21:32 -040059int PciAccessImpl::pci_device_cfg_write_u8(
60 struct pci_device* dev, std::uint8_t data, pciaddr_t offset) const
Benjamin Fairc1a30c02020-06-09 11:46:34 -070061{
62 return ::pci_device_cfg_write_u8(dev, data, offset);
63}
64
Benjamin Fair20a18092020-06-08 11:12:21 -070065int PciAccessImpl::pci_device_map_range(struct pci_device* dev, pciaddr_t base,
66 pciaddr_t size, unsigned map_flags,
67 void** addr) const
68{
69 return ::pci_device_map_range(dev, base, size, map_flags, addr);
70}
71
72int PciAccessImpl::pci_device_unmap_range(struct pci_device* dev, void* memory,
73 pciaddr_t size) const
74{
75 return ::pci_device_unmap_range(dev, memory, size);
76}
77
78PciAccessImpl::PciAccessImpl()
79{
80 int ret = ::pci_system_init();
81 if (ret)
82 {
83 throw std::system_error(ret, std::generic_category(),
84 "Error setting up libpciaccess");
85 }
86}
87
88PciAccessImpl::~PciAccessImpl()
89{
90 ::pci_system_cleanup();
91}
92
93} // namespace host_tool