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 34f75b5331SCédric Le Goater #define TYPE_ASPEED_SMC_FLASH "aspeed.smc.flash" 35f75b5331SCédric Le Goater OBJECT_DECLARE_SIMPLE_TYPE(AspeedSMCFlash, ASPEED_SMC_FLASH) 36f75b5331SCédric Le Goater struct AspeedSMCFlash { 37f75b5331SCédric Le Goater SysBusDevice parent_obj; 38f75b5331SCédric Le Goater 39f75b5331SCédric Le Goater struct AspeedSMCState *controller; 4010f915e4SCédric Le Goater uint8_t cs; 41924ed163SCédric Le Goater 42924ed163SCédric Le Goater MemoryRegion mmio; 43f75b5331SCé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) 49f75b5331SCé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; 55fc664254SCédric Le Goater MemoryRegion mmio_flash_container; 56924ed163SCédric Le Goater MemoryRegion mmio_flash; 577c1c69bcSCédric Le Goater 587c1c69bcSCédric Le Goater qemu_irq irq; 597c1c69bcSCédric Le Goater 607c1c69bcSCédric Le Goater uint32_t num_cs; 617c1c69bcSCédric Le Goater qemu_irq *cs_lines; 625258c2a6SCédric Le Goater bool inject_failure; 637c1c69bcSCédric Le Goater 647c1c69bcSCédric Le Goater SSIBus *spi; 657c1c69bcSCédric Le Goater 667c1c69bcSCédric Le Goater uint32_t regs[ASPEED_SMC_R_MAX]; 677c1c69bcSCédric Le Goater 687c1c69bcSCédric Le Goater /* depends on the controller type */ 697c1c69bcSCédric Le Goater uint8_t r_conf; 707c1c69bcSCédric Le Goater uint8_t r_ce_ctrl; 717c1c69bcSCédric Le Goater uint8_t r_ctrl0; 727c1c69bcSCédric Le Goater uint8_t r_timings; 737c1c69bcSCédric Le Goater uint8_t conf_enable_w0; 74924ed163SCédric Le Goater 75c4e1f0b4SCédric Le Goater AddressSpace flash_as; 76c4e1f0b4SCédric Le Goater MemoryRegion *dram_mr; 77c4e1f0b4SCédric Le Goater AddressSpace dram_as; 78c4e1f0b4SCédric Le Goater 79f75b5331SCédric Le Goater AspeedSMCFlash flashes[ASPEED_SMC_CS_MAX]; 80f95c4bffSCédric Le Goater 81f95c4bffSCédric Le Goater uint8_t snoop_index; 82f95c4bffSCédric Le Goater uint8_t snoop_dummies; 83db1015e9SEduardo Habkost }; 847c1c69bcSCédric Le Goater 8530b6852cSCédric Le Goater typedef struct AspeedSegments { 8630b6852cSCédric Le Goater hwaddr addr; 8730b6852cSCédric Le Goater uint32_t size; 8830b6852cSCédric Le Goater } AspeedSegments; 8930b6852cSCédric Le Goater 9030b6852cSCédric Le Goater struct AspeedSMCClass { 9130b6852cSCédric Le Goater SysBusDeviceClass parent_obj; 9230b6852cSCédric Le Goater 9330b6852cSCédric Le Goater uint8_t r_conf; 9430b6852cSCédric Le Goater uint8_t r_ce_ctrl; 9530b6852cSCédric Le Goater uint8_t r_ctrl0; 9630b6852cSCédric Le Goater uint8_t r_timings; 9730b6852cSCédric Le Goater uint8_t nregs_timings; 9830b6852cSCédric Le Goater uint8_t conf_enable_w0; 9930b6852cSCédric Le Goater uint8_t max_peripherals; 10071255c48SCédric Le Goater const uint32_t *resets; 10130b6852cSCédric Le Goater const AspeedSegments *segments; 102*7c8d2fc4SCédric Le Goater uint32_t segment_addr_mask; 10330b6852cSCédric Le Goater hwaddr flash_window_base; 10430b6852cSCédric Le Goater uint32_t flash_window_size; 10530b6852cSCédric Le Goater uint32_t features; 10630b6852cSCédric Le Goater hwaddr dma_flash_mask; 10730b6852cSCédric Le Goater hwaddr dma_dram_mask; 10830b6852cSCédric Le Goater uint32_t nregs; 10930b6852cSCédric Le Goater uint32_t (*segment_to_reg)(const AspeedSMCState *s, 11030b6852cSCédric Le Goater const AspeedSegments *seg); 11130b6852cSCédric Le Goater void (*reg_to_segment)(const AspeedSMCState *s, uint32_t reg, 11230b6852cSCédric Le Goater AspeedSegments *seg); 11330b6852cSCédric Le Goater void (*dma_ctrl)(AspeedSMCState *s, uint32_t value); 114a779e37cSCédric Le Goater int (*addr_width)(const AspeedSMCState *s); 11530b6852cSCédric Le Goater }; 11630b6852cSCédric Le Goater 1177c1c69bcSCédric Le Goater #endif /* ASPEED_SMC_H */ 118