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; 33b84a9482SCédric Le Goater struct AspeedSMCClass; 34924ed163SCédric Le Goater 35f75b5331SCédric Le Goater #define TYPE_ASPEED_SMC_FLASH "aspeed.smc.flash" 36f75b5331SCédric Le Goater OBJECT_DECLARE_SIMPLE_TYPE(AspeedSMCFlash, ASPEED_SMC_FLASH) 37f75b5331SCédric Le Goater struct AspeedSMCFlash { 38f75b5331SCédric Le Goater SysBusDevice parent_obj; 39f75b5331SCédric Le Goater 40f75b5331SCédric Le Goater struct AspeedSMCState *controller; 41b84a9482SCédric Le Goater struct AspeedSMCClass *asc; 4210f915e4SCédric Le Goater uint8_t cs; 43924ed163SCédric Le Goater 44924ed163SCédric Le Goater MemoryRegion mmio; 45f75b5331SCédric Le Goater }; 46924ed163SCédric Le Goater 477c1c69bcSCédric Le Goater #define TYPE_ASPEED_SMC "aspeed.smc" 48a489d195SEduardo Habkost OBJECT_DECLARE_TYPE(AspeedSMCState, AspeedSMCClass, ASPEED_SMC) 497c1c69bcSCédric Le Goater 507c1c69bcSCédric Le Goater #define ASPEED_SMC_R_MAX (0x100 / 4) 51f75b5331SCédric Le Goater #define ASPEED_SMC_CS_MAX 5 527c1c69bcSCédric Le Goater 53db1015e9SEduardo Habkost struct AspeedSMCState { 547c1c69bcSCédric Le Goater SysBusDevice parent_obj; 557c1c69bcSCédric Le Goater 567c1c69bcSCédric Le Goater MemoryRegion mmio; 57fc664254SCédric Le Goater MemoryRegion mmio_flash_container; 58924ed163SCédric Le Goater MemoryRegion mmio_flash; 597c1c69bcSCédric Le Goater 607c1c69bcSCédric Le Goater qemu_irq irq; 617c1c69bcSCédric Le Goater 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; 79ee48fef0SCédric Le Goater uint64_t dram_base; 80c4e1f0b4SCédric Le Goater 81*f1d73a0eSCédric Le Goater AddressSpace wdt2_as; 82*f1d73a0eSCédric Le Goater MemoryRegion *wdt2_mr; 83*f1d73a0eSCédric Le Goater 84f75b5331SCédric Le Goater AspeedSMCFlash flashes[ASPEED_SMC_CS_MAX]; 85f95c4bffSCédric Le Goater 86f95c4bffSCédric Le Goater uint8_t snoop_index; 87f95c4bffSCédric Le Goater uint8_t snoop_dummies; 8805d501a1SJamin Lin bool unselect; 89db1015e9SEduardo Habkost }; 907c1c69bcSCédric Le Goater 9130b6852cSCédric Le Goater typedef struct AspeedSegments { 9230b6852cSCédric Le Goater hwaddr addr; 9330b6852cSCédric Le Goater uint32_t size; 9430b6852cSCédric Le Goater } AspeedSegments; 9530b6852cSCédric Le Goater 9630b6852cSCédric Le Goater struct AspeedSMCClass { 9730b6852cSCédric Le Goater SysBusDeviceClass parent_obj; 9830b6852cSCédric Le Goater 9930b6852cSCédric Le Goater uint8_t r_conf; 10030b6852cSCédric Le Goater uint8_t r_ce_ctrl; 10130b6852cSCédric Le Goater uint8_t r_ctrl0; 10230b6852cSCédric Le Goater uint8_t r_timings; 10330b6852cSCédric Le Goater uint8_t nregs_timings; 10430b6852cSCédric Le Goater uint8_t conf_enable_w0; 105ae945a00SCédric Le Goater uint8_t cs_num_max; 10671255c48SCédric Le Goater const uint32_t *resets; 10730b6852cSCédric Le Goater const AspeedSegments *segments; 1087c8d2fc4SCédric Le Goater uint32_t segment_addr_mask; 10930b6852cSCédric Le Goater hwaddr flash_window_base; 11030b6852cSCédric Le Goater uint32_t flash_window_size; 11130b6852cSCédric Le Goater uint32_t features; 11230b6852cSCédric Le Goater hwaddr dma_flash_mask; 11330b6852cSCédric Le Goater hwaddr dma_dram_mask; 1143a6c0f0eSJamin Lin uint32_t dma_start_length; 11530b6852cSCédric Le Goater uint32_t nregs; 11630b6852cSCédric Le Goater uint32_t (*segment_to_reg)(const AspeedSMCState *s, 11730b6852cSCédric Le Goater const AspeedSegments *seg); 11830b6852cSCédric Le Goater void (*reg_to_segment)(const AspeedSMCState *s, uint32_t reg, 11930b6852cSCédric Le Goater AspeedSegments *seg); 12030b6852cSCédric Le Goater void (*dma_ctrl)(AspeedSMCState *s, uint32_t value); 121a779e37cSCédric Le Goater int (*addr_width)(const AspeedSMCState *s); 1220559e606SJamin Lin const MemoryRegionOps *reg_ops; 12330b6852cSCédric Le Goater }; 12430b6852cSCédric Le Goater 1257c1c69bcSCédric Le Goater #endif /* ASPEED_SMC_H */ 126