aboutsummaryrefslogtreecommitdiff
path: root/lib/caps/px.h
blob: 62388a141400a9e8dc45e5e3aad2bdda173ef91f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
 * Copyright (c) 2019 Nutanix Inc. All rights reserved.
 *
 * Authors: Thanos Makatos <thanos@nutanix.com>
 *          Swapnil Ingle <swapnil.ingle@nutanix.com>
 *          Felipe Franciosi <felipe@nutanix.com>
 *
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *      * Redistributions of source code must retain the above copyright
 *        notice, this list of conditions and the following disclaimer.
 *      * Redistributions in binary form must reproduce the above copyright
 *        notice, this list of conditions and the following disclaimer in the
 *        documentation and/or other materials provided with the distribution.
 *      * Neither the name of Nutanix nor the names of its contributors may be
 *        used to endorse or promote products derived from this software without
 *        specific prior written permission.
 *
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *  ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 *  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 *  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
 *  DAMAGE.
 *
 */

struct pxid {
    unsigned int cid:8;
    unsigned int next:8;
} __attribute__((packed));
_Static_assert(sizeof(struct pxid) == 0x2, "bad PXID size");

struct pxcaps {
    unsigned int ver:4;
    unsigned int dpt:4;
    unsigned int si:1;
    unsigned int imn:5;
    unsigned int res1:2;
} __attribute__((packed));
_Static_assert(sizeof(struct pxcaps) == 0x2, "bad PXCAPS size");

struct pxdcap {
    unsigned int mps:3;
    unsigned int pfs:2;
    unsigned int etfs:1;
    unsigned int l0sl:3;
    unsigned int l1l:3;
    unsigned int per:1;
    unsigned int res1:2;
    unsigned int csplv:8;
    unsigned int cspls:2;
    unsigned int flrc:1;
    unsigned int res2:3;
} __attribute__((packed));
_Static_assert(sizeof(struct pxdcap) == 0x4, "bad PXDCAP size");

union pxdc {
    uint16_t raw;
    struct {
        unsigned int cere:1;
        unsigned int nfere:1;
        unsigned int fere:1;
        unsigned int urre:1;
        unsigned int ero:1;
        unsigned int mps:3;
        unsigned int ete:1;
        unsigned int pfe:1;
        unsigned int appme:1;
        unsigned int ens:1;
        unsigned int mrrs:3;
        unsigned int iflr:1;
     } __attribute__((packed));
} __attribute__((packed));
_Static_assert(sizeof(union pxdc) == 0x2, "bad PXDC size");

/* TODO not defining for now since all values are 0 for reset */
struct pxds {
    unsigned int stuff:16;
} __attribute__((packed));
_Static_assert(sizeof(struct pxds) == 0x2, "bad PXDS size");

struct pxlcap {
    unsigned int stuff:32;
} __attribute__((packed));
_Static_assert(sizeof(struct pxlcap) == 0x4, "bad PXLCAP size");

struct pxlc {
    unsigned int stuff:16;
} __attribute__((packed));
_Static_assert(sizeof(struct pxlc) == 0x2, "bad PXLC size");

struct pxls {
    unsigned int stuff:16;
} __attribute__((packed));
_Static_assert(sizeof(struct pxls) == 0x2, "bad PXLS size");

struct pxdcap2 {
    unsigned int ctrs:4;
    unsigned int ctds:1;
    unsigned int arifs:1;
    unsigned int aors:1;
    unsigned int aocs32:1;
    unsigned int aocs64:1;
    unsigned int ccs128:1;
    unsigned int nprpr:1;
    unsigned int ltrs:1;
    unsigned int tphcs:2;
    unsigned int obffs:2;
    unsigned int effs:1;
    unsigned int eetps:1;
    unsigned int meetp:2;
    unsigned int res1:8;
} __attribute__((packed));
_Static_assert(sizeof(struct pxdcap2) == 0x4, "bad PXDCAP2 size");

struct pxdc2 {
    unsigned int stuff:16;
} __attribute__((packed));
_Static_assert(sizeof(struct pxdc2) == 0x2, "bad PXDC2 size");

/*
 * TODO the definition of this struct varies, check PCI Express 2.1
 * specification. Maybe we should only define the idividual registers but not
 * the whole struct.
 */
struct pxcap {
    struct pxid pxid;
    struct pxcaps pxcaps;
    struct pxdcap pxdcap;
    union pxdc pxdc;
    struct pxds pxds;
    struct pxlcap pxlcap;
    struct pxlc pxlc;
    struct pxls pxls;
    uint8_t pad[0x10];
    struct pxdcap2 pxdcap2;
    struct pxdc2 pxdc2;
} __attribute__((packed));
_Static_assert(sizeof(struct pxcap) == 0x2a,
		"bad PCI Express Capability size");

/* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */