xref: /qemu/include/hw/ssi/aspeed_smc.h (revision a489d1951cd9cc91c5954214fcf6ae0f9d2d4292)
17c1c69bcSCédric Le Goater /*
27c1c69bcSCédric Le Goater  * ASPEED AST2400 SMC Controller (SPI Flash Only)
37c1c69bcSCédric Le Goater  *
47c1c69bcSCédric Le Goater  * Copyright (C) 2016 IBM Corp.
57c1c69bcSCédric Le Goater  *
67c1c69bcSCédric Le Goater  * Permission is hereby granted, free of charge, to any person obtaining a copy
77c1c69bcSCédric Le Goater  * of this software and associated documentation files (the "Software"), to deal
87c1c69bcSCédric Le Goater  * in the Software without restriction, including without limitation the rights
97c1c69bcSCédric Le Goater  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
107c1c69bcSCédric Le Goater  * copies of the Software, and to permit persons to whom the Software is
117c1c69bcSCédric Le Goater  * furnished to do so, subject to the following conditions:
127c1c69bcSCédric Le Goater  *
137c1c69bcSCédric Le Goater  * The above copyright notice and this permission notice shall be included in
147c1c69bcSCédric Le Goater  * all copies or substantial portions of the Software.
157c1c69bcSCédric Le Goater  *
167c1c69bcSCédric Le Goater  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
177c1c69bcSCédric Le Goater  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
187c1c69bcSCédric Le Goater  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
197c1c69bcSCédric Le Goater  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
207c1c69bcSCédric Le Goater  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
217c1c69bcSCédric Le Goater  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
227c1c69bcSCédric Le Goater  * THE SOFTWARE.
237c1c69bcSCédric Le Goater  */
247c1c69bcSCédric Le Goater 
257c1c69bcSCédric Le Goater #ifndef ASPEED_SMC_H
267c1c69bcSCédric Le Goater #define ASPEED_SMC_H
277c1c69bcSCédric Le Goater 
287c1c69bcSCédric Le Goater #include "hw/ssi/ssi.h"
29ec150c7eSMarkus Armbruster #include "hw/sysbus.h"
30db1015e9SEduardo Habkost #include "qom/object.h"
317c1c69bcSCédric Le Goater 
32924ed163SCédric Le Goater typedef struct AspeedSegments {
33924ed163SCédric Le Goater     hwaddr addr;
34924ed163SCédric Le Goater     uint32_t size;
35924ed163SCédric Le Goater } AspeedSegments;
36924ed163SCédric Le Goater 
37924ed163SCédric Le Goater struct AspeedSMCState;
387c1c69bcSCédric Le Goater typedef struct AspeedSMCController {
397c1c69bcSCédric Le Goater     const char *name;
407c1c69bcSCédric Le Goater     uint8_t r_conf;
417c1c69bcSCédric Le Goater     uint8_t r_ce_ctrl;
427c1c69bcSCédric Le Goater     uint8_t r_ctrl0;
437c1c69bcSCédric Le Goater     uint8_t r_timings;
44f286f04cSCédric Le Goater     uint8_t nregs_timings;
457c1c69bcSCédric Le Goater     uint8_t conf_enable_w0;
467c1c69bcSCédric Le Goater     uint8_t max_slaves;
47924ed163SCédric Le Goater     const AspeedSegments *segments;
48dcb83444SCédric Le Goater     hwaddr flash_window_base;
49dcb83444SCédric Le Goater     uint32_t flash_window_size;
50d09dc5b7SCédric Le Goater     bool has_dma;
51c4e1f0b4SCédric Le Goater     hwaddr dma_flash_mask;
52c4e1f0b4SCédric Le Goater     hwaddr dma_dram_mask;
53087b57c9SCédric Le Goater     uint32_t nregs;
54d0e25040SCédric Le Goater     uint32_t (*segment_to_reg)(const struct AspeedSMCState *s,
55d0e25040SCédric Le Goater                                const AspeedSegments *seg);
56d0e25040SCédric Le Goater     void (*reg_to_segment)(const struct AspeedSMCState *s, uint32_t reg,
57d0e25040SCédric Le Goater                            AspeedSegments *seg);
587c1c69bcSCédric Le Goater } AspeedSMCController;
597c1c69bcSCédric Le Goater 
60924ed163SCédric Le Goater typedef struct AspeedSMCFlash {
61fcdf2c59SCédric Le Goater     struct AspeedSMCState *controller;
62924ed163SCédric Le Goater 
63924ed163SCédric Le Goater     uint8_t id;
64924ed163SCédric Le Goater     uint32_t size;
65924ed163SCédric Le Goater 
66924ed163SCédric Le Goater     MemoryRegion mmio;
67924ed163SCédric Le Goater     DeviceState *flash;
68924ed163SCédric Le Goater } AspeedSMCFlash;
69924ed163SCédric Le Goater 
707c1c69bcSCédric Le Goater #define TYPE_ASPEED_SMC "aspeed.smc"
71*a489d195SEduardo Habkost OBJECT_DECLARE_TYPE(AspeedSMCState, AspeedSMCClass, ASPEED_SMC)
727c1c69bcSCédric Le Goater 
73db1015e9SEduardo Habkost struct AspeedSMCClass {
747c1c69bcSCédric Le Goater     SysBusDevice parent_obj;
757c1c69bcSCédric Le Goater     const AspeedSMCController *ctrl;
76db1015e9SEduardo Habkost };
777c1c69bcSCédric Le Goater 
787c1c69bcSCédric Le Goater #define ASPEED_SMC_R_MAX        (0x100 / 4)
797c1c69bcSCédric Le Goater 
80db1015e9SEduardo Habkost struct AspeedSMCState {
817c1c69bcSCédric Le Goater     SysBusDevice parent_obj;
827c1c69bcSCédric Le Goater 
837c1c69bcSCédric Le Goater     const AspeedSMCController *ctrl;
847c1c69bcSCédric Le Goater 
857c1c69bcSCédric Le Goater     MemoryRegion mmio;
86924ed163SCédric Le Goater     MemoryRegion mmio_flash;
877c1c69bcSCédric Le Goater 
887c1c69bcSCédric Le Goater     qemu_irq irq;
897c1c69bcSCédric Le Goater     int irqline;
907c1c69bcSCédric Le Goater 
917c1c69bcSCédric Le Goater     uint32_t num_cs;
927c1c69bcSCédric Le Goater     qemu_irq *cs_lines;
935258c2a6SCédric Le Goater     bool inject_failure;
947c1c69bcSCédric Le Goater 
957c1c69bcSCédric Le Goater     SSIBus *spi;
967c1c69bcSCédric Le Goater 
977c1c69bcSCédric Le Goater     uint32_t regs[ASPEED_SMC_R_MAX];
987c1c69bcSCédric Le Goater 
997c1c69bcSCédric Le Goater     /* depends on the controller type */
1007c1c69bcSCédric Le Goater     uint8_t r_conf;
1017c1c69bcSCédric Le Goater     uint8_t r_ce_ctrl;
1027c1c69bcSCédric Le Goater     uint8_t r_ctrl0;
1037c1c69bcSCédric Le Goater     uint8_t r_timings;
1047c1c69bcSCédric Le Goater     uint8_t conf_enable_w0;
105924ed163SCédric Le Goater 
1066da4433fSCédric Le Goater     /* for DMA support */
1076da4433fSCédric Le Goater     uint64_t sdram_base;
1086da4433fSCédric Le Goater 
109c4e1f0b4SCédric Le Goater     AddressSpace flash_as;
110c4e1f0b4SCédric Le Goater     MemoryRegion *dram_mr;
111c4e1f0b4SCédric Le Goater     AddressSpace dram_as;
112c4e1f0b4SCédric Le Goater 
113924ed163SCédric Le Goater     AspeedSMCFlash *flashes;
114f95c4bffSCédric Le Goater 
115f95c4bffSCédric Le Goater     uint8_t snoop_index;
116f95c4bffSCédric Le Goater     uint8_t snoop_dummies;
117db1015e9SEduardo Habkost };
1187c1c69bcSCédric Le Goater 
1197c1c69bcSCédric Le Goater #endif /* ASPEED_SMC_H */
120