/*
 * Copyright 2020 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "pciaccess.hpp"

#include <cstdio>
#include <cstring>
#include <system_error>

namespace host_tool
{

struct pci_device_iterator* PciAccessImpl::pci_id_match_iterator_create(
    const struct pci_id_match* match) const
{
    return ::pci_id_match_iterator_create(match);
}

void PciAccessImpl::pci_iterator_destroy(struct pci_device_iterator* iter) const
{
    return ::pci_iterator_destroy(iter);
}

void PciAccessImpl::pci_device_enable(struct pci_device* dev) const
{
    return ::pci_device_enable(dev);
}

struct pci_device*
    PciAccessImpl::pci_device_next(struct pci_device_iterator* iter) const
{
    return ::pci_device_next(iter);
}

int PciAccessImpl::pci_device_probe(struct pci_device* dev) const
{
    return ::pci_device_probe(dev);
}

int PciAccessImpl::pci_device_cfg_read_u8(
    struct pci_device* dev, std::uint8_t* data, pciaddr_t offset) const
{
    return ::pci_device_cfg_read_u8(dev, data, offset);
}

int PciAccessImpl::pci_device_cfg_write_u8(
    struct pci_device* dev, std::uint8_t data, pciaddr_t offset) const
{
    return ::pci_device_cfg_write_u8(dev, data, offset);
}

int PciAccessImpl::pci_device_map_range(struct pci_device* dev, pciaddr_t base,
                                        pciaddr_t size, unsigned map_flags,
                                        void** addr) const
{
    return ::pci_device_map_range(dev, base, size, map_flags, addr);
}

int PciAccessImpl::pci_device_unmap_range(struct pci_device* dev, void* memory,
                                          pciaddr_t size) const
{
    return ::pci_device_unmap_range(dev, memory, size);
}

PciAccessImpl::PciAccessImpl()
{
    int ret = ::pci_system_init();
    if (ret)
    {
        throw std::system_error(ret, std::generic_category(),
                                "Error setting up libpciaccess");
    }
}

PciAccessImpl::~PciAccessImpl()
{
    ::pci_system_cleanup();
}

} // namespace host_tool
