1/**
2 * \file
3 * \brief Library to be used in PCI drivers to use PCI functionality.
4 */
5
6/*
7 * Copyright (c) 2018 ETH Zurich.
8 * All rights reserved.
9 *
10 * This file is distributed under the terms in the attached LICENSE file.
11 * If you do not find this file, copies can be found by writing to:
12 * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
13 */
14#ifndef PCI_DRIVER_CLIENT_H
15#define PCI_DRIVER_CLIENT_H
16
17#include <pci/pci_types.h>
18#include <barrelfish/caddr.h>
19#include <int_route/int_model.h>
20
21struct waitset;
22
23typedef void (*interrupt_handler_fn)(void *);
24
25struct pcid {
26    // Derived from initialization
27    struct waitset * ws;
28    struct pci_addr addr;
29    struct pci_id id;
30    struct pci_class cls;
31    struct int_startup_argument int_arg;
32    size_t num_bars;
33
34    //
35    struct cnoderef arg_cnode; // CNode (in local cspace) containing the passed caps
36};
37
38/**
39 * initialize the pci driver client.
40 * \param ws Used for the pci_driver_client binding and interrupts
41 * */
42errval_t pcid_init(
43            struct pcid* pdc,
44            struct capref* caps,
45            size_t caps_len,
46            char** args,
47            size_t args_len,
48            struct waitset *ws);
49
50/**
51 * Getting arguments that were passed by kaluga
52 * \param ws Used for the pci_driver_client binding and interrupts
53 * */
54errval_t pcid_get_interrupt_cap(struct pcid* pdc, struct capref *ret);
55errval_t pcid_get_bar_cap(struct pcid* pdc, int bar_index, struct capref *ret);
56size_t pcid_get_bar_num(struct pcid* pdc);
57/**
58 * Interrupt interface
59 */
60size_t pcid_get_int_num(struct pcid* pdc);
61errval_t pcid_connect_int(struct pcid* pdc, int int_index,
62                          interrupt_handler_fn handler, void *st);
63errval_t pcid_connect_int_with_cap(struct capref src_int, int int_index,
64                                   interrupt_handler_fn handler, void *st);
65errval_t pcid_enable_msix(int *num_vectors);
66
67#endif
68