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 read_config_byte(pci_location_t state, uint32_t reg, uint8_t *value) override;
24     virtual int read_config_half(pci_location_t state, uint32_t reg, uint16_t *value) override;
25     virtual int read_config_word(pci_location_t state, uint32_t reg, uint32_t *value) override;
26 
27     virtual int write_config_byte(pci_location_t state, uint32_t reg, uint8_t value) override;
28     virtual int write_config_half(pci_location_t state, uint32_t reg, uint16_t value) override;
29     virtual int write_config_word(pci_location_t state, uint32_t reg, uint32_t value) override;
30 
31 private:
32     // far call structure used by BIOS32 routines
33     struct bios32_entry {
34         uint32_t offset;
35         uint16_t selector;
36     } __PACKED;
37 
38     // only created via the detect() factory
pci_bios32(bios32_entry b32_entry)39     explicit pci_bios32(bios32_entry b32_entry) : bios32_entry_(b32_entry) {}
40 
41     bios32_entry bios32_entry_ {};
42 
43 #else // !ARCH_X86_32
44 
45     // not present on anything but x86-32
46 public:
47     static pci_bios32 *detect() { return nullptr; }
48 #endif
49 };
50 
51 
52