1 | /*
|
---|
2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
3 | * Copyright (c) 2010 Lenka Trochtova
|
---|
4 | * All rights reserved.
|
---|
5 | *
|
---|
6 | * Redistribution and use in source and binary forms, with or without
|
---|
7 | * modification, are permitted provided that the following conditions
|
---|
8 | * are met:
|
---|
9 | *
|
---|
10 | * - Redistributions of source code must retain the above copyright
|
---|
11 | * notice, this list of conditions and the following disclaimer.
|
---|
12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
13 | * notice, this list of conditions and the following disclaimer in the
|
---|
14 | * documentation and/or other materials provided with the distribution.
|
---|
15 | * - The name of the author may not be used to endorse or promote products
|
---|
16 | * derived from this software without specific prior written permission.
|
---|
17 | *
|
---|
18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
28 | */
|
---|
29 |
|
---|
30 | /** @addtogroup pciintel
|
---|
31 | * @{
|
---|
32 | */
|
---|
33 | /** @file
|
---|
34 | */
|
---|
35 |
|
---|
36 | #ifndef PCI_H_
|
---|
37 | #define PCI_H_
|
---|
38 |
|
---|
39 | #include <adt/list.h>
|
---|
40 | #include <ddi.h>
|
---|
41 | #include <ddf/driver.h>
|
---|
42 | #include <fibril_synch.h>
|
---|
43 | #include <stdbool.h>
|
---|
44 |
|
---|
45 | #define PCI_MAX_HW_RES 10
|
---|
46 |
|
---|
47 | typedef struct pciintel_bus {
|
---|
48 | /** DDF device node */
|
---|
49 | ddf_dev_t *dnode;
|
---|
50 | ioport32_t *conf_addr_reg;
|
---|
51 | ioport32_t *conf_data_reg;
|
---|
52 | ioport32_t *conf_space;
|
---|
53 | pio_window_t pio_win;
|
---|
54 | fibril_mutex_t conf_mutex;
|
---|
55 | /** List of functions (of pci_fun_t) */
|
---|
56 | list_t funs;
|
---|
57 | /** Enumeration is done */
|
---|
58 | bool enum_done;
|
---|
59 | /** Synchronize enum_done */
|
---|
60 | fibril_mutex_t enum_done_lock;
|
---|
61 | /** Signal change to enum_done */
|
---|
62 | fibril_condvar_t enum_done_cv;
|
---|
63 | /** @c true iff legacy IDE range is claimed by PCI IDE driver */
|
---|
64 | bool leg_ide_claimed;
|
---|
65 | } pci_bus_t;
|
---|
66 |
|
---|
67 | typedef struct pci_fun_data {
|
---|
68 | pci_bus_t *busptr;
|
---|
69 | ddf_fun_t *fnode;
|
---|
70 | /** Link to @c busptr->funs */
|
---|
71 | link_t lfuns;
|
---|
72 |
|
---|
73 | int bus;
|
---|
74 | int dev;
|
---|
75 | int fn;
|
---|
76 | uint16_t vendor_id;
|
---|
77 | uint16_t device_id;
|
---|
78 | uint16_t command;
|
---|
79 | uint8_t class_code;
|
---|
80 | uint8_t subclass_code;
|
---|
81 | uint8_t prog_if;
|
---|
82 | uint8_t revision;
|
---|
83 | bool querying;
|
---|
84 | hw_resource_list_t hw_resources;
|
---|
85 | hw_resource_t resources[PCI_MAX_HW_RES];
|
---|
86 | pio_window_t pio_window;
|
---|
87 | } pci_fun_t;
|
---|
88 |
|
---|
89 | extern pci_bus_t *pci_bus(ddf_dev_t *);
|
---|
90 |
|
---|
91 | extern void pci_fun_create_match_ids(pci_fun_t *);
|
---|
92 | extern pci_fun_t *pci_fun_first(pci_bus_t *);
|
---|
93 | extern pci_fun_t *pci_fun_next(pci_fun_t *);
|
---|
94 |
|
---|
95 | extern uint8_t pci_conf_read_8(pci_fun_t *, int);
|
---|
96 | extern uint16_t pci_conf_read_16(pci_fun_t *, int);
|
---|
97 | extern uint32_t pci_conf_read_32(pci_fun_t *, int);
|
---|
98 | extern void pci_conf_write_8(pci_fun_t *, int, uint8_t);
|
---|
99 | extern void pci_conf_write_16(pci_fun_t *, int, uint16_t);
|
---|
100 | extern void pci_conf_write_32(pci_fun_t *, int, uint32_t);
|
---|
101 |
|
---|
102 | extern void pci_add_range(pci_fun_t *, uint64_t, size_t, bool);
|
---|
103 | extern int pci_read_bar(pci_fun_t *, int);
|
---|
104 | extern void pci_read_interrupt(pci_fun_t *);
|
---|
105 | extern void pci_add_interrupt(pci_fun_t *, int);
|
---|
106 |
|
---|
107 | extern pci_fun_t *pci_fun_new(pci_bus_t *);
|
---|
108 | extern void pci_fun_init(pci_fun_t *, int, int, int);
|
---|
109 | extern void pci_fun_delete(pci_fun_t *);
|
---|
110 | extern char *pci_fun_create_name(pci_fun_t *);
|
---|
111 |
|
---|
112 | extern errno_t pci_bus_scan(pci_bus_t *, int);
|
---|
113 |
|
---|
114 | extern bool pci_alloc_resource_list(pci_fun_t *);
|
---|
115 | extern void pci_clean_resource_list(pci_fun_t *);
|
---|
116 |
|
---|
117 | extern void pci_read_bars(pci_fun_t *);
|
---|
118 | extern size_t pci_bar_mask_to_size(uint32_t);
|
---|
119 |
|
---|
120 | #endif
|
---|
121 |
|
---|
122 | /**
|
---|
123 | * @}
|
---|
124 | */
|
---|