xref: /qemu/include/hw/ssi/aspeed_smc.h (revision f75b5331178b6771f2a96e92ce140dd2786c8282)
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 struct AspeedSMCState;
33924ed163SCédric Le Goater 
34*f75b5331SCédric Le Goater #define TYPE_ASPEED_SMC_FLASH "aspeed.smc.flash"
35*f75b5331SCédric Le Goater OBJECT_DECLARE_SIMPLE_TYPE(AspeedSMCFlash, ASPEED_SMC_FLASH)
36*f75b5331SCédric Le Goater struct AspeedSMCFlash {
37*f75b5331SCédric Le Goater     SysBusDevice parent_obj;
38*f75b5331SCédric Le Goater 
39*f75b5331SCédric Le Goater     struct AspeedSMCState *controller;
4010f915e4SCédric Le Goater     uint8_t cs;
41924ed163SCédric Le Goater 
42924ed163SCédric Le Goater     MemoryRegion mmio;
43*f75b5331SCédric Le Goater };
44924ed163SCédric Le Goater 
457c1c69bcSCédric Le Goater #define TYPE_ASPEED_SMC "aspeed.smc"
46a489d195SEduardo Habkost OBJECT_DECLARE_TYPE(AspeedSMCState, AspeedSMCClass, ASPEED_SMC)
477c1c69bcSCédric Le Goater 
487c1c69bcSCédric Le Goater #define ASPEED_SMC_R_MAX        (0x100 / 4)
49*f75b5331SCédric Le Goater #define ASPEED_SMC_CS_MAX       5
507c1c69bcSCédric Le Goater 
51db1015e9SEduardo Habkost struct AspeedSMCState {
527c1c69bcSCédric Le Goater     SysBusDevice parent_obj;
537c1c69bcSCédric Le Goater 
547c1c69bcSCédric Le Goater     MemoryRegion mmio;
55924ed163SCédric Le Goater     MemoryRegion mmio_flash;
56e9c568dbSPhilippe Mathieu-Daudé     MemoryRegion mmio_flash_alias;
577c1c69bcSCédric Le Goater 
587c1c69bcSCédric Le Goater     qemu_irq irq;
597c1c69bcSCédric Le Goater     int irqline;
607c1c69bcSCédric Le Goater 
617c1c69bcSCédric Le Goater     uint32_t num_cs;
627c1c69bcSCédric Le Goater     qemu_irq *cs_lines;
635258c2a6SCédric Le Goater     bool inject_failure;
647c1c69bcSCédric Le Goater 
657c1c69bcSCédric Le Goater     SSIBus *spi;
667c1c69bcSCédric Le Goater 
677c1c69bcSCédric Le Goater     uint32_t regs[ASPEED_SMC_R_MAX];
687c1c69bcSCédric Le Goater 
697c1c69bcSCédric Le Goater     /* depends on the controller type */
707c1c69bcSCédric Le Goater     uint8_t r_conf;
717c1c69bcSCédric Le Goater     uint8_t r_ce_ctrl;
727c1c69bcSCédric Le Goater     uint8_t r_ctrl0;
737c1c69bcSCédric Le Goater     uint8_t r_timings;
747c1c69bcSCédric Le Goater     uint8_t conf_enable_w0;
75924ed163SCédric Le Goater 
76c4e1f0b4SCédric Le Goater     AddressSpace flash_as;
77c4e1f0b4SCédric Le Goater     MemoryRegion *dram_mr;
78c4e1f0b4SCédric Le Goater     AddressSpace dram_as;
79c4e1f0b4SCédric Le Goater 
80*f75b5331SCédric Le Goater     AspeedSMCFlash flashes[ASPEED_SMC_CS_MAX];
81f95c4bffSCédric Le Goater 
82f95c4bffSCédric Le Goater     uint8_t snoop_index;
83f95c4bffSCédric Le Goater     uint8_t snoop_dummies;
84db1015e9SEduardo Habkost };
857c1c69bcSCédric Le Goater 
8630b6852cSCédric Le Goater typedef struct AspeedSegments {
8730b6852cSCédric Le Goater     hwaddr addr;
8830b6852cSCédric Le Goater     uint32_t size;
8930b6852cSCédric Le Goater } AspeedSegments;
9030b6852cSCédric Le Goater 
9130b6852cSCédric Le Goater struct AspeedSMCClass {
9230b6852cSCédric Le Goater     SysBusDeviceClass parent_obj;
9330b6852cSCédric Le Goater 
9430b6852cSCédric Le Goater     uint8_t r_conf;
9530b6852cSCédric Le Goater     uint8_t r_ce_ctrl;
9630b6852cSCédric Le Goater     uint8_t r_ctrl0;
9730b6852cSCédric Le Goater     uint8_t r_timings;
9830b6852cSCédric Le Goater     uint8_t nregs_timings;
9930b6852cSCédric Le Goater     uint8_t conf_enable_w0;
10030b6852cSCédric Le Goater     uint8_t max_peripherals;
10130b6852cSCédric Le Goater     const AspeedSegments *segments;
10230b6852cSCédric Le Goater     hwaddr flash_window_base;
10330b6852cSCédric Le Goater     uint32_t flash_window_size;
10430b6852cSCédric Le Goater     uint32_t features;
10530b6852cSCédric Le Goater     hwaddr dma_flash_mask;
10630b6852cSCédric Le Goater     hwaddr dma_dram_mask;
10730b6852cSCédric Le Goater     uint32_t nregs;
10830b6852cSCédric Le Goater     uint32_t (*segment_to_reg)(const AspeedSMCState *s,
10930b6852cSCédric Le Goater                                const AspeedSegments *seg);
11030b6852cSCédric Le Goater     void (*reg_to_segment)(const AspeedSMCState *s, uint32_t reg,
11130b6852cSCédric Le Goater                            AspeedSegments *seg);
11230b6852cSCédric Le Goater     void (*dma_ctrl)(AspeedSMCState *s, uint32_t value);
11330b6852cSCédric Le Goater };
11430b6852cSCédric Le Goater 
1157c1c69bcSCédric Le Goater #endif /* ASPEED_SMC_H */
116