]> Git Repo - qemu.git/blob - hw/pci/pcie.c
pcie: Mangle types to match topology
[qemu.git] / hw / pci / pcie.c
1 /*
2  * pcie.c
3  *
4  * Copyright (c) 2010 Isaku Yamahata <yamahata at valinux co jp>
5  *                    VA Linux Systems Japan K.K.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #include "qemu-common.h"
22 #include "hw/pci/pci_bridge.h"
23 #include "hw/pci/pcie.h"
24 #include "hw/pci/msix.h"
25 #include "hw/pci/msi.h"
26 #include "hw/pci/pci_bus.h"
27 #include "hw/pci/pcie_regs.h"
28 #include "qemu/range.h"
29
30 //#define DEBUG_PCIE
31 #ifdef DEBUG_PCIE
32 # define PCIE_DPRINTF(fmt, ...)                                         \
33     fprintf(stderr, "%s:%d " fmt, __func__, __LINE__, ## __VA_ARGS__)
34 #else
35 # define PCIE_DPRINTF(fmt, ...) do {} while (0)
36 #endif
37 #define PCIE_DEV_PRINTF(dev, fmt, ...)                                  \
38     PCIE_DPRINTF("%s:%x "fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__)
39
40
41 /***************************************************************************
42  * pci express capability helper functions
43  */
44 int pcie_cap_init(PCIDevice *dev, uint8_t offset, uint8_t type, uint8_t port)
45 {
46     int pos;
47     uint8_t *exp_cap;
48
49     assert(pci_is_express(dev));
50
51     /*
52      * Mangle type to convert Endpoints to Root Complex Integrated Endpoints.
53      * Windows will report Code 10 (device cannot start) for regular Endpoints
54      * on the Root Complex.
55      */
56     if (pci_bus_is_express(dev->bus) && pci_bus_is_root(dev->bus)) {
57         switch (type) {
58         case PCI_EXP_TYPE_ENDPOINT:
59             type = PCI_EXP_TYPE_RC_END;
60             break;
61         }
62     }
63
64     pos = pci_add_capability(dev, PCI_CAP_ID_EXP, offset,
65                                  PCI_EXP_VER2_SIZEOF);
66     if (pos < 0) {
67         return pos;
68     }
69     dev->exp.exp_cap = pos;
70     exp_cap = dev->config + pos;
71
72     /* capability register
73        interrupt message number defaults to 0 */
74     pci_set_word(exp_cap + PCI_EXP_FLAGS,
75                  ((type << PCI_EXP_FLAGS_TYPE_SHIFT) & PCI_EXP_FLAGS_TYPE) |
76                  PCI_EXP_FLAGS_VER2);
77
78     /* device capability register
79      * table 7-12:
80      * roll based error reporting bit must be set by all
81      * Functions conforming to the ECN, PCI Express Base
82      * Specification, Revision 1.1., or subsequent PCI Express Base
83      * Specification revisions.
84      */
85     pci_set_long(exp_cap + PCI_EXP_DEVCAP, PCI_EXP_DEVCAP_RBER);
86
87     pci_set_long(exp_cap + PCI_EXP_LNKCAP,
88                  (port << PCI_EXP_LNKCAP_PN_SHIFT) |
89                  PCI_EXP_LNKCAP_ASPMS_0S |
90                  PCI_EXP_LNK_MLW_1 |
91                  PCI_EXP_LNK_LS_25);
92
93     pci_set_word(exp_cap + PCI_EXP_LNKSTA,
94                  PCI_EXP_LNK_MLW_1 | PCI_EXP_LNK_LS_25);
95
96     pci_set_long(exp_cap + PCI_EXP_DEVCAP2,
97                  PCI_EXP_DEVCAP2_EFF | PCI_EXP_DEVCAP2_EETLPP);
98
99     pci_set_word(dev->wmask + pos, PCI_EXP_DEVCTL2_EETLPPB);
100     return pos;
101 }
102
103 void pcie_cap_exit(PCIDevice *dev)
104 {
105     pci_del_capability(dev, PCI_CAP_ID_EXP, PCI_EXP_VER2_SIZEOF);
106 }
107
108 uint8_t pcie_cap_get_type(const PCIDevice *dev)
109 {
110     uint32_t pos = dev->exp.exp_cap;
111     assert(pos > 0);
112     return (pci_get_word(dev->config + pos + PCI_EXP_FLAGS) &
113             PCI_EXP_FLAGS_TYPE) >> PCI_EXP_FLAGS_TYPE_SHIFT;
114 }
115
116 /* MSI/MSI-X */
117 /* pci express interrupt message number */
118 /* 7.8.2 PCI Express Capabilities Register: Interrupt Message Number */
119 void pcie_cap_flags_set_vector(PCIDevice *dev, uint8_t vector)
120 {
121     uint8_t *exp_cap = dev->config + dev->exp.exp_cap;
122     assert(vector < 32);
123     pci_word_test_and_clear_mask(exp_cap + PCI_EXP_FLAGS, PCI_EXP_FLAGS_IRQ);
124     pci_word_test_and_set_mask(exp_cap + PCI_EXP_FLAGS,
125                                vector << PCI_EXP_FLAGS_IRQ_SHIFT);
126 }
127
128 uint8_t pcie_cap_flags_get_vector(PCIDevice *dev)
129 {
130     return (pci_get_word(dev->config + dev->exp.exp_cap + PCI_EXP_FLAGS) &
131             PCI_EXP_FLAGS_IRQ) >> PCI_EXP_FLAGS_IRQ_SHIFT;
132 }
133
134 void pcie_cap_deverr_init(PCIDevice *dev)
135 {
136     uint32_t pos = dev->exp.exp_cap;
137     pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_DEVCAP,
138                                PCI_EXP_DEVCAP_RBER);
139     pci_long_test_and_set_mask(dev->wmask + pos + PCI_EXP_DEVCTL,
140                                PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE |
141                                PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE);
142     pci_long_test_and_set_mask(dev->w1cmask + pos + PCI_EXP_DEVSTA,
143                                PCI_EXP_DEVSTA_CED | PCI_EXP_DEVSTA_NFED |
144                                PCI_EXP_DEVSTA_URD | PCI_EXP_DEVSTA_URD);
145 }
146
147 void pcie_cap_deverr_reset(PCIDevice *dev)
148 {
149     uint8_t *devctl = dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL;
150     pci_long_test_and_clear_mask(devctl,
151                                  PCI_EXP_DEVCTL_CERE | PCI_EXP_DEVCTL_NFERE |
152                                  PCI_EXP_DEVCTL_FERE | PCI_EXP_DEVCTL_URRE);
153 }
154
155 static void hotplug_event_update_event_status(PCIDevice *dev)
156 {
157     uint32_t pos = dev->exp.exp_cap;
158     uint8_t *exp_cap = dev->config + pos;
159     uint16_t sltctl = pci_get_word(exp_cap + PCI_EXP_SLTCTL);
160     uint16_t sltsta = pci_get_word(exp_cap + PCI_EXP_SLTSTA);
161
162     dev->exp.hpev_notified = (sltctl & PCI_EXP_SLTCTL_HPIE) &&
163         (sltsta & sltctl & PCI_EXP_HP_EV_SUPPORTED);
164 }
165
166 static void hotplug_event_notify(PCIDevice *dev)
167 {
168     bool prev = dev->exp.hpev_notified;
169
170     hotplug_event_update_event_status(dev);
171
172     if (prev == dev->exp.hpev_notified) {
173         return;
174     }
175
176     /* Note: the logic above does not take into account whether interrupts
177      * are masked. The result is that interrupt will be sent when it is
178      * subsequently unmasked. This appears to be legal: Section 6.7.3.4:
179      * The Port may optionally send an MSI when there are hot-plug events that
180      * occur while interrupt generation is disabled, and interrupt generation is
181      * subsequently enabled. */
182     if (msix_enabled(dev)) {
183         msix_notify(dev, pcie_cap_flags_get_vector(dev));
184     } else if (msi_enabled(dev)) {
185         msi_notify(dev, pcie_cap_flags_get_vector(dev));
186     } else {
187         qemu_set_irq(dev->irq[dev->exp.hpev_intx], dev->exp.hpev_notified);
188     }
189 }
190
191 static void hotplug_event_clear(PCIDevice *dev)
192 {
193     hotplug_event_update_event_status(dev);
194     if (!msix_enabled(dev) && !msi_enabled(dev) && !dev->exp.hpev_notified) {
195         qemu_set_irq(dev->irq[dev->exp.hpev_intx], 0);
196     }
197 }
198
199 /*
200  * A PCI Express Hot-Plug Event has occurred, so update slot status register
201  * and notify OS of the event if necessary.
202  *
203  * 6.7.3 PCI Express Hot-Plug Events
204  * 6.7.3.4 Software Notification of Hot-Plug Events
205  */
206 static void pcie_cap_slot_event(PCIDevice *dev, PCIExpressHotPlugEvent event)
207 {
208     /* Minor optimization: if nothing changed - no event is needed. */
209     if (pci_word_test_and_set_mask(dev->config + dev->exp.exp_cap +
210                                    PCI_EXP_SLTSTA, event)) {
211         return;
212     }
213     hotplug_event_notify(dev);
214 }
215
216 static int pcie_cap_slot_hotplug(DeviceState *qdev,
217                                  PCIDevice *pci_dev, PCIHotplugState state)
218 {
219     PCIDevice *d = PCI_DEVICE(qdev);
220     uint8_t *exp_cap = d->config + d->exp.exp_cap;
221     uint16_t sltsta = pci_get_word(exp_cap + PCI_EXP_SLTSTA);
222
223     /* Don't send event when device is enabled during qemu machine creation:
224      * it is present on boot, no hotplug event is necessary. We do send an
225      * event when the device is disabled later. */
226     if (state == PCI_COLDPLUG_ENABLED) {
227         pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA,
228                                    PCI_EXP_SLTSTA_PDS);
229         return 0;
230     }
231
232     PCIE_DEV_PRINTF(pci_dev, "hotplug state: %d\n", state);
233     if (sltsta & PCI_EXP_SLTSTA_EIS) {
234         /* the slot is electromechanically locked.
235          * This error is propagated up to qdev and then to HMP/QMP.
236          */
237         return -EBUSY;
238     }
239
240     /* TODO: multifunction hot-plug.
241      * Right now, only a device of function = 0 is allowed to be
242      * hot plugged/unplugged.
243      */
244     assert(PCI_FUNC(pci_dev->devfn) == 0);
245
246     if (state == PCI_HOTPLUG_ENABLED) {
247         pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTSTA,
248                                    PCI_EXP_SLTSTA_PDS);
249         pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
250     } else {
251         qdev_free(&pci_dev->qdev);
252         pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
253                                      PCI_EXP_SLTSTA_PDS);
254         pcie_cap_slot_event(d, PCI_EXP_HP_EV_PDC);
255     }
256     return 0;
257 }
258
259 /* pci express slot for pci express root/downstream port
260    PCI express capability slot registers */
261 void pcie_cap_slot_init(PCIDevice *dev, uint16_t slot)
262 {
263     uint32_t pos = dev->exp.exp_cap;
264
265     pci_word_test_and_set_mask(dev->config + pos + PCI_EXP_FLAGS,
266                                PCI_EXP_FLAGS_SLOT);
267
268     pci_long_test_and_clear_mask(dev->config + pos + PCI_EXP_SLTCAP,
269                                  ~PCI_EXP_SLTCAP_PSN);
270     pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCAP,
271                                (slot << PCI_EXP_SLTCAP_PSN_SHIFT) |
272                                PCI_EXP_SLTCAP_EIP |
273                                PCI_EXP_SLTCAP_HPS |
274                                PCI_EXP_SLTCAP_HPC |
275                                PCI_EXP_SLTCAP_PIP |
276                                PCI_EXP_SLTCAP_AIP |
277                                PCI_EXP_SLTCAP_ABP);
278
279     pci_word_test_and_clear_mask(dev->config + pos + PCI_EXP_SLTCTL,
280                                  PCI_EXP_SLTCTL_PIC |
281                                  PCI_EXP_SLTCTL_AIC);
282     pci_word_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCTL,
283                                PCI_EXP_SLTCTL_PIC_OFF |
284                                PCI_EXP_SLTCTL_AIC_OFF);
285     pci_word_test_and_set_mask(dev->wmask + pos + PCI_EXP_SLTCTL,
286                                PCI_EXP_SLTCTL_PIC |
287                                PCI_EXP_SLTCTL_AIC |
288                                PCI_EXP_SLTCTL_HPIE |
289                                PCI_EXP_SLTCTL_CCIE |
290                                PCI_EXP_SLTCTL_PDCE |
291                                PCI_EXP_SLTCTL_ABPE);
292     /* Although reading PCI_EXP_SLTCTL_EIC returns always 0,
293      * make the bit writable here in order to detect 1b is written.
294      * pcie_cap_slot_write_config() test-and-clear the bit, so
295      * this bit always returns 0 to the guest.
296      */
297     pci_word_test_and_set_mask(dev->wmask + pos + PCI_EXP_SLTCTL,
298                                PCI_EXP_SLTCTL_EIC);
299
300     pci_word_test_and_set_mask(dev->w1cmask + pos + PCI_EXP_SLTSTA,
301                                PCI_EXP_HP_EV_SUPPORTED);
302
303     dev->exp.hpev_notified = false;
304
305     pci_bus_hotplug(pci_bridge_get_sec_bus(DO_UPCAST(PCIBridge, dev, dev)),
306                     pcie_cap_slot_hotplug, &dev->qdev);
307 }
308
309 void pcie_cap_slot_reset(PCIDevice *dev)
310 {
311     uint8_t *exp_cap = dev->config + dev->exp.exp_cap;
312
313     PCIE_DEV_PRINTF(dev, "reset\n");
314
315     pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTCTL,
316                                  PCI_EXP_SLTCTL_EIC |
317                                  PCI_EXP_SLTCTL_PIC |
318                                  PCI_EXP_SLTCTL_AIC |
319                                  PCI_EXP_SLTCTL_HPIE |
320                                  PCI_EXP_SLTCTL_CCIE |
321                                  PCI_EXP_SLTCTL_PDCE |
322                                  PCI_EXP_SLTCTL_ABPE);
323     pci_word_test_and_set_mask(exp_cap + PCI_EXP_SLTCTL,
324                                PCI_EXP_SLTCTL_PIC_OFF |
325                                PCI_EXP_SLTCTL_AIC_OFF);
326
327     pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTSTA,
328                                  PCI_EXP_SLTSTA_EIS |/* on reset,
329                                                         the lock is released */
330                                  PCI_EXP_SLTSTA_CC |
331                                  PCI_EXP_SLTSTA_PDC |
332                                  PCI_EXP_SLTSTA_ABP);
333
334     hotplug_event_update_event_status(dev);
335 }
336
337 void pcie_cap_slot_write_config(PCIDevice *dev,
338                                 uint32_t addr, uint32_t val, int len)
339 {
340     uint32_t pos = dev->exp.exp_cap;
341     uint8_t *exp_cap = dev->config + pos;
342     uint16_t sltsta = pci_get_word(exp_cap + PCI_EXP_SLTSTA);
343
344     if (ranges_overlap(addr, len, pos + PCI_EXP_SLTSTA, 2)) {
345         hotplug_event_clear(dev);
346     }
347
348     if (!ranges_overlap(addr, len, pos + PCI_EXP_SLTCTL, 2)) {
349         return;
350     }
351
352     if (pci_word_test_and_clear_mask(exp_cap + PCI_EXP_SLTCTL,
353                                      PCI_EXP_SLTCTL_EIC)) {
354         sltsta ^= PCI_EXP_SLTSTA_EIS; /* toggle PCI_EXP_SLTSTA_EIS bit */
355         pci_set_word(exp_cap + PCI_EXP_SLTSTA, sltsta);
356         PCIE_DEV_PRINTF(dev, "PCI_EXP_SLTCTL_EIC: "
357                         "sltsta -> 0x%02"PRIx16"\n",
358                         sltsta);
359     }
360
361     hotplug_event_notify(dev);
362
363     /* 
364      * 6.7.3.2 Command Completed Events
365      *
366      * Software issues a command to a hot-plug capable Downstream Port by
367      * issuing a write transaction that targets any portion of the Port’s Slot
368      * Control register. A single write to the Slot Control register is
369      * considered to be a single command, even if the write affects more than
370      * one field in the Slot Control register. In response to this transaction,
371      * the Port must carry out the requested actions and then set the
372      * associated status field for the command completed event. */
373
374     /* Real hardware might take a while to complete requested command because
375      * physical movement would be involved like locking the electromechanical
376      * lock.  However in our case, command is completed instantaneously above,
377      * so send a command completion event right now.
378      */
379     pcie_cap_slot_event(dev, PCI_EXP_HP_EV_CCI);
380 }
381
382 int pcie_cap_slot_post_load(void *opaque, int version_id)
383 {
384     PCIDevice *dev = opaque;
385     hotplug_event_update_event_status(dev);
386     return 0;
387 }
388
389 void pcie_cap_slot_push_attention_button(PCIDevice *dev)
390 {
391     pcie_cap_slot_event(dev, PCI_EXP_HP_EV_ABP);
392 }
393
394 /* root control/capabilities/status. PME isn't emulated for now */
395 void pcie_cap_root_init(PCIDevice *dev)
396 {
397     pci_set_word(dev->wmask + dev->exp.exp_cap + PCI_EXP_RTCTL,
398                  PCI_EXP_RTCTL_SECEE | PCI_EXP_RTCTL_SENFEE |
399                  PCI_EXP_RTCTL_SEFEE);
400 }
401
402 void pcie_cap_root_reset(PCIDevice *dev)
403 {
404     pci_set_word(dev->config + dev->exp.exp_cap + PCI_EXP_RTCTL, 0);
405 }
406
407 /* function level reset(FLR) */
408 void pcie_cap_flr_init(PCIDevice *dev)
409 {
410     pci_long_test_and_set_mask(dev->config + dev->exp.exp_cap + PCI_EXP_DEVCAP,
411                                PCI_EXP_DEVCAP_FLR);
412
413     /* Although reading BCR_FLR returns always 0,
414      * the bit is made writable here in order to detect the 1b is written
415      * pcie_cap_flr_write_config() test-and-clear the bit, so
416      * this bit always returns 0 to the guest.
417      */
418     pci_word_test_and_set_mask(dev->wmask + dev->exp.exp_cap + PCI_EXP_DEVCTL,
419                                PCI_EXP_DEVCTL_BCR_FLR);
420 }
421
422 void pcie_cap_flr_write_config(PCIDevice *dev,
423                                uint32_t addr, uint32_t val, int len)
424 {
425     uint8_t *devctl = dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL;
426     if (pci_get_word(devctl) & PCI_EXP_DEVCTL_BCR_FLR) {
427         /* Clear PCI_EXP_DEVCTL_BCR_FLR after invoking the reset handler
428            so the handler can detect FLR by looking at this bit. */
429         pci_device_reset(dev);
430         pci_word_test_and_clear_mask(devctl, PCI_EXP_DEVCTL_BCR_FLR);
431     }
432 }
433
434 /* Alternative Routing-ID Interpretation (ARI) */
435 /* ari forwarding support for down stream port */
436 void pcie_cap_ari_init(PCIDevice *dev)
437 {
438     uint32_t pos = dev->exp.exp_cap;
439     pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_DEVCAP2,
440                                PCI_EXP_DEVCAP2_ARI);
441     pci_long_test_and_set_mask(dev->wmask + pos + PCI_EXP_DEVCTL2,
442                                PCI_EXP_DEVCTL2_ARI);
443 }
444
445 void pcie_cap_ari_reset(PCIDevice *dev)
446 {
447     uint8_t *devctl2 = dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL2;
448     pci_long_test_and_clear_mask(devctl2, PCI_EXP_DEVCTL2_ARI);
449 }
450
451 bool pcie_cap_is_ari_enabled(const PCIDevice *dev)
452 {
453     if (!pci_is_express(dev)) {
454         return false;
455     }
456     if (!dev->exp.exp_cap) {
457         return false;
458     }
459
460     return pci_get_long(dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL2) &
461         PCI_EXP_DEVCTL2_ARI;
462 }
463
464 /**************************************************************************
465  * pci express extended capability allocation functions
466  * uint16_t ext_cap_id (16 bit)
467  * uint8_t cap_ver (4 bit)
468  * uint16_t cap_offset (12 bit)
469  * uint16_t ext_cap_size
470  */
471
472 static uint16_t pcie_find_capability_list(PCIDevice *dev, uint16_t cap_id,
473                                           uint16_t *prev_p)
474 {
475     uint16_t prev = 0;
476     uint16_t next;
477     uint32_t header = pci_get_long(dev->config + PCI_CONFIG_SPACE_SIZE);
478
479     if (!header) {
480         /* no extended capability */
481         next = 0;
482         goto out;
483     }
484     for (next = PCI_CONFIG_SPACE_SIZE; next;
485          prev = next, next = PCI_EXT_CAP_NEXT(header)) {
486
487         assert(next >= PCI_CONFIG_SPACE_SIZE);
488         assert(next <= PCIE_CONFIG_SPACE_SIZE - 8);
489
490         header = pci_get_long(dev->config + next);
491         if (PCI_EXT_CAP_ID(header) == cap_id) {
492             break;
493         }
494     }
495
496 out:
497     if (prev_p) {
498         *prev_p = prev;
499     }
500     return next;
501 }
502
503 uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id)
504 {
505     return pcie_find_capability_list(dev, cap_id, NULL);
506 }
507
508 static void pcie_ext_cap_set_next(PCIDevice *dev, uint16_t pos, uint16_t next)
509 {
510     uint32_t header = pci_get_long(dev->config + pos);
511     assert(!(next & (PCI_EXT_CAP_ALIGN - 1)));
512     header = (header & ~PCI_EXT_CAP_NEXT_MASK) |
513         ((next << PCI_EXT_CAP_NEXT_SHIFT) & PCI_EXT_CAP_NEXT_MASK);
514     pci_set_long(dev->config + pos, header);
515 }
516
517 /*
518  * caller must supply valid (offset, size) * such that the range shouldn't
519  * overlap with other capability or other registers.
520  * This function doesn't check it.
521  */
522 void pcie_add_capability(PCIDevice *dev,
523                          uint16_t cap_id, uint8_t cap_ver,
524                          uint16_t offset, uint16_t size)
525 {
526     uint32_t header;
527     uint16_t next;
528
529     assert(offset >= PCI_CONFIG_SPACE_SIZE);
530     assert(offset < offset + size);
531     assert(offset + size < PCIE_CONFIG_SPACE_SIZE);
532     assert(size >= 8);
533     assert(pci_is_express(dev));
534
535     if (offset == PCI_CONFIG_SPACE_SIZE) {
536         header = pci_get_long(dev->config + offset);
537         next = PCI_EXT_CAP_NEXT(header);
538     } else {
539         uint16_t prev;
540
541         /* 0 is reserved cap id. use internally to find the last capability
542            in the linked list */
543         next = pcie_find_capability_list(dev, 0, &prev);
544
545         assert(prev >= PCI_CONFIG_SPACE_SIZE);
546         assert(next == 0);
547         pcie_ext_cap_set_next(dev, prev, offset);
548     }
549     pci_set_long(dev->config + offset, PCI_EXT_CAP(cap_id, cap_ver, next));
550
551     /* Make capability read-only by default */
552     memset(dev->wmask + offset, 0, size);
553     memset(dev->w1cmask + offset, 0, size);
554     /* Check capability by default */
555     memset(dev->cmask + offset, 0xFF, size);
556 }
557
558 /**************************************************************************
559  * pci express extended capability helper functions
560  */
561
562 /* ARI */
563 void pcie_ari_init(PCIDevice *dev, uint16_t offset, uint16_t nextfn)
564 {
565     pcie_add_capability(dev, PCI_EXT_CAP_ID_ARI, PCI_ARI_VER,
566                         offset, PCI_ARI_SIZEOF);
567     pci_set_long(dev->config + offset + PCI_ARI_CAP, PCI_ARI_CAP_NFN(nextfn));
568 }
This page took 0.05604 seconds and 4 git commands to generate.