4 * Copyright 2014 IBM Corp.
5 * Author(s): Frank Blaschka <frank.blaschka@de.ibm.com>
6 * Hong Bo Li <lihbbj@cn.ibm.com>
7 * Yi Min Zhao <zyimin@cn.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or (at
10 * your option) any later version. See the COPYING file in the top-level
14 #include "qemu/osdep.h"
15 #include "qapi/error.h"
16 #include "qapi/visitor.h"
17 #include "hw/s390x/s390-pci-bus.h"
18 #include "hw/s390x/s390-pci-inst.h"
19 #include "hw/s390x/s390-pci-kvm.h"
20 #include "hw/s390x/s390-pci-vfio.h"
21 #include "hw/pci/pci_bus.h"
22 #include "hw/qdev-properties.h"
23 #include "hw/pci/pci_bridge.h"
24 #include "hw/pci/msi.h"
25 #include "qemu/error-report.h"
26 #include "qemu/module.h"
28 #ifndef DEBUG_S390PCI_BUS
29 #define DEBUG_S390PCI_BUS 0
32 #define DPRINTF(fmt, ...) \
34 if (DEBUG_S390PCI_BUS) { \
35 fprintf(stderr, "S390pci-bus: " fmt, ## __VA_ARGS__); \
39 S390pciState
*s390_get_phb(void)
41 static S390pciState
*phb
;
44 phb
= S390_PCI_HOST_BRIDGE(
45 object_resolve_path(TYPE_S390_PCI_HOST_BRIDGE
, NULL
));
52 int pci_chsc_sei_nt2_get_event(void *res
)
54 ChscSeiNt2Res
*nt2_res
= (ChscSeiNt2Res
*)res
;
58 SeiContainer
*sei_cont
;
59 S390pciState
*s
= s390_get_phb();
61 sei_cont
= QTAILQ_FIRST(&s
->pending_sei
);
63 QTAILQ_REMOVE(&s
->pending_sei
, sei_cont
, link
);
65 nt2_res
->cc
= sei_cont
->cc
;
66 nt2_res
->length
= cpu_to_be16(sizeof(ChscSeiNt2Res
));
67 switch (sei_cont
->cc
) {
68 case 1: /* error event */
69 eccdf
= (PciCcdfErr
*)nt2_res
->ccdf
;
70 eccdf
->fid
= cpu_to_be32(sei_cont
->fid
);
71 eccdf
->fh
= cpu_to_be32(sei_cont
->fh
);
72 eccdf
->e
= cpu_to_be32(sei_cont
->e
);
73 eccdf
->faddr
= cpu_to_be64(sei_cont
->faddr
);
74 eccdf
->pec
= cpu_to_be16(sei_cont
->pec
);
76 case 2: /* availability event */
77 accdf
= (PciCcdfAvail
*)nt2_res
->ccdf
;
78 accdf
->fid
= cpu_to_be32(sei_cont
->fid
);
79 accdf
->fh
= cpu_to_be32(sei_cont
->fh
);
80 accdf
->pec
= cpu_to_be16(sei_cont
->pec
);
92 int pci_chsc_sei_nt2_have_event(void)
94 S390pciState
*s
= s390_get_phb();
96 return !QTAILQ_EMPTY(&s
->pending_sei
);
99 S390PCIBusDevice
*s390_pci_find_next_avail_dev(S390pciState
*s
,
100 S390PCIBusDevice
*pbdev
)
102 S390PCIBusDevice
*ret
= pbdev
? QTAILQ_NEXT(pbdev
, link
) :
103 QTAILQ_FIRST(&s
->zpci_devs
);
105 while (ret
&& ret
->state
== ZPCI_FS_RESERVED
) {
106 ret
= QTAILQ_NEXT(ret
, link
);
112 S390PCIBusDevice
*s390_pci_find_dev_by_fid(S390pciState
*s
, uint32_t fid
)
114 S390PCIBusDevice
*pbdev
;
116 QTAILQ_FOREACH(pbdev
, &s
->zpci_devs
, link
) {
117 if (pbdev
->fid
== fid
) {
125 void s390_pci_sclp_configure(SCCB
*sccb
)
127 IoaCfgSccb
*psccb
= (IoaCfgSccb
*)sccb
;
128 S390PCIBusDevice
*pbdev
= s390_pci_find_dev_by_fid(s390_get_phb(),
129 be32_to_cpu(psccb
->aid
));
133 DPRINTF("sclp config no dev found\n");
134 rc
= SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED
;
138 switch (pbdev
->state
) {
139 case ZPCI_FS_RESERVED
:
140 rc
= SCLP_RC_ADAPTER_IN_RESERVED_STATE
;
142 case ZPCI_FS_STANDBY
:
143 pbdev
->state
= ZPCI_FS_DISABLED
;
144 rc
= SCLP_RC_NORMAL_COMPLETION
;
147 rc
= SCLP_RC_NO_ACTION_REQUIRED
;
150 psccb
->header
.response_code
= cpu_to_be16(rc
);
153 static void s390_pci_perform_unplug(S390PCIBusDevice
*pbdev
)
155 HotplugHandler
*hotplug_ctrl
;
157 /* Unplug the PCI device */
159 DeviceState
*pdev
= DEVICE(pbdev
->pdev
);
161 hotplug_ctrl
= qdev_get_hotplug_handler(pdev
);
162 hotplug_handler_unplug(hotplug_ctrl
, pdev
, &error_abort
);
163 object_unparent(OBJECT(pdev
));
166 /* Unplug the zPCI device */
167 hotplug_ctrl
= qdev_get_hotplug_handler(DEVICE(pbdev
));
168 hotplug_handler_unplug(hotplug_ctrl
, DEVICE(pbdev
), &error_abort
);
169 object_unparent(OBJECT(pbdev
));
172 void s390_pci_sclp_deconfigure(SCCB
*sccb
)
174 IoaCfgSccb
*psccb
= (IoaCfgSccb
*)sccb
;
175 S390PCIBusDevice
*pbdev
= s390_pci_find_dev_by_fid(s390_get_phb(),
176 be32_to_cpu(psccb
->aid
));
180 DPRINTF("sclp deconfig no dev found\n");
181 rc
= SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED
;
185 switch (pbdev
->state
) {
186 case ZPCI_FS_RESERVED
:
187 rc
= SCLP_RC_ADAPTER_IN_RESERVED_STATE
;
189 case ZPCI_FS_STANDBY
:
190 rc
= SCLP_RC_NO_ACTION_REQUIRED
;
193 if (pbdev
->interp
&& (pbdev
->fh
& FH_MASK_ENABLE
)) {
194 /* Interpreted devices were using interrupt forwarding */
195 s390_pci_kvm_aif_disable(pbdev
);
196 } else if (pbdev
->summary_ind
) {
197 pci_dereg_irqs(pbdev
);
199 if (pbdev
->iommu
->enabled
) {
200 pci_dereg_ioat(pbdev
->iommu
);
202 pbdev
->state
= ZPCI_FS_STANDBY
;
203 rc
= SCLP_RC_NORMAL_COMPLETION
;
205 if (pbdev
->unplug_requested
) {
206 s390_pci_perform_unplug(pbdev
);
210 psccb
->header
.response_code
= cpu_to_be16(rc
);
213 static S390PCIBusDevice
*s390_pci_find_dev_by_uid(S390pciState
*s
, uint16_t uid
)
215 S390PCIBusDevice
*pbdev
;
217 QTAILQ_FOREACH(pbdev
, &s
->zpci_devs
, link
) {
218 if (pbdev
->uid
== uid
) {
226 S390PCIBusDevice
*s390_pci_find_dev_by_target(S390pciState
*s
,
229 S390PCIBusDevice
*pbdev
;
235 QTAILQ_FOREACH(pbdev
, &s
->zpci_devs
, link
) {
236 if (!strcmp(pbdev
->target
, target
)) {
244 static S390PCIBusDevice
*s390_pci_find_dev_by_pci(S390pciState
*s
,
247 S390PCIBusDevice
*pbdev
;
253 QTAILQ_FOREACH(pbdev
, &s
->zpci_devs
, link
) {
254 if (pbdev
->pdev
== pci_dev
) {
262 S390PCIBusDevice
*s390_pci_find_dev_by_idx(S390pciState
*s
, uint32_t idx
)
264 return g_hash_table_lookup(s
->zpci_table
, &idx
);
267 S390PCIBusDevice
*s390_pci_find_dev_by_fh(S390pciState
*s
, uint32_t fh
)
269 uint32_t idx
= FH_MASK_INDEX
& fh
;
270 S390PCIBusDevice
*pbdev
= s390_pci_find_dev_by_idx(s
, idx
);
272 if (pbdev
&& pbdev
->fh
== fh
) {
279 static void s390_pci_generate_event(uint8_t cc
, uint16_t pec
, uint32_t fh
,
280 uint32_t fid
, uint64_t faddr
, uint32_t e
)
282 SeiContainer
*sei_cont
;
283 S390pciState
*s
= s390_get_phb();
285 sei_cont
= g_new0(SeiContainer
, 1);
290 sei_cont
->faddr
= faddr
;
293 QTAILQ_INSERT_TAIL(&s
->pending_sei
, sei_cont
, link
);
294 css_generate_css_crws(0);
297 static void s390_pci_generate_plug_event(uint16_t pec
, uint32_t fh
,
300 s390_pci_generate_event(2, pec
, fh
, fid
, 0, 0);
303 void s390_pci_generate_error_event(uint16_t pec
, uint32_t fh
, uint32_t fid
,
304 uint64_t faddr
, uint32_t e
)
306 s390_pci_generate_event(1, pec
, fh
, fid
, faddr
, e
);
309 static void s390_pci_set_irq(void *opaque
, int irq
, int level
)
314 static int s390_pci_map_irq(PCIDevice
*pci_dev
, int irq_num
)
320 static uint64_t s390_pci_get_table_origin(uint64_t iota
)
322 return iota
& ~ZPCI_IOTA_RTTO_FLAG
;
325 static unsigned int calc_rtx(dma_addr_t ptr
)
327 return ((unsigned long) ptr
>> ZPCI_RT_SHIFT
) & ZPCI_INDEX_MASK
;
330 static unsigned int calc_sx(dma_addr_t ptr
)
332 return ((unsigned long) ptr
>> ZPCI_ST_SHIFT
) & ZPCI_INDEX_MASK
;
335 static unsigned int calc_px(dma_addr_t ptr
)
337 return ((unsigned long) ptr
>> TARGET_PAGE_BITS
) & ZPCI_PT_MASK
;
340 static uint64_t get_rt_sto(uint64_t entry
)
342 return ((entry
& ZPCI_TABLE_TYPE_MASK
) == ZPCI_TABLE_TYPE_RTX
)
343 ? (entry
& ZPCI_RTE_ADDR_MASK
)
347 static uint64_t get_st_pto(uint64_t entry
)
349 return ((entry
& ZPCI_TABLE_TYPE_MASK
) == ZPCI_TABLE_TYPE_SX
)
350 ? (entry
& ZPCI_STE_ADDR_MASK
)
354 static bool rt_entry_isvalid(uint64_t entry
)
356 return (entry
& ZPCI_TABLE_VALID_MASK
) == ZPCI_TABLE_VALID
;
359 static bool pt_entry_isvalid(uint64_t entry
)
361 return (entry
& ZPCI_PTE_VALID_MASK
) == ZPCI_PTE_VALID
;
364 static bool entry_isprotected(uint64_t entry
)
366 return (entry
& ZPCI_TABLE_PROT_MASK
) == ZPCI_TABLE_PROTECTED
;
369 /* ett is expected table type, -1 page table, 0 segment table, 1 region table */
370 static uint64_t get_table_index(uint64_t iova
, int8_t ett
)
374 return calc_px(iova
);
376 return calc_sx(iova
);
378 return calc_rtx(iova
);
384 static bool entry_isvalid(uint64_t entry
, int8_t ett
)
388 return pt_entry_isvalid(entry
);
391 return rt_entry_isvalid(entry
);
397 /* Return true if address translation is done */
398 static bool translate_iscomplete(uint64_t entry
, int8_t ett
)
402 return (entry
& ZPCI_TABLE_FC
) ? true : false;
410 static uint64_t get_frame_size(int8_t ett
)
424 static uint64_t get_next_table_origin(uint64_t entry
, int8_t ett
)
428 return entry
& ZPCI_PTE_ADDR_MASK
;
430 return get_st_pto(entry
);
432 return get_rt_sto(entry
);
439 * table_translate: do translation within one table and return the following
442 * @entry: the entry being translated, the result is stored in this.
443 * @to: the address of table origin.
444 * @ett: expected table type, 1 region table, 0 segment table and -1 page table.
447 static uint64_t table_translate(S390IOTLBEntry
*entry
, uint64_t to
, int8_t ett
,
450 uint64_t tx
, te
, nto
= 0;
453 tx
= get_table_index(entry
->iova
, ett
);
454 te
= address_space_ldq(&address_space_memory
, to
+ tx
* sizeof(uint64_t),
455 MEMTXATTRS_UNSPECIFIED
, NULL
);
458 err
= ERR_EVENT_INVALTE
;
462 if (!entry_isvalid(te
, ett
)) {
463 entry
->perm
&= IOMMU_NONE
;
467 if (ett
== ZPCI_ETT_RT
&& ((te
& ZPCI_TABLE_LEN_RTX
) != ZPCI_TABLE_LEN_RTX
468 || te
& ZPCI_TABLE_OFFSET_MASK
)) {
469 err
= ERR_EVENT_INVALTL
;
473 nto
= get_next_table_origin(te
, ett
);
479 if (entry_isprotected(te
)) {
480 entry
->perm
&= IOMMU_RO
;
482 entry
->perm
&= IOMMU_RW
;
485 if (translate_iscomplete(te
, ett
)) {
488 entry
->translated_addr
= te
& ZPCI_PTE_ADDR_MASK
;
491 entry
->translated_addr
= (te
& ZPCI_SFAA_MASK
) |
492 (entry
->iova
& ~ZPCI_SFAA_MASK
);
499 entry
->perm
= IOMMU_NONE
;
502 entry
->len
= get_frame_size(ett
);
506 uint16_t s390_guest_io_table_walk(uint64_t g_iota
, hwaddr addr
,
507 S390IOTLBEntry
*entry
)
509 uint64_t to
= s390_pci_get_table_origin(g_iota
);
513 entry
->iova
= addr
& TARGET_PAGE_MASK
;
514 entry
->translated_addr
= 0;
515 entry
->perm
= IOMMU_RW
;
517 if (entry_isprotected(g_iota
)) {
518 entry
->perm
&= IOMMU_RO
;
522 to
= table_translate(entry
, to
, ett
--, &error
);
528 static IOMMUTLBEntry
s390_translate_iommu(IOMMUMemoryRegion
*mr
, hwaddr addr
,
529 IOMMUAccessFlags flag
, int iommu_idx
)
531 S390PCIIOMMU
*iommu
= container_of(mr
, S390PCIIOMMU
, iommu_mr
);
532 S390IOTLBEntry
*entry
;
533 uint64_t iova
= addr
& TARGET_PAGE_MASK
;
535 IOMMUTLBEntry ret
= {
536 .target_as
= &address_space_memory
,
538 .translated_addr
= 0,
539 .addr_mask
= ~(hwaddr
)0,
543 switch (iommu
->pbdev
->state
) {
544 case ZPCI_FS_ENABLED
:
545 case ZPCI_FS_BLOCKED
:
546 if (!iommu
->enabled
) {
554 DPRINTF("iommu trans addr 0x%" PRIx64
"\n", addr
);
556 if (addr
< iommu
->pba
|| addr
> iommu
->pal
) {
557 error
= ERR_EVENT_OORANGE
;
561 entry
= g_hash_table_lookup(iommu
->iotlb
, &iova
);
563 ret
.iova
= entry
->iova
;
564 ret
.translated_addr
= entry
->translated_addr
;
565 ret
.addr_mask
= entry
->len
- 1;
566 ret
.perm
= entry
->perm
;
569 ret
.addr_mask
= ~TARGET_PAGE_MASK
;
570 ret
.perm
= IOMMU_NONE
;
573 if (flag
!= IOMMU_NONE
&& !(flag
& ret
.perm
)) {
574 error
= ERR_EVENT_TPROTE
;
578 iommu
->pbdev
->state
= ZPCI_FS_ERROR
;
579 s390_pci_generate_error_event(error
, iommu
->pbdev
->fh
,
580 iommu
->pbdev
->fid
, addr
, 0);
585 static void s390_pci_iommu_replay(IOMMUMemoryRegion
*iommu
,
586 IOMMUNotifier
*notifier
)
588 /* It's impossible to plug a pci device on s390x that already has iommu
589 * mappings which need to be replayed, that is due to the "one iommu per
590 * zpci device" construct. But when we support migration of vfio-pci
591 * devices in future, we need to revisit this.
596 static S390PCIIOMMU
*s390_pci_get_iommu(S390pciState
*s
, PCIBus
*bus
,
599 uint64_t key
= (uintptr_t)bus
;
600 S390PCIIOMMUTable
*table
= g_hash_table_lookup(s
->iommu_table
, &key
);
604 table
= g_new0(S390PCIIOMMUTable
, 1);
606 g_hash_table_insert(s
->iommu_table
, &table
->key
, table
);
609 iommu
= table
->iommu
[PCI_SLOT(devfn
)];
611 iommu
= S390_PCI_IOMMU(object_new(TYPE_S390_PCI_IOMMU
));
613 char *mr_name
= g_strdup_printf("iommu-root-%02x:%02x.%01x",
617 char *as_name
= g_strdup_printf("iommu-pci-%02x:%02x.%01x",
621 memory_region_init(&iommu
->mr
, OBJECT(iommu
), mr_name
, UINT64_MAX
);
622 address_space_init(&iommu
->as
, &iommu
->mr
, as_name
);
623 iommu
->iotlb
= g_hash_table_new_full(g_int64_hash
, g_int64_equal
,
625 table
->iommu
[PCI_SLOT(devfn
)] = iommu
;
634 static AddressSpace
*s390_pci_dma_iommu(PCIBus
*bus
, void *opaque
, int devfn
)
636 S390pciState
*s
= opaque
;
637 S390PCIIOMMU
*iommu
= s390_pci_get_iommu(s
, bus
, devfn
);
642 static uint8_t set_ind_atomic(uint64_t ind_loc
, uint8_t to_be_set
)
644 uint8_t expected
, actual
;
646 /* avoid multiple fetches */
647 uint8_t volatile *ind_addr
;
649 ind_addr
= cpu_physical_memory_map(ind_loc
, &len
, true);
651 s390_pci_generate_error_event(ERR_EVENT_AIRERR
, 0, 0, 0, 0);
657 actual
= qatomic_cmpxchg(ind_addr
, expected
, expected
| to_be_set
);
658 } while (actual
!= expected
);
659 cpu_physical_memory_unmap((void *)ind_addr
, len
, 1, len
);
664 static void s390_msi_ctrl_write(void *opaque
, hwaddr addr
, uint64_t data
,
667 S390PCIBusDevice
*pbdev
= opaque
;
668 uint32_t vec
= data
& ZPCI_MSI_VEC_MASK
;
673 DPRINTF("write_msix data 0x%" PRIx64
" idx %d vec 0x%x\n", data
,
676 if (pbdev
->state
!= ZPCI_FS_ENABLED
) {
680 ind_bit
= pbdev
->routes
.adapter
.ind_offset
;
681 sum_bit
= pbdev
->routes
.adapter
.summary_offset
;
683 set_ind_atomic(pbdev
->routes
.adapter
.ind_addr
+ (ind_bit
+ vec
) / 8,
684 0x80 >> ((ind_bit
+ vec
) % 8));
685 if (!set_ind_atomic(pbdev
->routes
.adapter
.summary_addr
+ sum_bit
/ 8,
686 0x80 >> (sum_bit
% 8))) {
687 css_adapter_interrupt(CSS_IO_ADAPTER_PCI
, pbdev
->isc
);
691 static uint64_t s390_msi_ctrl_read(void *opaque
, hwaddr addr
, unsigned size
)
696 static const MemoryRegionOps s390_msi_ctrl_ops
= {
697 .write
= s390_msi_ctrl_write
,
698 .read
= s390_msi_ctrl_read
,
699 .endianness
= DEVICE_LITTLE_ENDIAN
,
702 void s390_pci_iommu_enable(S390PCIIOMMU
*iommu
)
705 * The iommu region is initialized against a 0-mapped address space,
706 * so the smallest IOMMU region we can define runs from 0 to the end
707 * of the PCI address space.
709 char *name
= g_strdup_printf("iommu-s390-%04x", iommu
->pbdev
->uid
);
710 memory_region_init_iommu(&iommu
->iommu_mr
, sizeof(iommu
->iommu_mr
),
711 TYPE_S390_IOMMU_MEMORY_REGION
, OBJECT(&iommu
->mr
),
712 name
, iommu
->pal
+ 1);
713 iommu
->enabled
= true;
714 memory_region_add_subregion(&iommu
->mr
, 0, MEMORY_REGION(&iommu
->iommu_mr
));
718 void s390_pci_iommu_disable(S390PCIIOMMU
*iommu
)
720 iommu
->enabled
= false;
721 g_hash_table_remove_all(iommu
->iotlb
);
722 memory_region_del_subregion(&iommu
->mr
, MEMORY_REGION(&iommu
->iommu_mr
));
723 object_unparent(OBJECT(&iommu
->iommu_mr
));
726 static void s390_pci_iommu_free(S390pciState
*s
, PCIBus
*bus
, int32_t devfn
)
728 uint64_t key
= (uintptr_t)bus
;
729 S390PCIIOMMUTable
*table
= g_hash_table_lookup(s
->iommu_table
, &key
);
730 S390PCIIOMMU
*iommu
= table
? table
->iommu
[PCI_SLOT(devfn
)] : NULL
;
732 if (!table
|| !iommu
) {
736 table
->iommu
[PCI_SLOT(devfn
)] = NULL
;
737 g_hash_table_destroy(iommu
->iotlb
);
739 * An attached PCI device may have memory listeners, eg. VFIO PCI.
740 * The associated subregion will already have been unmapped in
741 * s390_pci_iommu_disable in response to the guest deconfigure request.
742 * Remove the listeners now before destroying the address space.
744 address_space_remove_listeners(&iommu
->as
);
745 address_space_destroy(&iommu
->as
);
746 object_unparent(OBJECT(&iommu
->mr
));
747 object_unparent(OBJECT(iommu
));
748 object_unref(OBJECT(iommu
));
751 S390PCIGroup
*s390_group_create(int id
)
754 S390pciState
*s
= s390_get_phb();
756 group
= g_new0(S390PCIGroup
, 1);
758 QTAILQ_INSERT_TAIL(&s
->zpci_groups
, group
, link
);
762 S390PCIGroup
*s390_group_find(int id
)
765 S390pciState
*s
= s390_get_phb();
767 QTAILQ_FOREACH(group
, &s
->zpci_groups
, link
) {
768 if (group
->id
== id
) {
775 static void s390_pci_init_default_group(void)
778 ClpRspQueryPciGrp
*resgrp
;
780 group
= s390_group_create(ZPCI_DEFAULT_FN_GRP
);
781 resgrp
= &group
->zpci_group
;
784 resgrp
->msia
= ZPCI_MSI_ADDR
;
785 resgrp
->mui
= DEFAULT_MUI
;
787 resgrp
->maxstbl
= 128;
789 resgrp
->dtsm
= ZPCI_DTSM
;
792 static void set_pbdev_info(S390PCIBusDevice
*pbdev
)
794 pbdev
->zpci_fn
.sdma
= ZPCI_SDMA_ADDR
;
795 pbdev
->zpci_fn
.edma
= ZPCI_EDMA_ADDR
;
796 pbdev
->zpci_fn
.pchid
= 0;
797 pbdev
->zpci_fn
.pfgid
= ZPCI_DEFAULT_FN_GRP
;
798 pbdev
->zpci_fn
.fid
= pbdev
->fid
;
799 pbdev
->zpci_fn
.uid
= pbdev
->uid
;
800 pbdev
->pci_group
= s390_group_find(ZPCI_DEFAULT_FN_GRP
);
803 static void s390_pcihost_realize(DeviceState
*dev
, Error
**errp
)
807 PCIHostState
*phb
= PCI_HOST_BRIDGE(dev
);
808 S390pciState
*s
= S390_PCI_HOST_BRIDGE(dev
);
810 DPRINTF("host_init\n");
812 b
= pci_register_root_bus(dev
, NULL
, s390_pci_set_irq
, s390_pci_map_irq
,
813 NULL
, get_system_memory(), get_system_io(), 0,
815 pci_setup_iommu(b
, s390_pci_dma_iommu
, s
);
818 qbus_set_hotplug_handler(bus
, OBJECT(dev
));
821 s
->bus
= S390_PCI_BUS(qbus_new(TYPE_S390_PCI_BUS
, dev
, NULL
));
822 qbus_set_hotplug_handler(BUS(s
->bus
), OBJECT(dev
));
824 s
->iommu_table
= g_hash_table_new_full(g_int64_hash
, g_int64_equal
,
826 s
->zpci_table
= g_hash_table_new_full(g_int_hash
, g_int_equal
, NULL
, NULL
);
828 QTAILQ_INIT(&s
->pending_sei
);
829 QTAILQ_INIT(&s
->zpci_devs
);
830 QTAILQ_INIT(&s
->zpci_dma_limit
);
831 QTAILQ_INIT(&s
->zpci_groups
);
833 s390_pci_init_default_group();
834 css_register_io_adapters(CSS_IO_ADAPTER_PCI
, true, false,
835 S390_ADAPTER_SUPPRESSIBLE
, errp
);
838 static void s390_pcihost_unrealize(DeviceState
*dev
)
841 S390pciState
*s
= S390_PCI_HOST_BRIDGE(dev
);
843 while (!QTAILQ_EMPTY(&s
->zpci_groups
)) {
844 group
= QTAILQ_FIRST(&s
->zpci_groups
);
845 QTAILQ_REMOVE(&s
->zpci_groups
, group
, link
);
849 static int s390_pci_msix_init(S390PCIBusDevice
*pbdev
)
856 pos
= pci_find_capability(pbdev
->pdev
, PCI_CAP_ID_MSIX
);
861 ctrl
= pci_host_config_read_common(pbdev
->pdev
, pos
+ PCI_MSIX_FLAGS
,
862 pci_config_size(pbdev
->pdev
), sizeof(ctrl
));
863 table
= pci_host_config_read_common(pbdev
->pdev
, pos
+ PCI_MSIX_TABLE
,
864 pci_config_size(pbdev
->pdev
), sizeof(table
));
865 pba
= pci_host_config_read_common(pbdev
->pdev
, pos
+ PCI_MSIX_PBA
,
866 pci_config_size(pbdev
->pdev
), sizeof(pba
));
868 pbdev
->msix
.table_bar
= table
& PCI_MSIX_FLAGS_BIRMASK
;
869 pbdev
->msix
.table_offset
= table
& ~PCI_MSIX_FLAGS_BIRMASK
;
870 pbdev
->msix
.pba_bar
= pba
& PCI_MSIX_FLAGS_BIRMASK
;
871 pbdev
->msix
.pba_offset
= pba
& ~PCI_MSIX_FLAGS_BIRMASK
;
872 pbdev
->msix
.entries
= (ctrl
& PCI_MSIX_FLAGS_QSIZE
) + 1;
874 name
= g_strdup_printf("msix-s390-%04x", pbdev
->uid
);
875 memory_region_init_io(&pbdev
->msix_notify_mr
, OBJECT(pbdev
),
876 &s390_msi_ctrl_ops
, pbdev
, name
, TARGET_PAGE_SIZE
);
877 memory_region_add_subregion(&pbdev
->iommu
->mr
,
878 pbdev
->pci_group
->zpci_group
.msia
,
879 &pbdev
->msix_notify_mr
);
885 static void s390_pci_msix_free(S390PCIBusDevice
*pbdev
)
887 if (pbdev
->msix
.entries
== 0) {
891 memory_region_del_subregion(&pbdev
->iommu
->mr
, &pbdev
->msix_notify_mr
);
892 object_unparent(OBJECT(&pbdev
->msix_notify_mr
));
895 static S390PCIBusDevice
*s390_pci_device_new(S390pciState
*s
,
896 const char *target
, Error
**errp
)
898 Error
*local_err
= NULL
;
901 dev
= qdev_try_new(TYPE_S390_PCI_DEVICE
);
903 error_setg(errp
, "zPCI device could not be created");
907 if (!object_property_set_str(OBJECT(dev
), "target", target
, &local_err
)) {
908 object_unparent(OBJECT(dev
));
909 error_propagate_prepend(errp
, local_err
,
910 "zPCI device could not be created: ");
913 if (!qdev_realize_and_unref(dev
, BUS(s
->bus
), &local_err
)) {
914 object_unparent(OBJECT(dev
));
915 error_propagate_prepend(errp
, local_err
,
916 "zPCI device could not be created: ");
920 return S390_PCI_DEVICE(dev
);
923 static bool s390_pci_alloc_idx(S390pciState
*s
, S390PCIBusDevice
*pbdev
)
928 while (s390_pci_find_dev_by_idx(s
, idx
)) {
929 idx
= (idx
+ 1) & FH_MASK_INDEX
;
930 if (idx
== s
->next_idx
) {
939 static void s390_pcihost_pre_plug(HotplugHandler
*hotplug_dev
, DeviceState
*dev
,
942 S390pciState
*s
= S390_PCI_HOST_BRIDGE(hotplug_dev
);
944 if (!s390_has_feat(S390_FEAT_ZPCI
)) {
945 warn_report("Plugging a PCI/zPCI device without the 'zpci' CPU "
946 "feature enabled; the guest will not be able to see/use "
950 if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_DEVICE
)) {
951 PCIDevice
*pdev
= PCI_DEVICE(dev
);
953 if (pdev
->cap_present
& QEMU_PCI_CAP_MULTIFUNCTION
) {
954 error_setg(errp
, "multifunction not supported in s390");
957 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_S390_PCI_DEVICE
)) {
958 S390PCIBusDevice
*pbdev
= S390_PCI_DEVICE(dev
);
960 if (!s390_pci_alloc_idx(s
, pbdev
)) {
961 error_setg(errp
, "no slot for plugging zpci device");
967 static void s390_pci_update_subordinate(PCIDevice
*dev
, uint32_t nr
)
971 pci_default_write_config(dev
, PCI_SUBORDINATE_BUS
, nr
, 1);
972 while (!pci_bus_is_root(pci_get_bus(dev
))) {
973 dev
= pci_get_bus(dev
)->parent_dev
;
975 old_nr
= pci_default_read_config(dev
, PCI_SUBORDINATE_BUS
, 1);
977 pci_default_write_config(dev
, PCI_SUBORDINATE_BUS
, nr
, 1);
982 static int s390_pci_interp_plug(S390pciState
*s
, S390PCIBusDevice
*pbdev
)
986 if (!s390_pci_get_host_fh(pbdev
, &fh
)) {
991 * The host device is already in an enabled state, but we always present
992 * the initial device state to the guest as disabled (ZPCI_FS_DISABLED).
993 * Therefore, mask off the enable bit from the passthrough handle until
994 * the guest issues a CLP SET PCI FN later to enable the device.
996 pbdev
->fh
= fh
& ~FH_MASK_ENABLE
;
998 /* Next, see if the idx is already in-use */
999 idx
= pbdev
->fh
& FH_MASK_INDEX
;
1000 if (pbdev
->idx
!= idx
) {
1001 if (s390_pci_find_dev_by_idx(s
, idx
)) {
1005 * Update the idx entry with the passed through idx
1006 * If the relinquished idx is lower than next_idx, use it
1007 * to replace next_idx
1009 g_hash_table_remove(s
->zpci_table
, &pbdev
->idx
);
1010 if (idx
< s
->next_idx
) {
1014 g_hash_table_insert(s
->zpci_table
, &pbdev
->idx
, pbdev
);
1020 static void s390_pcihost_plug(HotplugHandler
*hotplug_dev
, DeviceState
*dev
,
1023 S390pciState
*s
= S390_PCI_HOST_BRIDGE(hotplug_dev
);
1024 PCIDevice
*pdev
= NULL
;
1025 S390PCIBusDevice
*pbdev
= NULL
;
1028 if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_BRIDGE
)) {
1029 PCIBridge
*pb
= PCI_BRIDGE(dev
);
1031 pdev
= PCI_DEVICE(dev
);
1032 pci_bridge_map_irq(pb
, dev
->id
, s390_pci_map_irq
);
1033 pci_setup_iommu(&pb
->sec_bus
, s390_pci_dma_iommu
, s
);
1035 qbus_set_hotplug_handler(BUS(&pb
->sec_bus
), OBJECT(s
));
1037 if (dev
->hotplugged
) {
1038 pci_default_write_config(pdev
, PCI_PRIMARY_BUS
,
1039 pci_dev_bus_num(pdev
), 1);
1041 pci_default_write_config(pdev
, PCI_SECONDARY_BUS
, s
->bus_no
, 1);
1043 s390_pci_update_subordinate(pdev
, s
->bus_no
);
1045 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_DEVICE
)) {
1046 pdev
= PCI_DEVICE(dev
);
1049 /* In the case the PCI device does not define an id */
1050 /* we generate one based on the PCI address */
1051 dev
->id
= g_strdup_printf("auto_%02x:%02x.%01x",
1052 pci_dev_bus_num(pdev
),
1053 PCI_SLOT(pdev
->devfn
),
1054 PCI_FUNC(pdev
->devfn
));
1057 pbdev
= s390_pci_find_dev_by_target(s
, dev
->id
);
1059 pbdev
= s390_pci_device_new(s
, dev
->id
, errp
);
1066 pbdev
->iommu
= s390_pci_get_iommu(s
, pci_get_bus(pdev
), pdev
->devfn
);
1067 pbdev
->iommu
->pbdev
= pbdev
;
1068 pbdev
->state
= ZPCI_FS_DISABLED
;
1069 set_pbdev_info(pbdev
);
1071 if (object_dynamic_cast(OBJECT(dev
), "vfio-pci")) {
1073 * By default, interpretation is always requested; if the available
1074 * facilities indicate it is not available, fallback to the
1075 * interception model.
1077 if (pbdev
->interp
) {
1078 if (s390_pci_kvm_interp_allowed()) {
1079 rc
= s390_pci_interp_plug(s
, pbdev
);
1081 error_setg(errp
, "Plug failed for zPCI device in "
1082 "interpretation mode: %d", rc
);
1086 DPRINTF("zPCI interpretation facilities missing.\n");
1087 pbdev
->interp
= false;
1088 pbdev
->forwarding_assist
= false;
1091 pbdev
->iommu
->dma_limit
= s390_pci_start_dma_count(s
, pbdev
);
1092 /* Fill in CLP information passed via the vfio region */
1093 s390_pci_get_clp_info(pbdev
);
1094 if (!pbdev
->interp
) {
1095 /* Do vfio passthrough but intercept for I/O */
1096 pbdev
->fh
|= FH_SHM_VFIO
;
1097 pbdev
->forwarding_assist
= false;
1100 pbdev
->fh
|= FH_SHM_EMUL
;
1101 /* Always intercept emulated devices */
1102 pbdev
->interp
= false;
1103 pbdev
->forwarding_assist
= false;
1106 if (s390_pci_msix_init(pbdev
) && !pbdev
->interp
) {
1107 error_setg(errp
, "MSI-X support is mandatory "
1108 "in the S390 architecture");
1112 if (dev
->hotplugged
) {
1113 s390_pci_generate_plug_event(HP_EVENT_TO_CONFIGURED
,
1114 pbdev
->fh
, pbdev
->fid
);
1116 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_S390_PCI_DEVICE
)) {
1117 pbdev
= S390_PCI_DEVICE(dev
);
1119 /* the allocated idx is actually getting used */
1120 s
->next_idx
= (pbdev
->idx
+ 1) & FH_MASK_INDEX
;
1121 pbdev
->fh
= pbdev
->idx
;
1122 QTAILQ_INSERT_TAIL(&s
->zpci_devs
, pbdev
, link
);
1123 g_hash_table_insert(s
->zpci_table
, &pbdev
->idx
, pbdev
);
1125 g_assert_not_reached();
1129 static void s390_pcihost_unplug(HotplugHandler
*hotplug_dev
, DeviceState
*dev
,
1132 S390pciState
*s
= S390_PCI_HOST_BRIDGE(hotplug_dev
);
1133 S390PCIBusDevice
*pbdev
= NULL
;
1135 if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_DEVICE
)) {
1136 PCIDevice
*pci_dev
= PCI_DEVICE(dev
);
1140 pbdev
= s390_pci_find_dev_by_pci(s
, PCI_DEVICE(dev
));
1143 s390_pci_generate_plug_event(HP_EVENT_STANDBY_TO_RESERVED
,
1144 pbdev
->fh
, pbdev
->fid
);
1145 bus
= pci_get_bus(pci_dev
);
1146 devfn
= pci_dev
->devfn
;
1147 qdev_unrealize(dev
);
1149 s390_pci_msix_free(pbdev
);
1150 s390_pci_iommu_free(s
, bus
, devfn
);
1152 pbdev
->state
= ZPCI_FS_RESERVED
;
1153 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_S390_PCI_DEVICE
)) {
1154 pbdev
= S390_PCI_DEVICE(dev
);
1156 QTAILQ_REMOVE(&s
->zpci_devs
, pbdev
, link
);
1157 g_hash_table_remove(s
->zpci_table
, &pbdev
->idx
);
1158 if (pbdev
->iommu
->dma_limit
) {
1159 s390_pci_end_dma_count(s
, pbdev
->iommu
->dma_limit
);
1161 qdev_unrealize(dev
);
1165 static void s390_pcihost_unplug_request(HotplugHandler
*hotplug_dev
,
1169 S390pciState
*s
= S390_PCI_HOST_BRIDGE(hotplug_dev
);
1170 S390PCIBusDevice
*pbdev
;
1172 if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_BRIDGE
)) {
1173 error_setg(errp
, "PCI bridge hot unplug currently not supported");
1174 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_PCI_DEVICE
)) {
1176 * Redirect the unplug request to the zPCI device and remember that
1177 * we've checked the PCI device already (to prevent endless recursion).
1179 pbdev
= s390_pci_find_dev_by_pci(s
, PCI_DEVICE(dev
));
1181 pbdev
->pci_unplug_request_processed
= true;
1182 qdev_unplug(DEVICE(pbdev
), errp
);
1183 } else if (object_dynamic_cast(OBJECT(dev
), TYPE_S390_PCI_DEVICE
)) {
1184 pbdev
= S390_PCI_DEVICE(dev
);
1187 * If unplug was initially requested for the zPCI device, we
1188 * first have to redirect to the PCI device, which will in return
1189 * redirect back to us after performing its checks (if the request
1190 * is not blocked, e.g. because it's a PCI bridge).
1192 if (pbdev
->pdev
&& !pbdev
->pci_unplug_request_processed
) {
1193 qdev_unplug(DEVICE(pbdev
->pdev
), errp
);
1196 pbdev
->pci_unplug_request_processed
= false;
1198 switch (pbdev
->state
) {
1199 case ZPCI_FS_STANDBY
:
1200 case ZPCI_FS_RESERVED
:
1201 s390_pci_perform_unplug(pbdev
);
1205 * Allow to send multiple requests, e.g. if the guest crashed
1206 * before releasing the device, we would not be able to send
1207 * another request to the same VM (e.g. fresh OS).
1209 pbdev
->unplug_requested
= true;
1210 s390_pci_generate_plug_event(HP_EVENT_DECONFIGURE_REQUEST
,
1211 pbdev
->fh
, pbdev
->fid
);
1214 g_assert_not_reached();
1218 static void s390_pci_enumerate_bridge(PCIBus
*bus
, PCIDevice
*pdev
,
1221 S390pciState
*s
= opaque
;
1222 PCIBus
*sec_bus
= NULL
;
1224 if ((pci_default_read_config(pdev
, PCI_HEADER_TYPE
, 1) !=
1225 PCI_HEADER_TYPE_BRIDGE
)) {
1230 pci_default_write_config(pdev
, PCI_PRIMARY_BUS
, pci_dev_bus_num(pdev
), 1);
1231 pci_default_write_config(pdev
, PCI_SECONDARY_BUS
, s
->bus_no
, 1);
1232 pci_default_write_config(pdev
, PCI_SUBORDINATE_BUS
, s
->bus_no
, 1);
1234 sec_bus
= pci_bridge_get_sec_bus(PCI_BRIDGE(pdev
));
1239 /* Assign numbers to all child bridges. The last is the highest number. */
1240 pci_for_each_device_under_bus(sec_bus
, s390_pci_enumerate_bridge
, s
);
1241 pci_default_write_config(pdev
, PCI_SUBORDINATE_BUS
, s
->bus_no
, 1);
1244 static void s390_pcihost_reset(DeviceState
*dev
)
1246 S390pciState
*s
= S390_PCI_HOST_BRIDGE(dev
);
1247 PCIBus
*bus
= s
->parent_obj
.bus
;
1248 S390PCIBusDevice
*pbdev
, *next
;
1250 /* Process all pending unplug requests */
1251 QTAILQ_FOREACH_SAFE(pbdev
, &s
->zpci_devs
, link
, next
) {
1252 if (pbdev
->unplug_requested
) {
1253 if (pbdev
->interp
&& (pbdev
->fh
& FH_MASK_ENABLE
)) {
1254 /* Interpreted devices were using interrupt forwarding */
1255 s390_pci_kvm_aif_disable(pbdev
);
1256 } else if (pbdev
->summary_ind
) {
1257 pci_dereg_irqs(pbdev
);
1259 if (pbdev
->iommu
->enabled
) {
1260 pci_dereg_ioat(pbdev
->iommu
);
1262 pbdev
->state
= ZPCI_FS_STANDBY
;
1263 s390_pci_perform_unplug(pbdev
);
1268 * When resetting a PCI bridge, the assigned numbers are set to 0. So
1269 * on every system reset, we also have to reassign numbers.
1272 pci_for_each_device_under_bus(bus
, s390_pci_enumerate_bridge
, s
);
1275 static void s390_pcihost_class_init(ObjectClass
*klass
, void *data
)
1277 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1278 HotplugHandlerClass
*hc
= HOTPLUG_HANDLER_CLASS(klass
);
1280 dc
->reset
= s390_pcihost_reset
;
1281 dc
->realize
= s390_pcihost_realize
;
1282 dc
->unrealize
= s390_pcihost_unrealize
;
1283 hc
->pre_plug
= s390_pcihost_pre_plug
;
1284 hc
->plug
= s390_pcihost_plug
;
1285 hc
->unplug_request
= s390_pcihost_unplug_request
;
1286 hc
->unplug
= s390_pcihost_unplug
;
1287 msi_nonbroken
= true;
1290 static const TypeInfo s390_pcihost_info
= {
1291 .name
= TYPE_S390_PCI_HOST_BRIDGE
,
1292 .parent
= TYPE_PCI_HOST_BRIDGE
,
1293 .instance_size
= sizeof(S390pciState
),
1294 .class_init
= s390_pcihost_class_init
,
1295 .interfaces
= (InterfaceInfo
[]) {
1296 { TYPE_HOTPLUG_HANDLER
},
1301 static const TypeInfo s390_pcibus_info
= {
1302 .name
= TYPE_S390_PCI_BUS
,
1304 .instance_size
= sizeof(S390PCIBus
),
1307 static uint16_t s390_pci_generate_uid(S390pciState
*s
)
1313 if (!s390_pci_find_dev_by_uid(s
, uid
)) {
1316 } while (uid
< ZPCI_MAX_UID
);
1318 return UID_UNDEFINED
;
1321 static uint32_t s390_pci_generate_fid(S390pciState
*s
, Error
**errp
)
1326 if (!s390_pci_find_dev_by_fid(s
, fid
)) {
1329 } while (fid
++ != ZPCI_MAX_FID
);
1331 error_setg(errp
, "no free fid could be found");
1335 static void s390_pci_device_realize(DeviceState
*dev
, Error
**errp
)
1337 S390PCIBusDevice
*zpci
= S390_PCI_DEVICE(dev
);
1338 S390pciState
*s
= s390_get_phb();
1340 if (!zpci
->target
) {
1341 error_setg(errp
, "target must be defined");
1345 if (s390_pci_find_dev_by_target(s
, zpci
->target
)) {
1346 error_setg(errp
, "target %s already has an associated zpci device",
1351 if (zpci
->uid
== UID_UNDEFINED
) {
1352 zpci
->uid
= s390_pci_generate_uid(s
);
1354 error_setg(errp
, "no free uid could be found");
1357 } else if (s390_pci_find_dev_by_uid(s
, zpci
->uid
)) {
1358 error_setg(errp
, "uid %u already in use", zpci
->uid
);
1362 if (!zpci
->fid_defined
) {
1363 Error
*local_error
= NULL
;
1365 zpci
->fid
= s390_pci_generate_fid(s
, &local_error
);
1367 error_propagate(errp
, local_error
);
1370 } else if (s390_pci_find_dev_by_fid(s
, zpci
->fid
)) {
1371 error_setg(errp
, "fid %u already in use", zpci
->fid
);
1375 zpci
->state
= ZPCI_FS_RESERVED
;
1376 zpci
->fmb
.format
= ZPCI_FMB_FORMAT
;
1379 static void s390_pci_device_reset(DeviceState
*dev
)
1381 S390PCIBusDevice
*pbdev
= S390_PCI_DEVICE(dev
);
1383 switch (pbdev
->state
) {
1384 case ZPCI_FS_RESERVED
:
1386 case ZPCI_FS_STANDBY
:
1389 pbdev
->fh
&= ~FH_MASK_ENABLE
;
1390 pbdev
->state
= ZPCI_FS_DISABLED
;
1394 if (pbdev
->interp
&& (pbdev
->fh
& FH_MASK_ENABLE
)) {
1395 /* Interpreted devices were using interrupt forwarding */
1396 s390_pci_kvm_aif_disable(pbdev
);
1397 } else if (pbdev
->summary_ind
) {
1398 pci_dereg_irqs(pbdev
);
1400 if (pbdev
->iommu
->enabled
) {
1401 pci_dereg_ioat(pbdev
->iommu
);
1404 fmb_timer_free(pbdev
);
1407 static void s390_pci_get_fid(Object
*obj
, Visitor
*v
, const char *name
,
1408 void *opaque
, Error
**errp
)
1410 Property
*prop
= opaque
;
1411 uint32_t *ptr
= object_field_prop_ptr(obj
, prop
);
1413 visit_type_uint32(v
, name
, ptr
, errp
);
1416 static void s390_pci_set_fid(Object
*obj
, Visitor
*v
, const char *name
,
1417 void *opaque
, Error
**errp
)
1419 S390PCIBusDevice
*zpci
= S390_PCI_DEVICE(obj
);
1420 Property
*prop
= opaque
;
1421 uint32_t *ptr
= object_field_prop_ptr(obj
, prop
);
1423 if (!visit_type_uint32(v
, name
, ptr
, errp
)) {
1426 zpci
->fid_defined
= true;
1429 static const PropertyInfo s390_pci_fid_propinfo
= {
1431 .get
= s390_pci_get_fid
,
1432 .set
= s390_pci_set_fid
,
1435 #define DEFINE_PROP_S390_PCI_FID(_n, _s, _f) \
1436 DEFINE_PROP(_n, _s, _f, s390_pci_fid_propinfo, uint32_t)
1438 static Property s390_pci_device_properties
[] = {
1439 DEFINE_PROP_UINT16("uid", S390PCIBusDevice
, uid
, UID_UNDEFINED
),
1440 DEFINE_PROP_S390_PCI_FID("fid", S390PCIBusDevice
, fid
),
1441 DEFINE_PROP_STRING("target", S390PCIBusDevice
, target
),
1442 DEFINE_PROP_BOOL("interpret", S390PCIBusDevice
, interp
, true),
1443 DEFINE_PROP_BOOL("forwarding-assist", S390PCIBusDevice
, forwarding_assist
,
1445 DEFINE_PROP_END_OF_LIST(),
1448 static const VMStateDescription s390_pci_device_vmstate
= {
1449 .name
= TYPE_S390_PCI_DEVICE
,
1451 * TODO: add state handling here, so migration works at least with
1452 * emulated pci devices on s390x
1457 static void s390_pci_device_class_init(ObjectClass
*klass
, void *data
)
1459 DeviceClass
*dc
= DEVICE_CLASS(klass
);
1461 dc
->desc
= "zpci device";
1462 set_bit(DEVICE_CATEGORY_MISC
, dc
->categories
);
1463 dc
->reset
= s390_pci_device_reset
;
1464 dc
->bus_type
= TYPE_S390_PCI_BUS
;
1465 dc
->realize
= s390_pci_device_realize
;
1466 device_class_set_props(dc
, s390_pci_device_properties
);
1467 dc
->vmsd
= &s390_pci_device_vmstate
;
1470 static const TypeInfo s390_pci_device_info
= {
1471 .name
= TYPE_S390_PCI_DEVICE
,
1472 .parent
= TYPE_DEVICE
,
1473 .instance_size
= sizeof(S390PCIBusDevice
),
1474 .class_init
= s390_pci_device_class_init
,
1477 static const TypeInfo s390_pci_iommu_info
= {
1478 .name
= TYPE_S390_PCI_IOMMU
,
1479 .parent
= TYPE_OBJECT
,
1480 .instance_size
= sizeof(S390PCIIOMMU
),
1483 static void s390_iommu_memory_region_class_init(ObjectClass
*klass
, void *data
)
1485 IOMMUMemoryRegionClass
*imrc
= IOMMU_MEMORY_REGION_CLASS(klass
);
1487 imrc
->translate
= s390_translate_iommu
;
1488 imrc
->replay
= s390_pci_iommu_replay
;
1491 static const TypeInfo s390_iommu_memory_region_info
= {
1492 .parent
= TYPE_IOMMU_MEMORY_REGION
,
1493 .name
= TYPE_S390_IOMMU_MEMORY_REGION
,
1494 .class_init
= s390_iommu_memory_region_class_init
,
1497 static void s390_pci_register_types(void)
1499 type_register_static(&s390_pcihost_info
);
1500 type_register_static(&s390_pcibus_info
);
1501 type_register_static(&s390_pci_device_info
);
1502 type_register_static(&s390_pci_iommu_info
);
1503 type_register_static(&s390_iommu_memory_region_info
);
1506 type_init(s390_pci_register_types
)