source: mainline/uspace/drv/bus/pci/pciintel/pci.h@ 832cbe7

Last change on this file since 832cbe7 was 832cbe7, checked in by Jiri Svoboda <jiri@…>, 5 months ago

Add proper IDE PCI to ISA fallback mechanism.

To determine if legacy IDE I/O ports are free, isa-ide asks isa,
who asks pciintel. pciintel waits for bus enumeration to complete,
then waits for all functions except the one who is asking
(which is ISA bus) to stabilize. During attach pci-ide will claim
the legacy IDE ports. Thus, if at this point legacy IDE ports
are unclaimed, pciintel tells ISA they are free, which tells isa-ide,
which continues to attach. If they are not free, isa-ide will not
attach.

This works for all use cases, including system without PCI bus,
system with PCI bus, but no (or disabled) PCI IDE, system with PCI
IDE with unrecognized VID/PID (which we will handle in legacy ISA mode).

  • Property mode set to 100644
File size: 3.8 KB
RevLine 
[8c06905]1/*
[832cbe7]2 * Copyright (c) 2025 Jiri Svoboda
[663f41c4]3 * Copyright (c) 2010 Lenka Trochtova
[8c06905]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
[663f41c4]36#ifndef PCI_H_
37#define PCI_H_
[5e598e0]38
[7acd787]39#include <adt/list.h>
40#include <ddi.h>
[af6b5157]41#include <ddf/driver.h>
[7acd787]42#include <fibril_synch.h>
[832cbe7]43#include <stdbool.h>
[3a5909f]44
[1b20da0]45#define PCI_MAX_HW_RES 10
[3a5909f]46
[97a62fe]47typedef struct pciintel_bus {
48 /** DDF device node */
[83a2f43]49 ddf_dev_t *dnode;
[46eb2c4]50 ioport32_t *conf_addr_reg;
51 ioport32_t *conf_data_reg;
[92d5279]52 ioport32_t *conf_space;
[6dbc500]53 pio_window_t pio_win;
[97a62fe]54 fibril_mutex_t conf_mutex;
[7acd787]55 /** List of functions (of pci_fun_t) */
56 list_t funs;
[832cbe7]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;
[97a62fe]65} pci_bus_t;
66
[8b1e15ac]67typedef struct pci_fun_data {
[97a62fe]68 pci_bus_t *busptr;
[83a2f43]69 ddf_fun_t *fnode;
[7acd787]70 /** Link to @c busptr->funs */
71 link_t lfuns;
[68414f4a]72
[8c06905]73 int bus;
74 int dev;
75 int fn;
[c90aed4]76 uint16_t vendor_id;
77 uint16_t device_id;
78 uint16_t command;
[1d53a78]79 uint8_t class_code;
80 uint8_t subclass_code;
81 uint8_t prog_if;
82 uint8_t revision;
[832cbe7]83 bool querying;
[5e598e0]84 hw_resource_list_t hw_resources;
[992b47ea]85 hw_resource_t resources[PCI_MAX_HW_RES];
[6dbc500]86 pio_window_t pio_window;
[68414f4a]87} pci_fun_t;
88
[7acd787]89extern pci_bus_t *pci_bus(ddf_dev_t *);
90
[68414f4a]91extern void pci_fun_create_match_ids(pci_fun_t *);
[7acd787]92extern pci_fun_t *pci_fun_first(pci_bus_t *);
93extern pci_fun_t *pci_fun_next(pci_fun_t *);
[3a5909f]94
[68414f4a]95extern uint8_t pci_conf_read_8(pci_fun_t *, int);
96extern uint16_t pci_conf_read_16(pci_fun_t *, int);
97extern uint32_t pci_conf_read_32(pci_fun_t *, int);
98extern void pci_conf_write_8(pci_fun_t *, int, uint8_t);
99extern void pci_conf_write_16(pci_fun_t *, int, uint16_t);
100extern void pci_conf_write_32(pci_fun_t *, int, uint32_t);
[3a5909f]101
[68414f4a]102extern void pci_add_range(pci_fun_t *, uint64_t, size_t, bool);
103extern int pci_read_bar(pci_fun_t *, int);
104extern void pci_read_interrupt(pci_fun_t *);
105extern void pci_add_interrupt(pci_fun_t *, int);
[3a5909f]106
[97a62fe]107extern pci_fun_t *pci_fun_new(pci_bus_t *);
[68414f4a]108extern void pci_fun_init(pci_fun_t *, int, int, int);
109extern void pci_fun_delete(pci_fun_t *);
[97a62fe]110extern char *pci_fun_create_name(pci_fun_t *);
[3a5909f]111
[184f2f8a]112extern errno_t pci_bus_scan(pci_bus_t *, int);
[5e598e0]113
[68414f4a]114extern bool pci_alloc_resource_list(pci_fun_t *);
115extern void pci_clean_resource_list(pci_fun_t *);
[5e598e0]116
[68414f4a]117extern void pci_read_bars(pci_fun_t *);
[713a4b9]118extern size_t pci_bar_mask_to_size(uint32_t);
[8c06905]119
120#endif
121
122/**
123 * @}
[230385c]124 */
Note: See TracBrowser for help on using the repository browser.