blob: 8aced6fe760b8172221781a166dc2107d8e3484e [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
37struct pci_device*
38 PciAccessImpl::pci_device_next(struct pci_device_iterator* iter) const
39{
40 return ::pci_device_next(iter);
41}
42
43int PciAccessImpl::pci_device_probe(struct pci_device* dev) const
44{
45 return ::pci_device_probe(dev);
46}
47
48int PciAccessImpl::pci_device_map_range(struct pci_device* dev, pciaddr_t base,
49 pciaddr_t size, unsigned map_flags,
50 void** addr) const
51{
52 return ::pci_device_map_range(dev, base, size, map_flags, addr);
53}
54
55int PciAccessImpl::pci_device_unmap_range(struct pci_device* dev, void* memory,
56 pciaddr_t size) const
57{
58 return ::pci_device_unmap_range(dev, memory, size);
59}
60
61PciAccessImpl::PciAccessImpl()
62{
63 int ret = ::pci_system_init();
64 if (ret)
65 {
66 throw std::system_error(ret, std::generic_category(),
67 "Error setting up libpciaccess");
68 }
69}
70
71PciAccessImpl::~PciAccessImpl()
72{
73 ::pci_system_cleanup();
74}
75
76} // namespace host_tool