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 class pci_ecam final : public pci_backend {
13 public:
14     virtual ~pci_ecam();
15 
16     // factory to detect and create an instance
17     static pci_ecam *detect(paddr_t ecam_base, uint16_t segment, uint8_t start_bus, uint8_t end_bus);
18 
19     // a few overridden methods
20     int read_config_byte(const pci_location_t *state, uint32_t reg, uint8_t *value) override;
21     int read_config_half(const pci_location_t *state, uint32_t reg, uint16_t *value) override;
22     int read_config_word(const pci_location_t *state, uint32_t reg, uint32_t *value) override;
23     int write_config_byte(const pci_location_t *state, uint32_t reg, uint8_t value) override;
24     int write_config_half(const pci_location_t *state, uint32_t reg, uint16_t value) override;
25     int write_config_word(const pci_location_t *state, uint32_t reg, uint32_t value) override;
26 
27 private:
28     // only created via the detect() factory
29     pci_ecam(paddr_t base, uint16_t segment, uint8_t start_bus, uint8_t end_bus);
30 
31     // allocate vm resources for the object
32     status_t initialize();
33 
34     paddr_t base_;
35     uint16_t segment_;
36     uint16_t start_bus_;
37     uint16_t end_bus_;
38 
39     // vm region where the ecam is mapped
40     uint8_t *ecam_ptr_ = nullptr;
41 };
42 
43