Lines Matching refs:dev

40 #define PCIE_DEV_PRINTF(dev, fmt, ...)                                  \  argument
41 PCIE_DPRINTF("%s:%x "fmt, (dev)->name, (dev)->devfn, ## __VA_ARGS__)
71 pcie_cap_v1_fill(PCIDevice *dev, uint8_t port, uint8_t type, uint8_t version) in pcie_cap_v1_fill() argument
73 uint8_t *exp_cap = dev->config + dev->exp.exp_cap; in pcie_cap_v1_fill()
74 uint8_t *cmask = dev->cmask + dev->exp.exp_cap; in pcie_cap_v1_fill()
108 static void pcie_cap_fill_slot_lnk(PCIDevice *dev) in pcie_cap_fill_slot_lnk() argument
110 PCIESlot *s = (PCIESlot *)object_dynamic_cast(OBJECT(dev), TYPE_PCIE_SLOT); in pcie_cap_fill_slot_lnk()
111 uint8_t *exp_cap = dev->config + dev->exp.exp_cap; in pcie_cap_fill_slot_lnk()
185 int pcie_cap_init(PCIDevice *dev, uint8_t offset, in pcie_cap_init() argument
193 assert(pci_is_express(dev)); in pcie_cap_init()
195 pos = pci_add_capability(dev, PCI_CAP_ID_EXP, offset, in pcie_cap_init()
200 dev->exp.exp_cap = pos; in pcie_cap_init()
201 exp_cap = dev->config + pos; in pcie_cap_init()
204 pcie_cap_v1_fill(dev, port, type, PCI_EXP_FLAGS_VER2); in pcie_cap_init()
207 pcie_cap_fill_slot_lnk(dev); in pcie_cap_init()
213 pci_set_word(dev->wmask + pos + PCI_EXP_DEVCTL2, PCI_EXP_DEVCTL2_EETLPPB); in pcie_cap_init()
215 if (dev->cap_present & QEMU_PCIE_EXTCAP_INIT) { in pcie_cap_init()
217 pci_set_long(dev->wmask + PCI_CONFIG_SPACE_SIZE, 0); in pcie_cap_init()
223 int pcie_cap_v1_init(PCIDevice *dev, uint8_t offset, uint8_t type, in pcie_cap_v1_init() argument
230 assert(pci_is_express(dev)); in pcie_cap_v1_init()
232 pos = pci_add_capability(dev, PCI_CAP_ID_EXP, offset, in pcie_cap_v1_init()
238 dev->exp.exp_cap = pos; in pcie_cap_v1_init()
240 pcie_cap_v1_fill(dev, port, type, PCI_EXP_FLAGS_VER1); in pcie_cap_v1_init()
246 pcie_endpoint_cap_common_init(PCIDevice *dev, uint8_t offset, uint8_t cap_size) in pcie_endpoint_cap_common_init() argument
257 if (pci_bus_is_express(pci_get_bus(dev)) in pcie_endpoint_cap_common_init()
258 && pci_bus_is_root(pci_get_bus(dev))) { in pcie_endpoint_cap_common_init()
263 return pcie_cap_v1_init(dev, offset, type, 0); in pcie_endpoint_cap_common_init()
265 ret = pcie_cap_init(dev, offset, type, 0, &local_err); in pcie_endpoint_cap_common_init()
275 int pcie_endpoint_cap_init(PCIDevice *dev, uint8_t offset) in pcie_endpoint_cap_init() argument
277 return pcie_endpoint_cap_common_init(dev, offset, PCI_EXP_VER2_SIZEOF); in pcie_endpoint_cap_init()
280 int pcie_endpoint_cap_v1_init(PCIDevice *dev, uint8_t offset) in pcie_endpoint_cap_v1_init() argument
282 return pcie_endpoint_cap_common_init(dev, offset, PCI_EXP_VER1_SIZEOF); in pcie_endpoint_cap_v1_init()
285 void pcie_cap_exit(PCIDevice *dev) in pcie_cap_exit() argument
287 pci_del_capability(dev, PCI_CAP_ID_EXP, PCI_EXP_VER2_SIZEOF); in pcie_cap_exit()
290 void pcie_cap_v1_exit(PCIDevice *dev) in pcie_cap_v1_exit() argument
292 pci_del_capability(dev, PCI_CAP_ID_EXP, PCI_EXP_VER1_SIZEOF); in pcie_cap_v1_exit()
295 uint8_t pcie_cap_get_type(const PCIDevice *dev) in pcie_cap_get_type() argument
297 uint32_t pos = dev->exp.exp_cap; in pcie_cap_get_type()
299 return (pci_get_word(dev->config + pos + PCI_EXP_FLAGS) & in pcie_cap_get_type()
303 uint8_t pcie_cap_get_version(const PCIDevice *dev) in pcie_cap_get_version() argument
305 uint32_t pos = dev->exp.exp_cap; in pcie_cap_get_version()
307 return pci_get_word(dev->config + pos + PCI_EXP_FLAGS) & PCI_EXP_FLAGS_VERS; in pcie_cap_get_version()
313 void pcie_cap_flags_set_vector(PCIDevice *dev, uint8_t vector) in pcie_cap_flags_set_vector() argument
315 uint8_t *exp_cap = dev->config + dev->exp.exp_cap; in pcie_cap_flags_set_vector()
322 uint8_t pcie_cap_flags_get_vector(PCIDevice *dev) in pcie_cap_flags_get_vector() argument
324 return (pci_get_word(dev->config + dev->exp.exp_cap + PCI_EXP_FLAGS) & in pcie_cap_flags_get_vector()
328 void pcie_cap_deverr_init(PCIDevice *dev) in pcie_cap_deverr_init() argument
330 uint32_t pos = dev->exp.exp_cap; in pcie_cap_deverr_init()
331 pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_DEVCAP, in pcie_cap_deverr_init()
333 pci_long_test_and_set_mask(dev->wmask + pos + PCI_EXP_DEVCTL, in pcie_cap_deverr_init()
336 pci_long_test_and_set_mask(dev->w1cmask + pos + PCI_EXP_DEVSTA, in pcie_cap_deverr_init()
341 void pcie_cap_deverr_reset(PCIDevice *dev) in pcie_cap_deverr_reset() argument
343 uint8_t *devctl = dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL; in pcie_cap_deverr_reset()
349 void pcie_cap_lnkctl_init(PCIDevice *dev) in pcie_cap_lnkctl_init() argument
351 uint32_t pos = dev->exp.exp_cap; in pcie_cap_lnkctl_init()
352 pci_long_test_and_set_mask(dev->wmask + pos + PCI_EXP_LNKCTL, in pcie_cap_lnkctl_init()
356 void pcie_cap_lnkctl_reset(PCIDevice *dev) in pcie_cap_lnkctl_reset() argument
358 uint8_t *lnkctl = dev->config + dev->exp.exp_cap + PCI_EXP_LNKCTL; in pcie_cap_lnkctl_reset()
363 static void hotplug_event_update_event_status(PCIDevice *dev) in hotplug_event_update_event_status() argument
365 uint32_t pos = dev->exp.exp_cap; in hotplug_event_update_event_status()
366 uint8_t *exp_cap = dev->config + pos; in hotplug_event_update_event_status()
370 dev->exp.hpev_notified = (sltctl & PCI_EXP_SLTCTL_HPIE) && in hotplug_event_update_event_status()
374 static void hotplug_event_notify(PCIDevice *dev) in hotplug_event_notify() argument
376 bool prev = dev->exp.hpev_notified; in hotplug_event_notify()
378 hotplug_event_update_event_status(dev); in hotplug_event_notify()
380 if (prev == dev->exp.hpev_notified) { in hotplug_event_notify()
390 if (msix_enabled(dev)) { in hotplug_event_notify()
391 msix_notify(dev, pcie_cap_flags_get_vector(dev)); in hotplug_event_notify()
392 } else if (msi_enabled(dev)) { in hotplug_event_notify()
393 msi_notify(dev, pcie_cap_flags_get_vector(dev)); in hotplug_event_notify()
394 } else if (pci_intx(dev) != -1) { in hotplug_event_notify()
395 pci_set_irq(dev, dev->exp.hpev_notified); in hotplug_event_notify()
399 static void hotplug_event_clear(PCIDevice *dev) in hotplug_event_clear() argument
401 hotplug_event_update_event_status(dev); in hotplug_event_clear()
402 if (!msix_enabled(dev) && !msi_enabled(dev) && pci_intx(dev) != -1 && in hotplug_event_clear()
403 !dev->exp.hpev_notified) { in hotplug_event_clear()
404 pci_irq_deassert(dev); in hotplug_event_clear()
408 void pcie_cap_slot_enable_power(PCIDevice *dev) in pcie_cap_slot_enable_power() argument
410 uint8_t *exp_cap = dev->config + dev->exp.exp_cap; in pcie_cap_slot_enable_power()
419 static void pcie_set_power_device(PCIBus *bus, PCIDevice *dev, void *opaque) in pcie_set_power_device() argument
423 pci_set_power(dev, *power); in pcie_set_power_device()
450 static void pcie_cap_slot_event(PCIDevice *dev, PCIExpressHotPlugEvent event) in pcie_cap_slot_event() argument
453 if (pci_word_test_and_set_mask(dev->config + dev->exp.exp_cap + in pcie_cap_slot_event()
457 hotplug_event_notify(dev); in pcie_cap_slot_event()
460 static void pcie_cap_slot_plug_common(PCIDevice *hotplug_dev, DeviceState *dev, in pcie_cap_slot_plug_common() argument
466 PCIE_DEV_PRINTF(PCI_DEVICE(dev), "hotplug state: 0x%x\n", sltsta); in pcie_cap_slot_plug_common()
475 void pcie_cap_slot_pre_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, in pcie_cap_slot_pre_plug_cb() argument
483 if (dev->hotplugged && (sltcap & PCI_EXP_SLTCAP_HPC) == 0) { in pcie_cap_slot_pre_plug_cb()
489 pcie_cap_slot_plug_common(PCI_DEVICE(hotplug_dev), dev, errp); in pcie_cap_slot_pre_plug_cb()
492 void pcie_cap_slot_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, in pcie_cap_slot_plug_cb() argument
497 PCIDevice *pci_dev = PCI_DEVICE(dev); in pcie_cap_slot_plug_cb()
508 if (!dev->hotplugged) { in pcie_cap_slot_plug_cb()
538 void pcie_cap_slot_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, in pcie_cap_slot_unplug_cb() argument
541 qdev_unrealize(dev); in pcie_cap_slot_unplug_cb()
544 static void pcie_unplug_device(PCIBus *bus, PCIDevice *dev, void *opaque) in pcie_unplug_device() argument
546 HotplugHandler *hotplug_ctrl = qdev_get_hotplug_handler(DEVICE(dev)); in pcie_unplug_device()
548 if (dev->partially_hotplugged) { in pcie_unplug_device()
549 dev->qdev.pending_deleted_event = false; in pcie_unplug_device()
552 hotplug_handler_unplug(hotplug_ctrl, DEVICE(dev), &error_abort); in pcie_unplug_device()
553 object_unparent(OBJECT(dev)); in pcie_unplug_device()
556 static void pcie_cap_slot_do_unplug(PCIDevice *dev) in pcie_cap_slot_do_unplug() argument
558 PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); in pcie_cap_slot_do_unplug()
559 uint8_t *exp_cap = dev->config + dev->exp.exp_cap; in pcie_cap_slot_do_unplug()
566 if (dev->cap_present & QEMU_PCIE_LNKSTA_DLLLA || in pcie_cap_slot_do_unplug()
576 DeviceState *dev, Error **errp) in pcie_cap_slot_unplug_request_cb() argument
579 PCIDevice *pci_dev = PCI_DEVICE(dev); in pcie_cap_slot_unplug_request_cb()
594 pcie_cap_slot_plug_common(hotplug_pdev, dev, &local_err); in pcie_cap_slot_unplug_request_cb()
606 dev->pending_deleted_event = true; in pcie_cap_slot_unplug_request_cb()
607 dev->pending_deleted_expires_ms = in pcie_cap_slot_unplug_request_cb()
635 void pcie_cap_slot_init(PCIDevice *dev, PCIESlot *s) in pcie_cap_slot_init() argument
637 uint32_t pos = dev->exp.exp_cap; in pcie_cap_slot_init()
639 pci_word_test_and_set_mask(dev->config + pos + PCI_EXP_FLAGS, in pcie_cap_slot_init()
642 pci_long_test_and_clear_mask(dev->config + pos + PCI_EXP_SLTCAP, in pcie_cap_slot_init()
644 pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCAP, in pcie_cap_slot_init()
656 (!s->hide_native_hotplug_cap || DEVICE(dev)->hotplugged)) { in pcie_cap_slot_init()
657 pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCAP, in pcie_cap_slot_init()
662 if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) { in pcie_cap_slot_init()
663 pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCAP, in pcie_cap_slot_init()
665 pci_word_test_and_clear_mask(dev->config + pos + PCI_EXP_SLTCTL, in pcie_cap_slot_init()
667 pci_word_test_and_set_mask(dev->wmask + pos + PCI_EXP_SLTCTL, in pcie_cap_slot_init()
671 pci_word_test_and_clear_mask(dev->config + pos + PCI_EXP_SLTCTL, in pcie_cap_slot_init()
674 pci_word_test_and_set_mask(dev->config + pos + PCI_EXP_SLTCTL, in pcie_cap_slot_init()
677 pci_word_test_and_set_mask(dev->wmask + pos + PCI_EXP_SLTCTL, in pcie_cap_slot_init()
689 pci_word_test_and_set_mask(dev->wmask + pos + PCI_EXP_SLTCTL, in pcie_cap_slot_init()
692 pci_word_test_and_set_mask(dev->w1cmask + pos + PCI_EXP_SLTSTA, in pcie_cap_slot_init()
696 pci_word_test_and_clear_mask(dev->cmask + pos + PCI_EXP_SLTSTA, in pcie_cap_slot_init()
699 dev->exp.hpev_notified = false; in pcie_cap_slot_init()
701 qbus_set_hotplug_handler(BUS(pci_bridge_get_sec_bus(PCI_BRIDGE(dev))), in pcie_cap_slot_init()
702 OBJECT(dev)); in pcie_cap_slot_init()
705 void pcie_cap_slot_reset(PCIDevice *dev) in pcie_cap_slot_reset() argument
707 uint8_t *exp_cap = dev->config + dev->exp.exp_cap; in pcie_cap_slot_reset()
708 uint8_t port_type = pcie_cap_get_type(dev); in pcie_cap_slot_reset()
713 PCIE_DEV_PRINTF(dev, "reset\n"); in pcie_cap_slot_reset()
727 if (dev->cap_present & QEMU_PCIE_SLTCAP_PCP) { in pcie_cap_slot_reset()
729 bool populated = pci_bridge_get_sec_bus(PCI_BRIDGE(dev))->devices[0]; in pcie_cap_slot_reset()
752 pcie_cap_update_power(dev); in pcie_cap_slot_reset()
753 hotplug_event_update_event_status(dev); in pcie_cap_slot_reset()
756 void pcie_cap_slot_get(PCIDevice *dev, uint16_t *slt_ctl, uint16_t *slt_sta) in pcie_cap_slot_get() argument
758 uint32_t pos = dev->exp.exp_cap; in pcie_cap_slot_get()
759 uint8_t *exp_cap = dev->config + pos; in pcie_cap_slot_get()
764 static void find_child_fn(PCIBus *bus, PCIDevice *dev, void *opaque) in find_child_fn() argument
769 *child = dev; in find_child_fn()
776 static PCIDevice *pcie_cap_slot_find_child(PCIDevice *dev) in pcie_cap_slot_find_child() argument
778 PCIBus *sec_bus = pci_bridge_get_sec_bus(PCI_BRIDGE(dev)); in pcie_cap_slot_find_child()
786 void pcie_cap_slot_write_config(PCIDevice *dev, in pcie_cap_slot_write_config() argument
790 uint32_t pos = dev->exp.exp_cap; in pcie_cap_slot_write_config()
791 uint8_t *exp_cap = dev->config + pos; in pcie_cap_slot_write_config()
814 hotplug_event_clear(dev); in pcie_cap_slot_write_config()
825 PCIE_DEV_PRINTF(dev, "PCI_EXP_SLTCTL_EIC: " in pcie_cap_slot_write_config()
831 DeviceState *parent = DEVICE(dev); in pcie_cap_slot_write_config()
832 DeviceState *child = DEVICE(pcie_cap_slot_find_child(dev)); in pcie_cap_slot_write_config()
857 pcie_cap_slot_do_unplug(dev); in pcie_cap_slot_write_config()
859 pcie_cap_update_power(dev); in pcie_cap_slot_write_config()
861 hotplug_event_notify(dev); in pcie_cap_slot_write_config()
879 pcie_cap_slot_event(dev, PCI_EXP_HP_EV_CCI); in pcie_cap_slot_write_config()
884 PCIDevice *dev = opaque; in pcie_cap_slot_post_load() local
885 hotplug_event_update_event_status(dev); in pcie_cap_slot_post_load()
886 pcie_cap_update_power(dev); in pcie_cap_slot_post_load()
890 void pcie_cap_slot_push_attention_button(PCIDevice *dev) in pcie_cap_slot_push_attention_button() argument
892 pcie_cap_slot_event(dev, PCI_EXP_HP_EV_ABP); in pcie_cap_slot_push_attention_button()
896 void pcie_cap_root_init(PCIDevice *dev) in pcie_cap_root_init() argument
898 pci_set_word(dev->wmask + dev->exp.exp_cap + PCI_EXP_RTCTL, in pcie_cap_root_init()
903 void pcie_cap_root_reset(PCIDevice *dev) in pcie_cap_root_reset() argument
905 pci_set_word(dev->config + dev->exp.exp_cap + PCI_EXP_RTCTL, 0); in pcie_cap_root_reset()
909 void pcie_cap_flr_init(PCIDevice *dev) in pcie_cap_flr_init() argument
911 pci_long_test_and_set_mask(dev->config + dev->exp.exp_cap + PCI_EXP_DEVCAP, in pcie_cap_flr_init()
919 pci_word_test_and_set_mask(dev->wmask + dev->exp.exp_cap + PCI_EXP_DEVCTL, in pcie_cap_flr_init()
923 void pcie_cap_flr_write_config(PCIDevice *dev, in pcie_cap_flr_write_config() argument
926 uint8_t *devctl = dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL; in pcie_cap_flr_write_config()
930 pci_device_reset(dev); in pcie_cap_flr_write_config()
938 void pcie_cap_arifwd_init(PCIDevice *dev) in pcie_cap_arifwd_init() argument
940 uint32_t pos = dev->exp.exp_cap; in pcie_cap_arifwd_init()
941 pci_long_test_and_set_mask(dev->config + pos + PCI_EXP_DEVCAP2, in pcie_cap_arifwd_init()
943 pci_long_test_and_set_mask(dev->wmask + pos + PCI_EXP_DEVCTL2, in pcie_cap_arifwd_init()
947 void pcie_cap_arifwd_reset(PCIDevice *dev) in pcie_cap_arifwd_reset() argument
949 uint8_t *devctl2 = dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL2; in pcie_cap_arifwd_reset()
953 bool pcie_cap_is_arifwd_enabled(const PCIDevice *dev) in pcie_cap_is_arifwd_enabled() argument
955 if (!pci_is_express(dev)) { in pcie_cap_is_arifwd_enabled()
958 if (!dev->exp.exp_cap) { in pcie_cap_is_arifwd_enabled()
962 return pci_get_long(dev->config + dev->exp.exp_cap + PCI_EXP_DEVCTL2) & in pcie_cap_is_arifwd_enabled()
975 static uint16_t pcie_find_capability_list(PCIDevice *dev, uint32_t cap_id, in pcie_find_capability_list() argument
980 uint32_t header = pci_get_long(dev->config + PCI_CONFIG_SPACE_SIZE); in pcie_find_capability_list()
993 header = pci_get_long(dev->config + next); in pcie_find_capability_list()
1006 uint16_t pcie_find_capability(PCIDevice *dev, uint16_t cap_id) in pcie_find_capability() argument
1008 return pcie_find_capability_list(dev, cap_id, NULL); in pcie_find_capability()
1011 static void pcie_ext_cap_set_next(PCIDevice *dev, uint16_t pos, uint16_t next) in pcie_ext_cap_set_next() argument
1013 uint32_t header = pci_get_long(dev->config + pos); in pcie_ext_cap_set_next()
1017 pci_set_long(dev->config + pos, header); in pcie_ext_cap_set_next()
1025 void pcie_add_capability(PCIDevice *dev, in pcie_add_capability() argument
1033 assert(pci_is_express(dev)); in pcie_add_capability()
1042 pcie_find_capability_list(dev, 0xffffffff, &prev); in pcie_add_capability()
1044 pcie_ext_cap_set_next(dev, prev, offset); in pcie_add_capability()
1046 pci_set_long(dev->config + offset, PCI_EXT_CAP(cap_id, cap_ver, 0)); in pcie_add_capability()
1049 memset(dev->wmask + offset, 0, size); in pcie_add_capability()
1050 memset(dev->w1cmask + offset, 0, size); in pcie_add_capability()
1052 memset(dev->cmask + offset, 0xFF, size); in pcie_add_capability()
1106 void pcie_ari_init(PCIDevice *dev, uint16_t offset) in pcie_ari_init() argument
1108 uint16_t nextfn = dev->cap_present & QEMU_PCIE_ARI_NEXTFN_1 ? 1 : 0; in pcie_ari_init()
1110 pcie_add_capability(dev, PCI_EXT_CAP_ID_ARI, PCI_ARI_VER, in pcie_ari_init()
1112 pci_set_long(dev->config + offset + PCI_ARI_CAP, (nextfn & 0xff) << 8); in pcie_ari_init()
1115 void pcie_dev_ser_num_init(PCIDevice *dev, uint16_t offset, uint64_t ser_num) in pcie_dev_ser_num_init() argument
1120 pcie_add_capability(dev, PCI_EXT_CAP_ID_DSN, pci_dsn_ver, offset, in pcie_dev_ser_num_init()
1122 pci_set_quad(dev->config + offset + pci_dsn_cap, ser_num); in pcie_dev_ser_num_init()
1125 void pcie_ats_init(PCIDevice *dev, uint16_t offset, bool aligned) in pcie_ats_init() argument
1127 pcie_add_capability(dev, PCI_EXT_CAP_ID_ATS, 0x1, in pcie_ats_init()
1130 dev->exp.ats_cap = offset; in pcie_ats_init()
1134 pci_set_word(dev->config + offset + PCI_ATS_CAP, in pcie_ats_init()
1138 pci_set_word(dev->config + offset + PCI_ATS_CTRL, 0); in pcie_ats_init()
1140 pci_set_word(dev->wmask + dev->exp.ats_cap + PCI_ATS_CTRL, 0x800f); in pcie_ats_init()
1144 void pcie_acs_init(PCIDevice *dev, uint16_t offset) in pcie_acs_init() argument
1146 bool is_downstream = pci_is_express_downstream_port(dev); in pcie_acs_init()
1151 (dev->cap_present & QEMU_PCI_CAP_MULTIFUNCTION) || in pcie_acs_init()
1152 PCI_FUNC(dev->devfn)); in pcie_acs_init()
1154 pcie_add_capability(dev, PCI_EXT_CAP_ID_ACS, PCI_ACS_VER, offset, in pcie_acs_init()
1156 dev->exp.acs_cap = offset; in pcie_acs_init()
1170 pci_set_word(dev->config + offset + PCI_ACS_CAP, cap_bits); in pcie_acs_init()
1171 pci_set_word(dev->wmask + offset + PCI_ACS_CTRL, cap_bits); in pcie_acs_init()
1174 void pcie_acs_reset(PCIDevice *dev) in pcie_acs_reset() argument
1176 if (dev->exp.acs_cap) { in pcie_acs_reset()
1177 pci_set_word(dev->config + dev->exp.acs_cap + PCI_ACS_CTRL, 0); in pcie_acs_reset()