2 * SPDX-License-Identifier: GPL-2.0-or-later
4 * Emulation of a CXL Switch Mailbox CCI PCIe function.
6 * Copyright (c) 2023 Huawei Technologies.
8 * From www.computeexpresslink.org
9 * Compute Express Link (CXL) Specification revision 3.0 Version 1.0
11 #include "qemu/osdep.h"
12 #include "hw/pci/pci.h"
13 #include "hw/pci-bridge/cxl_upstream_port.h"
14 #include "qapi/error.h"
16 #include "qemu/module.h"
17 #include "hw/qdev-properties.h"
18 #include "hw/cxl/cxl.h"
20 static void cswmbcci_reset(DeviceState
*dev
)
22 CSWMBCCIDev
*cswmb
= CXL_SWITCH_MAILBOX_CCI(dev
);
23 cxl_device_register_init_swcci(cswmb
);
26 static void cswbcci_realize(PCIDevice
*pci_dev
, Error
**errp
)
28 CSWMBCCIDev
*cswmb
= CXL_SWITCH_MAILBOX_CCI(pci_dev
);
29 CXLComponentState
*cxl_cstate
= &cswmb
->cxl_cstate
;
30 CXLDeviceState
*cxl_dstate
= &cswmb
->cxl_dstate
;
31 CXLDVSECRegisterLocator
*regloc_dvsec
;
35 error_setg(errp
, "Target not set");
38 usp
= CXL_USP(cswmb
->target
);
40 pcie_endpoint_cap_init(pci_dev
, 0x80);
41 cxl_cstate
->dvsec_offset
= 0x100;
42 cxl_cstate
->pdev
= pci_dev
;
43 cswmb
->cci
= &usp
->swcci
;
44 cxl_device_register_block_init(OBJECT(pci_dev
), cxl_dstate
, cswmb
->cci
);
45 pci_register_bar(pci_dev
, 0,
46 PCI_BASE_ADDRESS_SPACE_MEMORY
|
47 PCI_BASE_ADDRESS_MEM_TYPE_64
,
48 &cxl_dstate
->device_registers
);
49 regloc_dvsec
= &(CXLDVSECRegisterLocator
) {
51 .reg0_base_lo
= RBI_CXL_DEVICE_REG
| 0,
54 cxl_component_create_dvsec(cxl_cstate
, CXL3_SWITCH_MAILBOX_CCI
,
55 REG_LOC_DVSEC_LENGTH
, REG_LOC_DVSEC
,
56 REG_LOC_DVSEC_REVID
, (uint8_t *)regloc_dvsec
);
58 cxl_initialize_mailbox_swcci(cswmb
->cci
, DEVICE(pci_dev
),
59 DEVICE(cswmb
->target
),
60 CXL_MAILBOX_MAX_PAYLOAD_SIZE
);
63 static void cswmbcci_exit(PCIDevice
*pci_dev
)
65 /* Nothing to do here yet */
68 static Property cxl_switch_cci_props
[] = {
69 DEFINE_PROP_LINK("target", CSWMBCCIDev
,
70 target
, TYPE_CXL_USP
, PCIDevice
*),
71 DEFINE_PROP_END_OF_LIST(),
74 static void cswmbcci_class_init(ObjectClass
*oc
, void *data
)
76 DeviceClass
*dc
= DEVICE_CLASS(oc
);
77 PCIDeviceClass
*pc
= PCI_DEVICE_CLASS(oc
);
79 pc
->realize
= cswbcci_realize
;
80 pc
->exit
= cswmbcci_exit
;
81 /* Serial bus, CXL Switch CCI */
82 pc
->class_id
= 0x0c0b;
85 * CXL Switch Mailbox CCI - DID assigned for emulation only.
86 * No real hardware will ever use this ID.
88 pc
->vendor_id
= 0x19e5;
89 pc
->device_id
= 0xa123;
91 dc
->desc
= "CXL Switch Mailbox CCI";
92 dc
->reset
= cswmbcci_reset
;
93 device_class_set_props(dc
, cxl_switch_cci_props
);
96 static const TypeInfo cswmbcci_info
= {
97 .name
= TYPE_CXL_SWITCH_MAILBOX_CCI
,
98 .parent
= TYPE_PCI_DEVICE
,
99 .class_init
= cswmbcci_class_init
,
100 .instance_size
= sizeof(CSWMBCCIDev
),
101 .interfaces
= (InterfaceInfo
[]) {
102 { INTERFACE_PCIE_DEVICE
},
107 static void cxl_switch_mailbox_cci_register(void)
109 type_register_static(&cswmbcci_info
);
111 type_init(cxl_switch_mailbox_cci_register
);