2 * Microchip PolarFire SoC IOSCB module emulation
4 * Copyright (c) 2020 Wind River Systems, Inc.
7 * Bin Meng <bin.meng@windriver.com>
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 or
12 * (at your option) version 3 of the License.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "qemu/osdep.h"
24 #include "qemu/bitops.h"
26 #include "qapi/error.h"
28 #include "hw/sysbus.h"
29 #include "hw/misc/mchp_pfsoc_ioscb.h"
32 * The whole IOSCB module registers map into the system address at 0x3000_0000,
33 * named as "System Port 0 (AXI-D0)".
35 #define IOSCB_WHOLE_REG_SIZE 0x10000000
36 #define IOSCB_SUBMOD_REG_SIZE 0x1000
37 #define IOSCB_CCC_REG_SIZE 0x2000000
38 #define IOSCB_CTRL_REG_SIZE 0x800
39 #define IOSCB_QSPIXIP_REG_SIZE 0x200
43 * There are many sub-modules in the IOSCB module.
44 * See Microchip PolarFire SoC documentation (Register_Map.zip),
45 * Register Map/PF_SoC_RegMap_V1_1/MPFS250T/mpfs250t_ioscb_memmap_dri.htm
47 * The following are sub-modules offsets that are of concern.
49 #define IOSCB_LANE01_BASE 0x06500000
50 #define IOSCB_LANE23_BASE 0x06510000
51 #define IOSCB_CTRL_BASE 0x07020000
52 #define IOSCB_QSPIXIP_BASE 0x07020100
53 #define IOSCB_MAILBOX_BASE 0x07020800
54 #define IOSCB_CFG_BASE 0x07080000
55 #define IOSCB_CCC_BASE 0x08000000
56 #define IOSCB_PLL_MSS_BASE 0x0E001000
57 #define IOSCB_CFM_MSS_BASE 0x0E002000
58 #define IOSCB_PLL_DDR_BASE 0x0E010000
59 #define IOSCB_BC_DDR_BASE 0x0E020000
60 #define IOSCB_IO_CALIB_DDR_BASE 0x0E040000
61 #define IOSCB_PLL_SGMII_BASE 0x0E080000
62 #define IOSCB_DLL_SGMII_BASE 0x0E100000
63 #define IOSCB_CFM_SGMII_BASE 0x0E200000
64 #define IOSCB_BC_SGMII_BASE 0x0E400000
65 #define IOSCB_IO_CALIB_SGMII_BASE 0x0E800000
67 static uint64_t mchp_pfsoc_dummy_read(void *opaque
, hwaddr offset
,
70 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented device read "
71 "(size %d, offset 0x%" HWADDR_PRIx
")\n",
72 __func__
, size
, offset
);
77 static void mchp_pfsoc_dummy_write(void *opaque
, hwaddr offset
,
78 uint64_t value
, unsigned size
)
80 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented device write "
81 "(size %d, value 0x%" PRIx64
82 ", offset 0x%" HWADDR_PRIx
")\n",
83 __func__
, size
, value
, offset
);
86 static const MemoryRegionOps mchp_pfsoc_dummy_ops
= {
87 .read
= mchp_pfsoc_dummy_read
,
88 .write
= mchp_pfsoc_dummy_write
,
89 .endianness
= DEVICE_LITTLE_ENDIAN
,
92 /* All PLL modules in IOSCB have the same register layout */
96 static uint64_t mchp_pfsoc_pll_read(void *opaque
, hwaddr offset
,
107 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented device read "
108 "(size %d, offset 0x%" HWADDR_PRIx
")\n",
109 __func__
, size
, offset
);
116 static const MemoryRegionOps mchp_pfsoc_pll_ops
= {
117 .read
= mchp_pfsoc_pll_read
,
118 .write
= mchp_pfsoc_dummy_write
,
119 .endianness
= DEVICE_LITTLE_ENDIAN
,
122 /* IO_CALIB_DDR submodule */
124 #define IO_CALIB_DDR_IOC_REG1 0x08
126 static uint64_t mchp_pfsoc_io_calib_ddr_read(void *opaque
, hwaddr offset
,
132 case IO_CALIB_DDR_IOC_REG1
:
133 /* calibration completed */
137 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented device read "
138 "(size %d, offset 0x%" HWADDR_PRIx
")\n",
139 __func__
, size
, offset
);
146 static const MemoryRegionOps mchp_pfsoc_io_calib_ddr_ops
= {
147 .read
= mchp_pfsoc_io_calib_ddr_read
,
148 .write
= mchp_pfsoc_dummy_write
,
149 .endianness
= DEVICE_LITTLE_ENDIAN
,
152 #define SERVICES_CR 0x50
153 #define SERVICES_SR 0x54
154 #define SERVICES_STATUS_SHIFT 16
156 static uint64_t mchp_pfsoc_ctrl_read(void *opaque
, hwaddr offset
,
164 * Although some services have no error codes, most do. All services
165 * that do implement errors, begin their error codes at 1. Treat all
166 * service requests as failures & return 1.
167 * See the "PolarFire® FPGA and PolarFire SoC FPGA System Services"
168 * user guide for more information on service error codes.
170 val
= 1u << SERVICES_STATUS_SHIFT
;
173 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented device read "
174 "(size %d, offset 0x%" HWADDR_PRIx
")\n",
175 __func__
, size
, offset
);
181 static void mchp_pfsoc_ctrl_write(void *opaque
, hwaddr offset
,
182 uint64_t value
, unsigned size
)
184 MchpPfSoCIoscbState
*s
= opaque
;
188 qemu_irq_raise(s
->irq
);
191 qemu_log_mask(LOG_UNIMP
, "%s: unimplemented device write "
192 "(size %d, value 0x%" PRIx64
193 ", offset 0x%" HWADDR_PRIx
")\n",
194 __func__
, size
, value
, offset
);
198 static const MemoryRegionOps mchp_pfsoc_ctrl_ops
= {
199 .read
= mchp_pfsoc_ctrl_read
,
200 .write
= mchp_pfsoc_ctrl_write
,
201 .endianness
= DEVICE_LITTLE_ENDIAN
,
204 static void mchp_pfsoc_ioscb_realize(DeviceState
*dev
, Error
**errp
)
206 MchpPfSoCIoscbState
*s
= MCHP_PFSOC_IOSCB(dev
);
207 SysBusDevice
*sbd
= SYS_BUS_DEVICE(dev
);
209 memory_region_init(&s
->container
, OBJECT(s
),
210 "mchp.pfsoc.ioscb", IOSCB_WHOLE_REG_SIZE
);
211 sysbus_init_mmio(sbd
, &s
->container
);
213 /* add subregions for all sub-modules in IOSCB */
215 memory_region_init_io(&s
->lane01
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
216 "mchp.pfsoc.ioscb.lane01", IOSCB_SUBMOD_REG_SIZE
);
217 memory_region_add_subregion(&s
->container
, IOSCB_LANE01_BASE
, &s
->lane01
);
219 memory_region_init_io(&s
->lane23
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
220 "mchp.pfsoc.ioscb.lane23", IOSCB_SUBMOD_REG_SIZE
);
221 memory_region_add_subregion(&s
->container
, IOSCB_LANE23_BASE
, &s
->lane23
);
223 memory_region_init_io(&s
->ctrl
, OBJECT(s
), &mchp_pfsoc_ctrl_ops
, s
,
224 "mchp.pfsoc.ioscb.ctrl", IOSCB_CTRL_REG_SIZE
);
225 memory_region_add_subregion(&s
->container
, IOSCB_CTRL_BASE
, &s
->ctrl
);
227 memory_region_init_io(&s
->qspixip
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
228 "mchp.pfsoc.ioscb.qspixip", IOSCB_QSPIXIP_REG_SIZE
);
229 memory_region_add_subregion(&s
->container
, IOSCB_QSPIXIP_BASE
, &s
->qspixip
);
231 memory_region_init_io(&s
->mailbox
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
232 "mchp.pfsoc.ioscb.mailbox", IOSCB_SUBMOD_REG_SIZE
);
233 memory_region_add_subregion(&s
->container
, IOSCB_MAILBOX_BASE
, &s
->mailbox
);
235 memory_region_init_io(&s
->cfg
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
236 "mchp.pfsoc.ioscb.cfg", IOSCB_SUBMOD_REG_SIZE
);
237 memory_region_add_subregion(&s
->container
, IOSCB_CFG_BASE
, &s
->cfg
);
239 memory_region_init_io(&s
->ccc
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
240 "mchp.pfsoc.ioscb.ccc", IOSCB_CCC_REG_SIZE
);
241 memory_region_add_subregion(&s
->container
, IOSCB_CCC_BASE
, &s
->ccc
);
243 memory_region_init_io(&s
->pll_mss
, OBJECT(s
), &mchp_pfsoc_pll_ops
, s
,
244 "mchp.pfsoc.ioscb.pll_mss", IOSCB_SUBMOD_REG_SIZE
);
245 memory_region_add_subregion(&s
->container
, IOSCB_PLL_MSS_BASE
, &s
->pll_mss
);
247 memory_region_init_io(&s
->cfm_mss
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
248 "mchp.pfsoc.ioscb.cfm_mss", IOSCB_SUBMOD_REG_SIZE
);
249 memory_region_add_subregion(&s
->container
, IOSCB_CFM_MSS_BASE
, &s
->cfm_mss
);
251 memory_region_init_io(&s
->pll_ddr
, OBJECT(s
), &mchp_pfsoc_pll_ops
, s
,
252 "mchp.pfsoc.ioscb.pll_ddr", IOSCB_SUBMOD_REG_SIZE
);
253 memory_region_add_subregion(&s
->container
, IOSCB_PLL_DDR_BASE
, &s
->pll_ddr
);
255 memory_region_init_io(&s
->bc_ddr
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
256 "mchp.pfsoc.ioscb.bc_ddr", IOSCB_SUBMOD_REG_SIZE
);
257 memory_region_add_subregion(&s
->container
, IOSCB_BC_DDR_BASE
, &s
->bc_ddr
);
259 memory_region_init_io(&s
->io_calib_ddr
, OBJECT(s
),
260 &mchp_pfsoc_io_calib_ddr_ops
, s
,
261 "mchp.pfsoc.ioscb.io_calib_ddr",
262 IOSCB_SUBMOD_REG_SIZE
);
263 memory_region_add_subregion(&s
->container
, IOSCB_IO_CALIB_DDR_BASE
,
266 memory_region_init_io(&s
->pll_sgmii
, OBJECT(s
), &mchp_pfsoc_pll_ops
, s
,
267 "mchp.pfsoc.ioscb.pll_sgmii", IOSCB_SUBMOD_REG_SIZE
);
268 memory_region_add_subregion(&s
->container
, IOSCB_PLL_SGMII_BASE
,
271 memory_region_init_io(&s
->dll_sgmii
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
272 "mchp.pfsoc.ioscb.dll_sgmii", IOSCB_SUBMOD_REG_SIZE
);
273 memory_region_add_subregion(&s
->container
, IOSCB_DLL_SGMII_BASE
,
276 memory_region_init_io(&s
->cfm_sgmii
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
277 "mchp.pfsoc.ioscb.cfm_sgmii", IOSCB_SUBMOD_REG_SIZE
);
278 memory_region_add_subregion(&s
->container
, IOSCB_CFM_SGMII_BASE
,
281 memory_region_init_io(&s
->bc_sgmii
, OBJECT(s
), &mchp_pfsoc_dummy_ops
, s
,
282 "mchp.pfsoc.ioscb.bc_sgmii", IOSCB_SUBMOD_REG_SIZE
);
283 memory_region_add_subregion(&s
->container
, IOSCB_BC_SGMII_BASE
,
286 memory_region_init_io(&s
->io_calib_sgmii
, OBJECT(s
), &mchp_pfsoc_dummy_ops
,
287 s
, "mchp.pfsoc.ioscb.io_calib_sgmii",
288 IOSCB_SUBMOD_REG_SIZE
);
289 memory_region_add_subregion(&s
->container
, IOSCB_IO_CALIB_SGMII_BASE
,
292 sysbus_init_irq(SYS_BUS_DEVICE(dev
), &s
->irq
);
295 static void mchp_pfsoc_ioscb_class_init(ObjectClass
*klass
, void *data
)
297 DeviceClass
*dc
= DEVICE_CLASS(klass
);
299 dc
->desc
= "Microchip PolarFire SoC IOSCB modules";
300 dc
->realize
= mchp_pfsoc_ioscb_realize
;
303 static const TypeInfo mchp_pfsoc_ioscb_info
= {
304 .name
= TYPE_MCHP_PFSOC_IOSCB
,
305 .parent
= TYPE_SYS_BUS_DEVICE
,
306 .instance_size
= sizeof(MchpPfSoCIoscbState
),
307 .class_init
= mchp_pfsoc_ioscb_class_init
,
310 static void mchp_pfsoc_ioscb_register_types(void)
312 type_register_static(&mchp_pfsoc_ioscb_info
);
315 type_init(mchp_pfsoc_ioscb_register_types
)