target/ppc: Filter mtmsr[d] input before setting MSR
[qemu/rayw.git] / hw / misc / mchp_pfsoc_ioscb.c
blobf4fd55a0e5c77ebda0baed62de482843a44fcfa9
1 /*
2 * Microchip PolarFire SoC IOSCB module emulation
4 * Copyright (c) 2020 Wind River Systems, Inc.
6 * Author:
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"
25 #include "qemu/log.h"
26 #include "qapi/error.h"
27 #include "hw/sysbus.h"
28 #include "hw/misc/mchp_pfsoc_ioscb.h"
31 * The whole IOSCB module registers map into the system address at 0x3000_0000,
32 * named as "System Port 0 (AXI-D0)".
34 #define IOSCB_WHOLE_REG_SIZE 0x10000000
35 #define IOSCB_SUBMOD_REG_SIZE 0x1000
38 * There are many sub-modules in the IOSCB module.
39 * See Microchip PolarFire SoC documentation (Register_Map.zip),
40 * Register Map/PF_SoC_RegMap_V1_1/MPFS250T/mpfs250t_ioscb_memmap_dri.htm
42 * The following are sub-modules offsets that are of concern.
44 #define IOSCB_LANE01_BASE 0x06500000
45 #define IOSCB_LANE23_BASE 0x06510000
46 #define IOSCB_CTRL_BASE 0x07020000
47 #define IOSCB_CFG_BASE 0x07080000
48 #define IOSCB_PLL_MSS_BASE 0x0E001000
49 #define IOSCB_CFM_MSS_BASE 0x0E002000
50 #define IOSCB_PLL_DDR_BASE 0x0E010000
51 #define IOSCB_BC_DDR_BASE 0x0E020000
52 #define IOSCB_IO_CALIB_DDR_BASE 0x0E040000
53 #define IOSCB_PLL_SGMII_BASE 0x0E080000
54 #define IOSCB_DLL_SGMII_BASE 0x0E100000
55 #define IOSCB_CFM_SGMII_BASE 0x0E200000
56 #define IOSCB_BC_SGMII_BASE 0x0E400000
57 #define IOSCB_IO_CALIB_SGMII_BASE 0x0E800000
59 static uint64_t mchp_pfsoc_dummy_read(void *opaque, hwaddr offset,
60 unsigned size)
62 qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
63 "(size %d, offset 0x%" HWADDR_PRIx ")\n",
64 __func__, size, offset);
66 return 0;
69 static void mchp_pfsoc_dummy_write(void *opaque, hwaddr offset,
70 uint64_t value, unsigned size)
72 qemu_log_mask(LOG_UNIMP, "%s: unimplemented device write "
73 "(size %d, value 0x%" PRIx64
74 ", offset 0x%" HWADDR_PRIx ")\n",
75 __func__, size, value, offset);
78 static const MemoryRegionOps mchp_pfsoc_dummy_ops = {
79 .read = mchp_pfsoc_dummy_read,
80 .write = mchp_pfsoc_dummy_write,
81 .endianness = DEVICE_LITTLE_ENDIAN,
84 /* All PLL modules in IOSCB have the same register layout */
86 #define PLL_CTRL 0x04
88 static uint64_t mchp_pfsoc_pll_read(void *opaque, hwaddr offset,
89 unsigned size)
91 uint32_t val = 0;
93 switch (offset) {
94 case PLL_CTRL:
95 /* PLL is locked */
96 val = BIT(25);
97 break;
98 default:
99 qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
100 "(size %d, offset 0x%" HWADDR_PRIx ")\n",
101 __func__, size, offset);
102 break;
105 return val;
108 static const MemoryRegionOps mchp_pfsoc_pll_ops = {
109 .read = mchp_pfsoc_pll_read,
110 .write = mchp_pfsoc_dummy_write,
111 .endianness = DEVICE_LITTLE_ENDIAN,
114 /* IO_CALIB_DDR submodule */
116 #define IO_CALIB_DDR_IOC_REG1 0x08
118 static uint64_t mchp_pfsoc_io_calib_ddr_read(void *opaque, hwaddr offset,
119 unsigned size)
121 uint32_t val = 0;
123 switch (offset) {
124 case IO_CALIB_DDR_IOC_REG1:
125 /* calibration completed */
126 val = BIT(2);
127 break;
128 default:
129 qemu_log_mask(LOG_UNIMP, "%s: unimplemented device read "
130 "(size %d, offset 0x%" HWADDR_PRIx ")\n",
131 __func__, size, offset);
132 break;
135 return val;
138 static const MemoryRegionOps mchp_pfsoc_io_calib_ddr_ops = {
139 .read = mchp_pfsoc_io_calib_ddr_read,
140 .write = mchp_pfsoc_dummy_write,
141 .endianness = DEVICE_LITTLE_ENDIAN,
144 static void mchp_pfsoc_ioscb_realize(DeviceState *dev, Error **errp)
146 MchpPfSoCIoscbState *s = MCHP_PFSOC_IOSCB(dev);
147 SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
149 memory_region_init(&s->container, OBJECT(s),
150 "mchp.pfsoc.ioscb", IOSCB_WHOLE_REG_SIZE);
151 sysbus_init_mmio(sbd, &s->container);
153 /* add subregions for all sub-modules in IOSCB */
155 memory_region_init_io(&s->lane01, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
156 "mchp.pfsoc.ioscb.lane01", IOSCB_SUBMOD_REG_SIZE);
157 memory_region_add_subregion(&s->container, IOSCB_LANE01_BASE, &s->lane01);
159 memory_region_init_io(&s->lane23, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
160 "mchp.pfsoc.ioscb.lane23", IOSCB_SUBMOD_REG_SIZE);
161 memory_region_add_subregion(&s->container, IOSCB_LANE23_BASE, &s->lane23);
163 memory_region_init_io(&s->ctrl, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
164 "mchp.pfsoc.ioscb.ctrl", IOSCB_SUBMOD_REG_SIZE);
165 memory_region_add_subregion(&s->container, IOSCB_CTRL_BASE, &s->ctrl);
167 memory_region_init_io(&s->cfg, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
168 "mchp.pfsoc.ioscb.cfg", IOSCB_SUBMOD_REG_SIZE);
169 memory_region_add_subregion(&s->container, IOSCB_CFG_BASE, &s->cfg);
171 memory_region_init_io(&s->pll_mss, OBJECT(s), &mchp_pfsoc_pll_ops, s,
172 "mchp.pfsoc.ioscb.pll_mss", IOSCB_SUBMOD_REG_SIZE);
173 memory_region_add_subregion(&s->container, IOSCB_PLL_MSS_BASE, &s->pll_mss);
175 memory_region_init_io(&s->cfm_mss, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
176 "mchp.pfsoc.ioscb.cfm_mss", IOSCB_SUBMOD_REG_SIZE);
177 memory_region_add_subregion(&s->container, IOSCB_CFM_MSS_BASE, &s->cfm_mss);
179 memory_region_init_io(&s->pll_ddr, OBJECT(s), &mchp_pfsoc_pll_ops, s,
180 "mchp.pfsoc.ioscb.pll_ddr", IOSCB_SUBMOD_REG_SIZE);
181 memory_region_add_subregion(&s->container, IOSCB_PLL_DDR_BASE, &s->pll_ddr);
183 memory_region_init_io(&s->bc_ddr, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
184 "mchp.pfsoc.ioscb.bc_ddr", IOSCB_SUBMOD_REG_SIZE);
185 memory_region_add_subregion(&s->container, IOSCB_BC_DDR_BASE, &s->bc_ddr);
187 memory_region_init_io(&s->io_calib_ddr, OBJECT(s),
188 &mchp_pfsoc_io_calib_ddr_ops, s,
189 "mchp.pfsoc.ioscb.io_calib_ddr",
190 IOSCB_SUBMOD_REG_SIZE);
191 memory_region_add_subregion(&s->container, IOSCB_IO_CALIB_DDR_BASE,
192 &s->io_calib_ddr);
194 memory_region_init_io(&s->pll_sgmii, OBJECT(s), &mchp_pfsoc_pll_ops, s,
195 "mchp.pfsoc.ioscb.pll_sgmii", IOSCB_SUBMOD_REG_SIZE);
196 memory_region_add_subregion(&s->container, IOSCB_PLL_SGMII_BASE,
197 &s->pll_sgmii);
199 memory_region_init_io(&s->dll_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
200 "mchp.pfsoc.ioscb.dll_sgmii", IOSCB_SUBMOD_REG_SIZE);
201 memory_region_add_subregion(&s->container, IOSCB_DLL_SGMII_BASE,
202 &s->dll_sgmii);
204 memory_region_init_io(&s->cfm_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
205 "mchp.pfsoc.ioscb.cfm_sgmii", IOSCB_SUBMOD_REG_SIZE);
206 memory_region_add_subregion(&s->container, IOSCB_CFM_SGMII_BASE,
207 &s->cfm_sgmii);
209 memory_region_init_io(&s->bc_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops, s,
210 "mchp.pfsoc.ioscb.bc_sgmii", IOSCB_SUBMOD_REG_SIZE);
211 memory_region_add_subregion(&s->container, IOSCB_BC_SGMII_BASE,
212 &s->bc_sgmii);
214 memory_region_init_io(&s->io_calib_sgmii, OBJECT(s), &mchp_pfsoc_dummy_ops,
215 s, "mchp.pfsoc.ioscb.io_calib_sgmii",
216 IOSCB_SUBMOD_REG_SIZE);
217 memory_region_add_subregion(&s->container, IOSCB_IO_CALIB_SGMII_BASE,
218 &s->io_calib_sgmii);
221 static void mchp_pfsoc_ioscb_class_init(ObjectClass *klass, void *data)
223 DeviceClass *dc = DEVICE_CLASS(klass);
225 dc->desc = "Microchip PolarFire SoC IOSCB modules";
226 dc->realize = mchp_pfsoc_ioscb_realize;
229 static const TypeInfo mchp_pfsoc_ioscb_info = {
230 .name = TYPE_MCHP_PFSOC_IOSCB,
231 .parent = TYPE_SYS_BUS_DEVICE,
232 .instance_size = sizeof(MchpPfSoCIoscbState),
233 .class_init = mchp_pfsoc_ioscb_class_init,
236 static void mchp_pfsoc_ioscb_register_types(void)
238 type_register_static(&mchp_pfsoc_ioscb_info);
241 type_init(mchp_pfsoc_ioscb_register_types)