2 * OpenPOWER Palmetto BMC
4 * Andrew Jeffery <andrew@aj.id.au>
6 * Copyright 2016 IBM Corp.
8 * This code is licensed under the GPL version 2 or later. See
9 * the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "qemu-common.h"
16 #include "exec/address-spaces.h"
17 #include "hw/arm/arm.h"
18 #include "hw/arm/aspeed_soc.h"
19 #include "hw/boards.h"
21 #include "sysemu/block-backend.h"
22 #include "sysemu/blockdev.h"
24 static struct arm_boot_info aspeed_board_binfo
= {
25 .board_id
= -1, /* device-tree-only board */
29 typedef struct AspeedBoardState
{
34 typedef struct AspeedBoardConfig
{
37 const char *fmc_model
;
38 const char *spi_model
;
47 /* Palmetto hardware value: 0x120CE416 */
48 #define PALMETTO_BMC_HW_STRAP1 ( \
49 SCU_AST2400_HW_STRAP_DRAM_SIZE(DRAM_SIZE_256MB) | \
50 SCU_AST2400_HW_STRAP_DRAM_CONFIG(2 /* DDR3 with CL=6, CWL=5 */) | \
51 SCU_AST2400_HW_STRAP_ACPI_DIS | \
52 SCU_AST2400_HW_STRAP_SET_CLK_SOURCE(AST2400_CLK_48M_IN) | \
53 SCU_HW_STRAP_VGA_CLASS_CODE | \
54 SCU_HW_STRAP_LPC_RESET_PIN | \
55 SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_M_S_EN) | \
56 SCU_AST2400_HW_STRAP_SET_CPU_AHB_RATIO(AST2400_CPU_AHB_RATIO_2_1) | \
57 SCU_HW_STRAP_SPI_WIDTH | \
58 SCU_HW_STRAP_VGA_SIZE_SET(VGA_16M_DRAM) | \
59 SCU_AST2400_HW_STRAP_BOOT_MODE(AST2400_SPI_BOOT))
61 /* AST2500 evb hardware value: 0xF100C2E6 */
62 #define AST2500_EVB_HW_STRAP1 (( \
63 AST2500_HW_STRAP1_DEFAULTS | \
64 SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE | \
65 SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE | \
66 SCU_AST2500_HW_STRAP_UART_DEBUG | \
67 SCU_AST2500_HW_STRAP_DDR4_ENABLE | \
68 SCU_HW_STRAP_MAC1_RGMII | \
69 SCU_HW_STRAP_MAC0_RGMII) & \
70 ~SCU_HW_STRAP_2ND_BOOT_WDT)
72 /* Romulus hardware value: 0xF10AD206 */
73 #define ROMULUS_BMC_HW_STRAP1 ( \
74 AST2500_HW_STRAP1_DEFAULTS | \
75 SCU_AST2500_HW_STRAP_SPI_AUTOFETCH_ENABLE | \
76 SCU_AST2500_HW_STRAP_GPIO_STRAP_ENABLE | \
77 SCU_AST2500_HW_STRAP_UART_DEBUG | \
78 SCU_AST2500_HW_STRAP_DDR4_ENABLE | \
79 SCU_AST2500_HW_STRAP_ACPI_ENABLE | \
80 SCU_HW_STRAP_SPI_MODE(SCU_HW_STRAP_SPI_MASTER))
82 static const AspeedBoardConfig aspeed_boards
[] = {
84 .soc_name
= "ast2400-a1",
85 .hw_strap1
= PALMETTO_BMC_HW_STRAP1
,
86 .fmc_model
= "n25q256a",
87 .spi_model
= "mx25l25635e",
90 .soc_name
= "ast2500-a1",
91 .hw_strap1
= AST2500_EVB_HW_STRAP1
,
92 .fmc_model
= "n25q256a",
93 .spi_model
= "mx25l25635e",
96 .soc_name
= "ast2500-a1",
97 .hw_strap1
= ROMULUS_BMC_HW_STRAP1
,
98 .fmc_model
= "n25q256a",
99 .spi_model
= "mx66l1g45g",
103 static void aspeed_board_init_flashes(AspeedSMCState
*s
, const char *flashtype
,
108 for (i
= 0; i
< s
->num_cs
; ++i
) {
109 AspeedSMCFlash
*fl
= &s
->flashes
[i
];
110 DriveInfo
*dinfo
= drive_get_next(IF_MTD
);
114 * FIXME: check that we are not using a flash module exceeding
115 * the controller segment size
117 fl
->flash
= ssi_create_slave_no_init(s
->spi
, flashtype
);
119 qdev_prop_set_drive(fl
->flash
, "drive", blk_by_legacy_dinfo(dinfo
),
122 qdev_init_nofail(fl
->flash
);
124 cs_line
= qdev_get_gpio_in_named(fl
->flash
, SSI_GPIO_CS
, 0);
125 sysbus_connect_irq(SYS_BUS_DEVICE(s
), i
+ 1, cs_line
);
129 static void aspeed_board_init(MachineState
*machine
,
130 const AspeedBoardConfig
*cfg
)
132 AspeedBoardState
*bmc
;
135 bmc
= g_new0(AspeedBoardState
, 1);
136 object_initialize(&bmc
->soc
, (sizeof(bmc
->soc
)), cfg
->soc_name
);
137 object_property_add_child(OBJECT(machine
), "soc", OBJECT(&bmc
->soc
),
140 sc
= ASPEED_SOC_GET_CLASS(&bmc
->soc
);
142 object_property_set_int(OBJECT(&bmc
->soc
), ram_size
, "ram-size",
144 object_property_set_int(OBJECT(&bmc
->soc
), cfg
->hw_strap1
, "hw-strap1",
146 object_property_set_bool(OBJECT(&bmc
->soc
), true, "realized",
150 * Allocate RAM after the memory controller has checked the size
151 * was valid. If not, a default value is used.
153 ram_size
= object_property_get_int(OBJECT(&bmc
->soc
), "ram-size",
156 memory_region_allocate_system_memory(&bmc
->ram
, NULL
, "ram", ram_size
);
157 memory_region_add_subregion(get_system_memory(), sc
->info
->sdram_base
,
159 object_property_add_const_link(OBJECT(&bmc
->soc
), "ram", OBJECT(&bmc
->ram
),
162 aspeed_board_init_flashes(&bmc
->soc
.fmc
, cfg
->fmc_model
, &error_abort
);
163 aspeed_board_init_flashes(&bmc
->soc
.spi
[0], cfg
->spi_model
, &error_abort
);
165 aspeed_board_binfo
.kernel_filename
= machine
->kernel_filename
;
166 aspeed_board_binfo
.initrd_filename
= machine
->initrd_filename
;
167 aspeed_board_binfo
.kernel_cmdline
= machine
->kernel_cmdline
;
168 aspeed_board_binfo
.ram_size
= ram_size
;
169 aspeed_board_binfo
.loader_start
= sc
->info
->sdram_base
;
171 arm_load_kernel(ARM_CPU(first_cpu
), &aspeed_board_binfo
);
174 static void palmetto_bmc_init(MachineState
*machine
)
176 aspeed_board_init(machine
, &aspeed_boards
[PALMETTO_BMC
]);
179 static void palmetto_bmc_class_init(ObjectClass
*oc
, void *data
)
181 MachineClass
*mc
= MACHINE_CLASS(oc
);
183 mc
->desc
= "OpenPOWER Palmetto BMC (ARM926EJ-S)";
184 mc
->init
= palmetto_bmc_init
;
192 static const TypeInfo palmetto_bmc_type
= {
193 .name
= MACHINE_TYPE_NAME("palmetto-bmc"),
194 .parent
= TYPE_MACHINE
,
195 .class_init
= palmetto_bmc_class_init
,
198 static void ast2500_evb_init(MachineState
*machine
)
200 aspeed_board_init(machine
, &aspeed_boards
[AST2500_EVB
]);
203 static void ast2500_evb_class_init(ObjectClass
*oc
, void *data
)
205 MachineClass
*mc
= MACHINE_CLASS(oc
);
207 mc
->desc
= "Aspeed AST2500 EVB (ARM1176)";
208 mc
->init
= ast2500_evb_init
;
216 static const TypeInfo ast2500_evb_type
= {
217 .name
= MACHINE_TYPE_NAME("ast2500-evb"),
218 .parent
= TYPE_MACHINE
,
219 .class_init
= ast2500_evb_class_init
,
222 static void romulus_bmc_init(MachineState
*machine
)
224 aspeed_board_init(machine
, &aspeed_boards
[ROMULUS_BMC
]);
227 static void romulus_bmc_class_init(ObjectClass
*oc
, void *data
)
229 MachineClass
*mc
= MACHINE_CLASS(oc
);
231 mc
->desc
= "OpenPOWER Romulus BMC (ARM1176)";
232 mc
->init
= romulus_bmc_init
;
240 static const TypeInfo romulus_bmc_type
= {
241 .name
= MACHINE_TYPE_NAME("romulus-bmc"),
242 .parent
= TYPE_MACHINE
,
243 .class_init
= romulus_bmc_class_init
,
246 static void aspeed_machine_init(void)
248 type_register_static(&palmetto_bmc_type
);
249 type_register_static(&ast2500_evb_type
);
250 type_register_static(&romulus_bmc_type
);
253 type_init(aspeed_machine_init
)