/*
 * 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.
 */

#pragma once

extern "C"
{
#include <pciaccess.h>
} // extern "C"

#include <cstdint>

namespace host_tool
{

/**
 * @class PciAccess
 * @brief Overridable interface to libpciacess for unit testing
 */
class PciAccess
{
  public:
    virtual struct pci_device_iterator* pci_id_match_iterator_create(
        const struct pci_id_match* match) const = 0;
    virtual void
        pci_iterator_destroy(struct pci_device_iterator* iter) const = 0;
    virtual void pci_device_enable(struct pci_device* dev) const = 0;
    virtual struct pci_device*
        pci_device_next(struct pci_device_iterator* iter) const = 0;
    virtual int pci_device_probe(struct pci_device* dev) const = 0;
    virtual int pci_device_cfg_read_u8(
        struct pci_device* dev, std::uint8_t* data, pciaddr_t offset) const = 0;
    virtual int pci_device_cfg_write_u8(
        struct pci_device* dev, std::uint8_t data, pciaddr_t offset) const = 0;
    virtual int pci_device_map_range(struct pci_device* dev, pciaddr_t base,
                                     pciaddr_t size, unsigned map_flags,
                                     void** addr) const = 0;
    virtual int pci_device_unmap_range(struct pci_device* dev, void* memory,
                                       pciaddr_t size) const = 0;

    virtual ~PciAccess() = default;
};

/**
 * @class PciAccessImpl
 * @brief libpciaccess concrete implementation
 * @details Passes through all calls to the underlying library.
 */
class PciAccessImpl : public PciAccess
{
  public:
    struct pci_device_iterator* pci_id_match_iterator_create(
        const struct pci_id_match* match) const override;
    void pci_iterator_destroy(struct pci_device_iterator* iter) const override;
    void pci_device_enable(struct pci_device* dev) const override;
    struct pci_device*
        pci_device_next(struct pci_device_iterator* iter) const override;
    int pci_device_probe(struct pci_device* dev) const override;
    int pci_device_cfg_read_u8(struct pci_device* dev, std::uint8_t* data,
                               pciaddr_t offset) const override;
    int pci_device_cfg_write_u8(struct pci_device* dev, std::uint8_t data,
                                pciaddr_t offset) const override;
    int pci_device_map_range(struct pci_device* dev, pciaddr_t base,
                             pciaddr_t size, unsigned map_flags,
                             void** addr) const override;
    int pci_device_unmap_range(struct pci_device* dev, void* memory,
                               pciaddr_t size) const override;

    static PciAccessImpl& getInstance()
    {
        static PciAccessImpl instance;
        return instance;
    }

  private:
    PciAccessImpl();
    virtual ~PciAccessImpl();
};

} // namespace host_tool
