提交 d0e25040 编写于 作者: C Cédric Le Goater 提交者: Peter Maydell

aspeed/smc: Introduce segment operations

AST2600 will use a different encoding for the addresses defined in the
Segment Register.
Signed-off-by: NCédric Le Goater <clg@kaod.org>
Acked-by: NJoel Stanley <joel@jms.id.au>
Message-id: 20190925143248.10000-13-clg@kaod.org
Signed-off-by: NPeter Maydell <peter.maydell@linaro.org>
上级 6b2b2a70
...@@ -211,6 +211,10 @@ static const AspeedSegments aspeed_segments_ast2500_spi2[] = { ...@@ -211,6 +211,10 @@ static const AspeedSegments aspeed_segments_ast2500_spi2[] = {
{ 0x38000000, 32 * 1024 * 1024 }, /* start address is readonly */ { 0x38000000, 32 * 1024 * 1024 }, /* start address is readonly */
{ 0x3A000000, 96 * 1024 * 1024 }, /* end address is readonly */ { 0x3A000000, 96 * 1024 * 1024 }, /* end address is readonly */
}; };
static uint32_t aspeed_smc_segment_to_reg(const AspeedSMCState *s,
const AspeedSegments *seg);
static void aspeed_smc_reg_to_segment(const AspeedSMCState *s, uint32_t reg,
AspeedSegments *seg);
static const AspeedSMCController controllers[] = { static const AspeedSMCController controllers[] = {
{ {
...@@ -226,6 +230,8 @@ static const AspeedSMCController controllers[] = { ...@@ -226,6 +230,8 @@ static const AspeedSMCController controllers[] = {
.flash_window_size = 0x6000000, .flash_window_size = 0x6000000,
.has_dma = false, .has_dma = false,
.nregs = ASPEED_SMC_R_SMC_MAX, .nregs = ASPEED_SMC_R_SMC_MAX,
.segment_to_reg = aspeed_smc_segment_to_reg,
.reg_to_segment = aspeed_smc_reg_to_segment,
}, { }, {
.name = "aspeed.fmc-ast2400", .name = "aspeed.fmc-ast2400",
.r_conf = R_CONF, .r_conf = R_CONF,
...@@ -241,6 +247,8 @@ static const AspeedSMCController controllers[] = { ...@@ -241,6 +247,8 @@ static const AspeedSMCController controllers[] = {
.dma_flash_mask = 0x0FFFFFFC, .dma_flash_mask = 0x0FFFFFFC,
.dma_dram_mask = 0x1FFFFFFC, .dma_dram_mask = 0x1FFFFFFC,
.nregs = ASPEED_SMC_R_MAX, .nregs = ASPEED_SMC_R_MAX,
.segment_to_reg = aspeed_smc_segment_to_reg,
.reg_to_segment = aspeed_smc_reg_to_segment,
}, { }, {
.name = "aspeed.spi1-ast2400", .name = "aspeed.spi1-ast2400",
.r_conf = R_SPI_CONF, .r_conf = R_SPI_CONF,
...@@ -254,6 +262,8 @@ static const AspeedSMCController controllers[] = { ...@@ -254,6 +262,8 @@ static const AspeedSMCController controllers[] = {
.flash_window_size = 0x10000000, .flash_window_size = 0x10000000,
.has_dma = false, .has_dma = false,
.nregs = ASPEED_SMC_R_SPI_MAX, .nregs = ASPEED_SMC_R_SPI_MAX,
.segment_to_reg = aspeed_smc_segment_to_reg,
.reg_to_segment = aspeed_smc_reg_to_segment,
}, { }, {
.name = "aspeed.fmc-ast2500", .name = "aspeed.fmc-ast2500",
.r_conf = R_CONF, .r_conf = R_CONF,
...@@ -269,6 +279,8 @@ static const AspeedSMCController controllers[] = { ...@@ -269,6 +279,8 @@ static const AspeedSMCController controllers[] = {
.dma_flash_mask = 0x0FFFFFFC, .dma_flash_mask = 0x0FFFFFFC,
.dma_dram_mask = 0x3FFFFFFC, .dma_dram_mask = 0x3FFFFFFC,
.nregs = ASPEED_SMC_R_MAX, .nregs = ASPEED_SMC_R_MAX,
.segment_to_reg = aspeed_smc_segment_to_reg,
.reg_to_segment = aspeed_smc_reg_to_segment,
}, { }, {
.name = "aspeed.spi1-ast2500", .name = "aspeed.spi1-ast2500",
.r_conf = R_CONF, .r_conf = R_CONF,
...@@ -282,6 +294,8 @@ static const AspeedSMCController controllers[] = { ...@@ -282,6 +294,8 @@ static const AspeedSMCController controllers[] = {
.flash_window_size = 0x8000000, .flash_window_size = 0x8000000,
.has_dma = false, .has_dma = false,
.nregs = ASPEED_SMC_R_MAX, .nregs = ASPEED_SMC_R_MAX,
.segment_to_reg = aspeed_smc_segment_to_reg,
.reg_to_segment = aspeed_smc_reg_to_segment,
}, { }, {
.name = "aspeed.spi2-ast2500", .name = "aspeed.spi2-ast2500",
.r_conf = R_CONF, .r_conf = R_CONF,
...@@ -295,19 +309,19 @@ static const AspeedSMCController controllers[] = { ...@@ -295,19 +309,19 @@ static const AspeedSMCController controllers[] = {
.flash_window_size = 0x8000000, .flash_window_size = 0x8000000,
.has_dma = false, .has_dma = false,
.nregs = ASPEED_SMC_R_MAX, .nregs = ASPEED_SMC_R_MAX,
.segment_to_reg = aspeed_smc_segment_to_reg,
.reg_to_segment = aspeed_smc_reg_to_segment,
}, },
}; };
/* /*
* The Segment Register uses a 8MB unit to encode the start address * The Segment Registers of the AST2400 and AST2500 have a 8MB
* and the end address of the mapping window of a flash SPI slave : * unit. The address range of a flash SPI slave is encoded with
* * absolute addresses which should be part of the overall controller
* | byte 1 | byte 2 | byte 3 | byte 4 | * window.
* +--------+--------+--------+--------+
* | end | start | 0 | 0 |
*
*/ */
static inline uint32_t aspeed_smc_segment_to_reg(const AspeedSegments *seg) static uint32_t aspeed_smc_segment_to_reg(const AspeedSMCState *s,
const AspeedSegments *seg)
{ {
uint32_t reg = 0; uint32_t reg = 0;
reg |= ((seg->addr >> 23) & SEG_START_MASK) << SEG_START_SHIFT; reg |= ((seg->addr >> 23) & SEG_START_MASK) << SEG_START_SHIFT;
...@@ -315,7 +329,8 @@ static inline uint32_t aspeed_smc_segment_to_reg(const AspeedSegments *seg) ...@@ -315,7 +329,8 @@ static inline uint32_t aspeed_smc_segment_to_reg(const AspeedSegments *seg)
return reg; return reg;
} }
static inline void aspeed_smc_reg_to_segment(uint32_t reg, AspeedSegments *seg) static void aspeed_smc_reg_to_segment(const AspeedSMCState *s,
uint32_t reg, AspeedSegments *seg)
{ {
seg->addr = ((reg >> SEG_START_SHIFT) & SEG_START_MASK) << 23; seg->addr = ((reg >> SEG_START_SHIFT) & SEG_START_MASK) << 23;
seg->size = (((reg >> SEG_END_SHIFT) & SEG_END_MASK) << 23) - seg->addr; seg->size = (((reg >> SEG_END_SHIFT) & SEG_END_MASK) << 23) - seg->addr;
...@@ -333,7 +348,7 @@ static bool aspeed_smc_flash_overlap(const AspeedSMCState *s, ...@@ -333,7 +348,7 @@ static bool aspeed_smc_flash_overlap(const AspeedSMCState *s,
continue; continue;
} }
aspeed_smc_reg_to_segment(s->regs[R_SEG_ADDR0 + i], &seg); s->ctrl->reg_to_segment(s, s->regs[R_SEG_ADDR0 + i], &seg);
if (new->addr + new->size > seg.addr && if (new->addr + new->size > seg.addr &&
new->addr < seg.addr + seg.size) { new->addr < seg.addr + seg.size) {
...@@ -354,7 +369,7 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs, ...@@ -354,7 +369,7 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,
AspeedSMCFlash *fl = &s->flashes[cs]; AspeedSMCFlash *fl = &s->flashes[cs];
AspeedSegments seg; AspeedSegments seg;
aspeed_smc_reg_to_segment(new, &seg); s->ctrl->reg_to_segment(s, new, &seg);
/* The start address of CS0 is read-only */ /* The start address of CS0 is read-only */
if (cs == 0 && seg.addr != s->ctrl->flash_window_base) { if (cs == 0 && seg.addr != s->ctrl->flash_window_base) {
...@@ -362,7 +377,7 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs, ...@@ -362,7 +377,7 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,
"%s: Tried to change CS0 start address to 0x%" "%s: Tried to change CS0 start address to 0x%"
HWADDR_PRIx "\n", s->ctrl->name, seg.addr); HWADDR_PRIx "\n", s->ctrl->name, seg.addr);
seg.addr = s->ctrl->flash_window_base; seg.addr = s->ctrl->flash_window_base;
new = aspeed_smc_segment_to_reg(&seg); new = s->ctrl->segment_to_reg(s, &seg);
} }
/* /*
...@@ -379,7 +394,7 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs, ...@@ -379,7 +394,7 @@ static void aspeed_smc_flash_set_segment(AspeedSMCState *s, int cs,
HWADDR_PRIx "\n", s->ctrl->name, cs, seg.addr + seg.size); HWADDR_PRIx "\n", s->ctrl->name, cs, seg.addr + seg.size);
seg.size = s->ctrl->segments[cs].addr + s->ctrl->segments[cs].size - seg.size = s->ctrl->segments[cs].addr + s->ctrl->segments[cs].size -
seg.addr; seg.addr;
new = aspeed_smc_segment_to_reg(&seg); new = s->ctrl->segment_to_reg(s, &seg);
} }
/* Keep the segment in the overall flash window */ /* Keep the segment in the overall flash window */
...@@ -509,7 +524,7 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl, ...@@ -509,7 +524,7 @@ static uint32_t aspeed_smc_check_segment_addr(const AspeedSMCFlash *fl,
const AspeedSMCState *s = fl->controller; const AspeedSMCState *s = fl->controller;
AspeedSegments seg; AspeedSegments seg;
aspeed_smc_reg_to_segment(s->regs[R_SEG_ADDR0 + fl->id], &seg); s->ctrl->reg_to_segment(s, s->regs[R_SEG_ADDR0 + fl->id], &seg);
if ((addr % seg.size) != addr) { if ((addr % seg.size) != addr) {
qemu_log_mask(LOG_GUEST_ERROR, qemu_log_mask(LOG_GUEST_ERROR,
"%s: invalid address 0x%08x for CS%d segment : " "%s: invalid address 0x%08x for CS%d segment : "
...@@ -769,7 +784,7 @@ static void aspeed_smc_reset(DeviceState *d) ...@@ -769,7 +784,7 @@ static void aspeed_smc_reset(DeviceState *d)
/* setup default segment register values for all */ /* setup default segment register values for all */
for (i = 0; i < s->ctrl->max_slaves; ++i) { for (i = 0; i < s->ctrl->max_slaves; ++i) {
s->regs[R_SEG_ADDR0 + i] = s->regs[R_SEG_ADDR0 + i] =
aspeed_smc_segment_to_reg(&s->ctrl->segments[i]); s->ctrl->segment_to_reg(s, &s->ctrl->segments[i]);
} }
/* HW strapping flash type for FMC controllers */ /* HW strapping flash type for FMC controllers */
......
...@@ -49,6 +49,10 @@ typedef struct AspeedSMCController { ...@@ -49,6 +49,10 @@ typedef struct AspeedSMCController {
hwaddr dma_flash_mask; hwaddr dma_flash_mask;
hwaddr dma_dram_mask; hwaddr dma_dram_mask;
uint32_t nregs; uint32_t nregs;
uint32_t (*segment_to_reg)(const struct AspeedSMCState *s,
const AspeedSegments *seg);
void (*reg_to_segment)(const struct AspeedSMCState *s, uint32_t reg,
AspeedSegments *seg);
} AspeedSMCController; } AspeedSMCController;
typedef struct AspeedSMCFlash { typedef struct AspeedSMCFlash {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册