[8c06905] | 1 | /*
|
---|
[663f41c4] | 2 | * Copyright (c) 2010 Lenka Trochtova
|
---|
[68414f4a] | 3 | * Copyright (c) 2011 Jiri Svoboda
|
---|
[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 |
|
---|
[af6b5157] | 39 | #include <ddf/driver.h>
|
---|
[3a5909f] | 40 | #include "pci_regs.h"
|
---|
| 41 |
|
---|
[6dbc500] | 42 | #define PCI_MAX_HW_RES 10
|
---|
[3a5909f] | 43 |
|
---|
[97a62fe] | 44 | typedef struct pciintel_bus {
|
---|
| 45 | /** DDF device node */
|
---|
[83a2f43] | 46 | ddf_dev_t *dnode;
|
---|
[46eb2c4] | 47 | ioport32_t *conf_addr_reg;
|
---|
| 48 | ioport32_t *conf_data_reg;
|
---|
[6dbc500] | 49 | pio_window_t pio_win;
|
---|
[97a62fe] | 50 | fibril_mutex_t conf_mutex;
|
---|
| 51 | } pci_bus_t;
|
---|
| 52 |
|
---|
[8b1e15ac] | 53 | typedef struct pci_fun_data {
|
---|
[97a62fe] | 54 | pci_bus_t *busptr;
|
---|
[83a2f43] | 55 | ddf_fun_t *fnode;
|
---|
[68414f4a] | 56 |
|
---|
[8c06905] | 57 | int bus;
|
---|
| 58 | int dev;
|
---|
| 59 | int fn;
|
---|
[c90aed4] | 60 | uint16_t vendor_id;
|
---|
| 61 | uint16_t device_id;
|
---|
| 62 | uint16_t command;
|
---|
[1d53a78] | 63 | uint8_t class_code;
|
---|
| 64 | uint8_t subclass_code;
|
---|
| 65 | uint8_t prog_if;
|
---|
| 66 | uint8_t revision;
|
---|
[5e598e0] | 67 | hw_resource_list_t hw_resources;
|
---|
[992b47ea] | 68 | hw_resource_t resources[PCI_MAX_HW_RES];
|
---|
[6dbc500] | 69 | pio_window_t pio_window;
|
---|
[68414f4a] | 70 | } pci_fun_t;
|
---|
| 71 |
|
---|
| 72 | extern void pci_fun_create_match_ids(pci_fun_t *);
|
---|
[3a5909f] | 73 |
|
---|
[68414f4a] | 74 | extern uint8_t pci_conf_read_8(pci_fun_t *, int);
|
---|
| 75 | extern uint16_t pci_conf_read_16(pci_fun_t *, int);
|
---|
| 76 | extern uint32_t pci_conf_read_32(pci_fun_t *, int);
|
---|
| 77 | extern void pci_conf_write_8(pci_fun_t *, int, uint8_t);
|
---|
| 78 | extern void pci_conf_write_16(pci_fun_t *, int, uint16_t);
|
---|
| 79 | extern void pci_conf_write_32(pci_fun_t *, int, uint32_t);
|
---|
[3a5909f] | 80 |
|
---|
[68414f4a] | 81 | extern void pci_add_range(pci_fun_t *, uint64_t, size_t, bool);
|
---|
| 82 | extern int pci_read_bar(pci_fun_t *, int);
|
---|
| 83 | extern void pci_read_interrupt(pci_fun_t *);
|
---|
| 84 | extern void pci_add_interrupt(pci_fun_t *, int);
|
---|
[3a5909f] | 85 |
|
---|
[97a62fe] | 86 | extern pci_fun_t *pci_fun_new(pci_bus_t *);
|
---|
[68414f4a] | 87 | extern void pci_fun_init(pci_fun_t *, int, int, int);
|
---|
| 88 | extern void pci_fun_delete(pci_fun_t *);
|
---|
[97a62fe] | 89 | extern char *pci_fun_create_name(pci_fun_t *);
|
---|
[3a5909f] | 90 |
|
---|
[68414f4a] | 91 | extern void pci_bus_scan(pci_bus_t *, int);
|
---|
[5e598e0] | 92 |
|
---|
[68414f4a] | 93 | extern bool pci_alloc_resource_list(pci_fun_t *);
|
---|
| 94 | extern void pci_clean_resource_list(pci_fun_t *);
|
---|
[5e598e0] | 95 |
|
---|
[68414f4a] | 96 | extern void pci_read_bars(pci_fun_t *);
|
---|
[713a4b9] | 97 | extern size_t pci_bar_mask_to_size(uint32_t);
|
---|
[8c06905] | 98 |
|
---|
| 99 | #endif
|
---|
| 100 |
|
---|
| 101 | /**
|
---|
| 102 | * @}
|
---|
[230385c] | 103 | */
|
---|