Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Minor compile warning fixup and error checks
[palacios.git] / palacios / include / devices / pci_types.h
1 /* 
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2009, Jack Lange <jarusl@cs.northwestern.edu>
11  * Copyright (c) 2009, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author:  Jack Lange 
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #ifndef __DEVICES_PCI_TYPES_H__
21 #define __DEVICES_PCI_TYPES_H__
22
23
24 #include <palacios/vmm_types.h>
25
26 // struct pci_device_config
27 struct pci_config_header {
28     uint16_t   vendor_id;
29     uint16_t   device_id;
30     
31     uint16_t   command;
32     uint16_t   status;
33     
34     
35     uint8_t    revision;
36     uint8_t    prog_if;
37     uint8_t     subclass;
38     uint8_t     class;
39
40     uint8_t    cache_line_size;
41     uint8_t    latency_time;
42     uint8_t    header_type; // bits 6-0: 00: other, 01: pci-pci bridge, 02: pci-cardbus; bit 7: 1=multifunction
43     uint8_t    BIST;  
44     
45
46     uint32_t   BAR0;
47     uint32_t   BAR1;
48     uint32_t   BAR2;
49     uint32_t   BAR3;
50     uint32_t   BAR4;
51     uint32_t   BAR5;
52     uint32_t   cardbus_cis_pointer;
53     uint16_t   subsystem_vendor_id;
54     uint16_t   subsystem_id;
55     uint32_t expansion_rom_address;
56     uint8_t cap_ptr;  // capabilities list offset in config space
57     uint8_t rsvd1[3];
58     uint32_t rsvd2;
59     uint8_t    intr_line; // 00=none, 01=IRQ1, etc.
60     uint8_t    intr_pin;  // 00=none, otherwise INTA# to INTD#
61     uint8_t    min_grant; // min busmaster time - units of 250ns
62     uint8_t    max_latency; // units of 250ns - busmasters
63 } __attribute__((packed));
64
65
66 struct pci_cmd_reg {
67     union {
68         uint16_t val;
69         struct {
70             uint16_t io_enable         : 1;
71             uint16_t mem_enable        : 1;
72             uint16_t dma_enable        : 1;
73             uint16_t special_cycles    : 1;
74             uint16_t mem_wr_inv_enable : 1;
75             uint16_t vga_snoop         : 1;
76             uint16_t parity_err_resp   : 1;
77             uint16_t rsvd1             : 1;
78             uint16_t serr_enable       : 1;
79             uint16_t fast_b2b_enable   : 1;
80             uint16_t intx_disable      : 1;
81             uint16_t rsvd2             : 5;
82         } __attribute__((packed));
83     } __attribute__((packed));
84
85 } __attribute__((packed));
86
87
88 typedef enum { PCI_CLASS_PRE2 = 0x00, 
89                PCI_CLASS_STORAGE = 0x01, 
90                PCI_CLASS_NETWORK = 0x02,
91                PCI_CLASS_DISPLAY = 0x03,
92                PCI_CLASS_MMEDIA = 0x04,
93                PCI_CLASS_MEMORY = 0x05,
94                PCI_CLASS_BRIDGE = 0x06,
95                PCI_CLASS_COMM_CTRL = 0x07,
96                PCI_CLASS_BASE_PERIPH = 0x08,
97                PCI_CLASS_INPUT = 0x09, 
98                PCI_CLASS_DOCK = 0x0a,
99                PCI_CLASS_PROC = 0x0b, 
100                PCI_CLASS_SERIAL = 0x0c,
101                PCI_CLASS_MISC = 0xff } pci_class_t;
102
103 typedef enum { PCI_STORAGE_SUBCLASS_SCSI = 0x00,
104                PCI_STORAGE_SUBCLASS_IDE = 0x01,
105                PCI_STORAGE_SUBCLASS_FLOPPY = 0x02,
106                PCI_STORAGE_SUBCLASS_IPI = 0x03,
107                PCI_STORAGE_SUBCLASS_RAID = 0x04,
108                PCI_STORAGE_SUBCLASS_SATA = 0x06,
109                PCI_STORAGE_SUBCLASS_SAS = 0x07,
110                PCI_STORAGE_SUBCLASS_OTHER = 0x80 } pci_storage_subclass_t;
111
112
113
114 typedef enum { PCI_NET_SUBCLASS_ETHER = 0x00,
115                PCI_NET_SUBCLASS_TOKRING = 0x01,
116                PCI_NET_SUBCLASS_FDDI = 0x02,
117                PCI_NET_SUBCLASS_ATM = 0x03,
118                PCI_NET_SUBCLASS_OTHER = 0x80 } pci_network_subclass_t;
119
120 typedef enum { PCI_DISPLAY_SUBCLASS_VGA = 0x00,
121                PCI_DISPLAY_SUBCLASS_XGA = 0x01,
122                PCI_DISPLAY_SUBCLASS_OTHER = 0x80 } pci_display_subclass_t;
123
124 typedef enum { PCI_MMEDIA_SUBCLASS_VIDEO = 0x00,
125                PCI_MMEDIA_SUBCLASS_AUDIO = 0x01,
126                PCI_MMEDIA_SUBCLASS_OTHER = 0x80 } pci_multimedia_subclass_t;
127                
128 typedef enum { PCI_MEM_SUBCLASS_RAM = 0x00, 
129                PCI_MEM_SUBCLASS_FLASH = 0x01,
130                PCI_MEM_SUBCLASS_OTHER = 0x80 } pci_memory_subclass_t;
131
132 typedef enum { PCI_BRIDGE_SUBCLASS_HOST_PCI = 0x00,
133                PCI_BRIDGE_SUBCLASS_PCI_ISA = 0x01,
134                PCI_BRIDGE_SUBCLASS_PCI_EISA = 0x02,
135                PCI_BRIDGE_SUBCLASS_PCI_MICRO = 0x03,
136                PCI_BRIDGE_SUBCLASS_PCI_PCI = 0x04,
137                PCI_BRIDGE_SUBCLASS_PCI_PCMCIA = 0x05,
138                PCI_BRIDGE_SUBCLASS_PCI_NUBUS = 0x06,
139                PCI_BRIDGE_SUBCLASS_PCI_CARDBUS = 0x07,
140                PCI_BRIDGE_SUBCLASS_PCI_OTHER = 0x80 } pci_bridge_subclass_t;
141
142
143
144 /*
145   struct pci_class_desc {
146   uint16_t class;
147   const char * desc;
148   };
149   
150   static struct pci_class_desc pci_class_descriptions[] = {
151   { 0x0100, "SCSI controller"},
152   { 0x0101, "IDE controller"},
153   { 0x0102, "Floppy controller"},
154   { 0x0103, "IPI controller"},
155   { 0x0104, "RAID controller"},
156   { 0x0106, "SATA controller"},
157   { 0x0107, "SAS controller"},
158   { 0x0180, "Storage controller"},
159   { 0x0200, "Ethernet controller"},
160   { 0x0201, "Token Ring controller"},
161   { 0x0202, "FDDI controller"},
162   { 0x0203, "ATM controller"},
163   { 0x0280, "Network controller"},
164   { 0x0300, "VGA controller"},
165   { 0x0301, "XGA controller"},
166   { 0x0302, "3D controller"},
167   { 0x0380, "Display controller"},
168   { 0x0400, "Video controller"},
169   { 0x0401, "Audio controller"},
170   { 0x0402, "Phone"},
171   { 0x0480, "Multimedia controller"},
172   { 0x0500, "RAM controller"},
173   { 0x0501, "Flash controller"},
174   { 0x0580, "Memory controller"},
175   { 0x0600, "Host bridge"},
176   { 0x0601, "ISA bridge"},
177   { 0x0602, "EISA bridge"},
178   { 0x0603, "MC bridge"},
179   { 0x0604, "PCI bridge"},
180   { 0x0605, "PCMCIA bridge"},
181   { 0x0606, "NUBUS bridge"},
182   { 0x0607, "CARDBUS bridge"},
183   { 0x0608, "RACEWAY bridge"},
184   { 0x0680, "Bridge"},
185   { 0x0c03, "USB controller"},
186   { 0, NULL}
187   };
188 */
189
190
191
192 struct msi_addr {
193     union {
194         uint32_t val;
195         struct {
196             uint32_t rsvd1        : 2;
197             uint32_t dst_mode     : 1;
198             uint32_t redir_hint   : 1;
199             uint32_t rsvd2        : 8;
200             uint32_t dst_id       : 8;
201             uint32_t fixaddr      : 12;
202         } __attribute__((packed));
203     } __attribute__((packed));
204 } __attribute__((packed));
205
206
207 struct msi_data {
208     union {
209         uint16_t val;
210         struct {
211             uint16_t vector       : 8;
212             uint16_t del_mode     : 3;
213             uint16_t rsvd1        : 3;
214             uint16_t level        : 1;
215             uint16_t trig_mode    : 1;
216         } __attribute__((packed));;
217     } __attribute__((packed));
218 } __attribute__((packed));
219
220
221 struct msi_msg_ctrl {
222     union {
223         uint16_t val;
224         struct {
225             uint16_t msi_enable       : 1;
226             uint16_t mult_msg_capable : 3;
227             uint16_t mult_msg_enable  : 3;
228             uint16_t cap_64bit        : 1;
229             uint16_t per_vect_mask    : 1;
230             uint16_t rsvd             : 7;
231         } __attribute__((packed));
232     } __attribute__((packed));
233 } __attribute__((packed));
234
235
236 struct msi32_msg_addr {
237     struct msi_msg_ctrl msg_ctrl;
238     struct msi_addr addr;
239     struct msi_data data;
240 } __attribute__((packed));
241
242
243 struct msi64_msg_addr {
244     struct msi_msg_ctrl msg_ctrl;
245     struct msi_addr addr;
246     uint32_t hi_addr;
247     struct msi_data data;
248 } __attribute__((packed));
249
250
251 struct msi64_pervec_msg_addr {
252     struct msi_msg_ctrl msg_ctrl;
253     struct msi_addr addr;
254     uint32_t hi_addr;
255     struct msi_data data;
256     uint16_t rsvd;
257     uint32_t mask;
258     uint32_t pending;
259 } __attribute__((packed));
260
261
262 struct msix_msg_ctrl {
263     uint16_t table_size   : 11;
264     uint16_t rsvd         : 4;
265     uint16_t msix_enable  : 1;
266 } __attribute__((packed));
267
268 struct msix_cap {
269     struct msix_msg_ctrl msg_ctrl;
270     uint32_t hi_addr;
271     uint32_t bir      : 3;
272     uint32_t table_offset : 29;
273 } __attribute__((packed));
274
275
276 struct msix_table {
277     struct {
278         struct msi_data data;
279         struct msi_addr addr;
280     } __attribute__((packed)) entries[0];
281 } __attribute__((packed));
282
283
284
285 // See PCI power management specification (1.2)
286 struct pmc_cap {
287     struct {
288         uint16_t version        : 3;
289         uint16_t pme_clock      : 1;
290         uint16_t rsvd1          : 1;
291         uint16_t dsi            : 1;
292         uint16_t aux_current    : 3;
293         uint16_t d1_support     : 1;
294         uint16_t d2_support     : 1;
295         uint16_t pme_support    : 5;
296     } __attribute__((packed)) pmc;
297
298     struct {
299         uint16_t power_state    : 2;
300         uint16_t rsvd1          : 1;
301         uint16_t no_soft_reset  : 1;
302         uint16_t rsvd2          : 4;
303         uint16_t pme_en         : 1;
304         uint16_t data_select    : 4;
305         uint16_t data_scale     : 2;
306         uint16_t pme_status     : 1;
307     } __attribute__((packed)) pmcsr;
308
309     struct {
310         uint8_t rsvd1           : 6;
311         uint8_t b2_b3           : 1;
312         uint8_t bpcc_en         : 1;
313     } __attribute__((packed)) pmcsr_bse;
314
315     uint8_t data;
316 } __attribute__((packed));
317
318
319 struct pcie_cap_reg {
320     uint16_t version     : 4;
321     uint16_t type        : 4;
322     uint16_t slot_impl   : 1;
323     uint16_t irq_msg_num : 5;
324     uint16_t rsvd        : 2;
325 } __attribute__((packed));
326
327 struct pcie_cap_v1 {
328     struct pcie_cap_reg pcie_cap;
329
330     union {
331         uint32_t val;
332         struct {
333             uint32_t max_payload          : 3;
334             uint32_t phantom_fns          : 2;
335             uint32_t ext_tag_support      : 1;
336             uint32_t endpt_L0_latency     : 3;
337             uint32_t endpt_L1_latency     : 3;
338             uint32_t maybe_rsvd1          : 3;
339             uint32_t role_err_reporting   : 1;
340             uint32_t rsvd2                : 2;
341             uint32_t slot_pwr_lim_val     : 8;
342             uint32_t slot_pwr_lim_scale   : 2;
343             uint32_t rsvd3                : 4;
344         } __attribute__((packed));
345     } __attribute__((packed)) dev_cap;
346
347     union {
348         uint16_t val;
349         struct {
350             uint16_t correctable_err_enable  : 1;
351             uint16_t non_fatal_err_enable    : 1;
352             uint16_t fatal_err_enable        : 1;
353             uint16_t unsupp_req_enable       : 1;
354             uint16_t relaxed_order_enable    : 1;
355             uint16_t max_payload_size        : 3;
356             uint16_t ext_tag_field_enable    : 1;
357             uint16_t phantom_fn_enable       : 1;
358             uint16_t aux_pwr_enable          : 1;
359             uint16_t no_snoop_enable         : 1;
360             uint16_t max_read_req_size       : 3;
361             uint16_t bridge_cfg_retry_enable : 1;
362         } __attribute__((packed));
363     } __attribute__((packed)) dev_ctrl;
364
365     union {
366         uint16_t val;
367         struct {
368             uint16_t correctable_err         : 1;
369             uint16_t non_fatal_err           : 1;
370             uint16_t fatal_err               : 1;
371             uint16_t unsupp_req              : 1;
372             uint16_t aux_pwr                 : 1;
373             uint16_t transaction_pending     : 1;
374             uint16_t rsvd                    : 10;
375         } __attribute__((packed));
376     } __attribute__((packed)) dev_status;
377
378     union {
379         uint32_t val;
380         struct {
381             uint32_t max_link_speed            : 4;
382             uint32_t max_link_width            : 6;
383             uint32_t aspm_support              : 2; /* Active State Power Management Support */
384             uint32_t L0_exit_latency           : 3;
385             uint32_t L1_exit_latency           : 3;
386             uint32_t clk_pwr_mngmt             : 1;
387             uint32_t surprise_pwr_down_capable : 1;
388             uint32_t data_link_active_capable  : 1;
389             uint32_t rsvd1                     : 3;
390             uint32_t port_number               : 8;
391         } __attribute__((packed));
392     } __attribute__((packed)) link_cap;
393
394
395     union {
396         uint16_t val;
397         struct {
398             uint16_t aspm_ctrl                 : 2;
399             uint16_t rsvd1                     : 1;
400             uint16_t rd_cmpl_bndry             : 1;
401             uint16_t link_disable              : 1;
402             uint16_t retrain_link              : 1;
403             uint16_t common_clk_cfg            : 1;
404             uint16_t ext_synch                 : 1;
405             uint16_t clk_pwr_mngmt_enable      : 1;
406             uint16_t rsvd2                     : 7;
407         } __attribute__((packed));
408     } __attribute__((packed)) link_ctrl;
409
410
411     union {
412         uint16_t val;
413         struct {
414             uint16_t link_speed               : 4;
415             uint16_t negotiate_link_width     : 6;
416             uint16_t undef                    : 1;
417             uint16_t link_training            : 1;
418             uint16_t slot_clk_cfg             : 1;
419             uint16_t data_link_layer_active   : 1;
420             uint16_t rsvd                     : 2;
421         } __attribute__((packed));
422     } __attribute__((packed)) link_status;
423
424 } __attribute__((packed));
425
426
427
428
429 struct pcie_cap_v2 {
430    struct pcie_cap_reg pcie_cap;
431
432     union {
433         uint32_t val;
434         struct {
435             uint32_t max_payload          : 3;
436             uint32_t phantom_fns          : 2;
437             uint32_t ext_tag_support      : 1;
438             uint32_t endpt_L0_latency     : 3;
439             uint32_t endpt_L1_latency     : 3;
440             uint32_t maybe_rsvd1          : 3;
441             uint32_t role_err_reporting   : 1;
442             uint32_t rsvd2                : 2;
443             uint32_t slot_pwr_lim_val     : 8;
444             uint32_t slot_pwr_lim_scale   : 2;
445             uint32_t fn_level_reset       : 1;
446             uint32_t rsvd3                : 3;
447         } __attribute__((packed));
448     } __attribute__((packed)) dev_cap;
449
450     union {
451         uint16_t val;
452         struct {
453             uint16_t correctable_err_enable  : 1;
454             uint16_t non_fatal_err_enable    : 1;
455             uint16_t fatal_err_enable        : 1;
456             uint16_t unsupp_req_enable       : 1;
457             uint16_t relaxed_order_enable    : 1;
458             uint16_t max_payload_size        : 3;
459             uint16_t ext_tag_field_enable    : 1;
460             uint16_t phantom_fn_enable       : 1;
461             uint16_t aux_pwr_enable          : 1;
462             uint16_t no_snoop_enable         : 1;
463             uint16_t max_read_req_size       : 3;
464             uint16_t bridge_cfg_retry_enable : 1;
465         } __attribute__((packed));
466     } __attribute__((packed)) dev_ctrl;
467
468     union {
469         uint16_t val;
470         struct {
471             uint16_t correctable_err         : 1;
472             uint16_t non_fatal_err           : 1;
473             uint16_t fatal_err               : 1;
474             uint16_t unsupp_req              : 1;
475             uint16_t aux_pwr                 : 1;
476             uint16_t transaction_pending     : 1;
477             uint16_t rsvd                    : 10;
478         } __attribute__((packed));
479     } __attribute__((packed)) dev_status;
480
481     union {
482         uint32_t val;
483         struct {
484             uint32_t max_link_speed            : 4;
485             uint32_t max_link_width            : 6;
486             uint32_t aspm_support              : 2; /* Active State Power Management Support */
487             uint32_t L0_exit_latency           : 3;
488             uint32_t L1_exit_latency           : 3;
489             uint32_t clk_pwr_mngmt             : 1;
490             uint32_t surprise_pwr_down_capable : 1;
491             uint32_t data_link_active_capable  : 1;
492             uint32_t rsvd1                     : 3;
493             uint32_t port_number               : 8;
494         } __attribute__((packed));
495     } __attribute__((packed)) link_cap;
496
497
498     union {
499         uint16_t val;
500         struct {
501             uint16_t aspm_ctrl                 : 2;
502             uint16_t rsvd1                     : 1;
503             uint16_t rd_cmpl_bndry             : 1;
504             uint16_t link_disable              : 1;
505             uint16_t retrain_link              : 1;
506             uint16_t common_clk_cfg            : 1;
507             uint16_t ext_synch                 : 1;
508             uint16_t clk_pwr_mngmt_enable      : 1;
509             uint16_t rsvd2                     : 7;
510         } __attribute__((packed));
511     } __attribute__((packed)) link_ctrl;
512
513
514     union {
515         uint16_t val;
516         struct {
517             uint16_t link_speed               : 4;
518             uint16_t negotiate_link_width     : 6;
519             uint16_t undef                    : 1;
520             uint16_t link_training            : 1;
521             uint16_t slot_clk_cfg             : 1;
522             uint16_t data_link_layer_active   : 1;
523             uint16_t rsvd                     : 2;
524         } __attribute__((packed));
525     } __attribute__((packed)) link_status;
526
527
528     /* Some crap whose format we don't know because the PCI-SIG sucks */
529     
530     uint32_t slot_cap;
531     uint16_t slot_ctrl;
532     uint16_t slot_status;
533
534     uint16_t root_ctrl;
535     uint16_t root_cap;
536     uint32_t root_status;
537
538 } __attribute__((packed));
539
540
541
542 #endif
543