1 /*
2  * Copyright (c) 2021 Travis Geiselbrecht
3  *
4  * Use of this source code is governed by a MIT-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/MIT
7  */
8 #pragma once
9 
10 #include "pci_backend.h"
11 
12 #include <stdint.h>
13 
14 class pci_bios32 final : public pci_backend {
15 #if ARCH_X86_32
16 public:
17     virtual ~pci_bios32() = default;
18 
19     // factory to detect and create an instance
20     static pci_bios32 *detect();
21 
22     // a few overridden methods
23     virtual int find_pci_device(pci_location_t *state, uint16_t device_id, uint16_t vendor_id, uint16_t index) override;
24     virtual int find_pci_class_code(pci_location_t *state, uint32_t class_code, uint16_t index) override;
25 
26     virtual int read_config_byte(const pci_location_t *state, uint32_t reg, uint8_t *value) override;
27     virtual int read_config_half(const pci_location_t *state, uint32_t reg, uint16_t *value) override;
28     virtual int read_config_word(const pci_location_t *state, uint32_t reg, uint32_t *value) override;
29 
30     virtual int write_config_byte(const pci_location_t *state, uint32_t reg, uint8_t value) override;
31     virtual int write_config_half(const pci_location_t *state, uint32_t reg, uint16_t value) override;
32     virtual int write_config_word(const pci_location_t *state, uint32_t reg, uint32_t value) override;
33 
34     virtual int get_irq_routing_options(irq_routing_options_t *options, uint16_t *pci_irqs) override;
35     virtual int set_irq_hw_int(const pci_location_t *state, uint8_t int_pin, uint8_t irq) override;
36 
37 private:
38     // far call structure used by BIOS32 routines
39     struct bios32_entry {
40         uint32_t offset;
41         uint16_t selector;
42     } __PACKED;
43 
44     // only created via the detect() factory
pci_bios32(bios32_entry b32_entry)45     explicit pci_bios32(bios32_entry b32_entry) : bios32_entry_(b32_entry) {}
46 
47     bios32_entry bios32_entry_ {};
48 
49 #else // !ARCH_X86_32
50 
51     // not present on anything but x86-32
52 public:
53     static pci_bios32 *detect() { return nullptr; }
54 #endif
55 };
56 
57 
58