Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2010,2011 Carl-Daniel Hailfinger |
| 5 | * Written by Carl-Daniel Hailfinger for Angelbird Ltd. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /* Datasheets are not public (yet?) */ |
Andrew Morgan | a074383 | 2011-07-25 22:07:05 +0000 | [diff] [blame] | 18 | #if defined(__i386__) || defined(__x86_64__) |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 19 | |
| 20 | #include <stdlib.h> |
| 21 | #include "flash.h" |
| 22 | #include "programmer.h" |
Patrick Georgi | 32508eb | 2012-07-20 20:35:14 +0000 | [diff] [blame] | 23 | #include "hwaccess.h" |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 24 | |
| 25 | uint8_t *mv_bar; |
| 26 | uint16_t mv_iobar; |
| 27 | |
Stefan Tauner | 4b24a2d | 2012-12-27 18:40:36 +0000 | [diff] [blame] | 28 | const struct dev_entry satas_mv[] = { |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 29 | /* 88SX6041 and 88SX6042 are the same according to the datasheet. */ |
| 30 | {0x11ab, 0x7042, OK, "Marvell", "88SX7042 PCI-e 4-port SATA-II"}, |
| 31 | |
Carl-Daniel Hailfinger | 1c6d2ff | 2012-08-27 00:44:42 +0000 | [diff] [blame] | 32 | {0}, |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | #define NVRAM_PARAM 0x1045c |
| 36 | #define FLASH_PARAM 0x1046c |
| 37 | #define EXPANSION_ROM_BAR_CONTROL 0x00d2c |
| 38 | #define PCI_BAR2_CONTROL 0x00c08 |
| 39 | #define GPIO_PORT_CONTROL 0x104f0 |
| 40 | |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 41 | static void satamv_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 42 | chipaddr addr); |
| 43 | static uint8_t satamv_chip_readb(const struct flashctx *flash, |
| 44 | const chipaddr addr); |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 45 | static const struct par_master par_master_satamv = { |
Carl-Daniel Hailfinger | eaacd2d | 2011-11-09 23:40:00 +0000 | [diff] [blame] | 46 | .chip_readb = satamv_chip_readb, |
| 47 | .chip_readw = fallback_chip_readw, |
| 48 | .chip_readl = fallback_chip_readl, |
| 49 | .chip_readn = fallback_chip_readn, |
| 50 | .chip_writeb = satamv_chip_writeb, |
| 51 | .chip_writew = fallback_chip_writew, |
| 52 | .chip_writel = fallback_chip_writel, |
| 53 | .chip_writen = fallback_chip_writen, |
| 54 | }; |
| 55 | |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 56 | /* |
| 57 | * Random notes: |
| 58 | * FCE# Flash Chip Enable |
| 59 | * FWE# Flash Write Enable |
| 60 | * FOE# Flash Output Enable |
| 61 | * FALE[1:0] Flash Address Latch Enable |
| 62 | * FAD[7:0] Flash Multiplexed Address/Data Bus |
| 63 | * FA[2:0] Flash Address Low |
| 64 | * |
| 65 | * GPIO[15,2] GPIO Port Mode |
| 66 | * GPIO[4:3] Flash Size |
| 67 | * |
| 68 | * 0xd2c Expansion ROM BAR Control |
| 69 | * 0xc08 PCI BAR2 (Flash/NVRAM) Control |
| 70 | * 0x1046c Flash Parameters |
| 71 | */ |
| 72 | int satamv_init(void) |
| 73 | { |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 74 | struct pci_dev *dev = NULL; |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 75 | uintptr_t addr; |
| 76 | uint32_t tmp; |
| 77 | |
Carl-Daniel Hailfinger | d6bb828 | 2012-07-21 17:27:08 +0000 | [diff] [blame] | 78 | if (rget_io_perms()) |
| 79 | return 1; |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 80 | |
| 81 | /* BAR0 has all internal registers memory mapped. */ |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 82 | dev = pcidev_init(satas_mv, PCI_BASE_ADDRESS_0); |
| 83 | if (!dev) |
| 84 | return 1; |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 85 | |
Carl-Daniel Hailfinger | a2faddf | 2013-01-05 23:52:45 +0000 | [diff] [blame] | 86 | addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0); |
Niklas Söderlund | 89edf36 | 2013-08-23 23:29:23 +0000 | [diff] [blame] | 87 | if (!addr) |
| 88 | return 1; |
| 89 | |
Stefan Tauner | 7fb5aa0 | 2013-08-14 15:48:44 +0000 | [diff] [blame] | 90 | mv_bar = rphysmap("Marvell 88SX7042 registers", addr, 0x20000); |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 91 | if (mv_bar == ERROR_PTR) |
Stefan Tauner | 5561955 | 2013-01-04 22:24:58 +0000 | [diff] [blame] | 92 | return 1; |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 93 | |
| 94 | tmp = pci_mmio_readl(mv_bar + FLASH_PARAM); |
| 95 | msg_pspew("Flash Parameters:\n"); |
| 96 | msg_pspew("TurnOff=0x%01x\n", (tmp >> 0) & 0x7); |
| 97 | msg_pspew("Acc2First=0x%01x\n", (tmp >> 3) & 0xf); |
| 98 | msg_pspew("Acc2Next=0x%01x\n", (tmp >> 7) & 0xf); |
| 99 | msg_pspew("ALE2Wr=0x%01x\n", (tmp >> 11) & 0x7); |
| 100 | msg_pspew("WrLow=0x%01x\n", (tmp >> 14) & 0x7); |
| 101 | msg_pspew("WrHigh=0x%01x\n", (tmp >> 17) & 0x7); |
| 102 | msg_pspew("Reserved[21:20]=0x%01x\n", (tmp >> 20) & 0x3); |
| 103 | msg_pspew("TurnOffExt=0x%01x\n", (tmp >> 22) & 0x1); |
| 104 | msg_pspew("Acc2FirstExt=0x%01x\n", (tmp >> 23) & 0x1); |
| 105 | msg_pspew("Acc2NextExt=0x%01x\n", (tmp >> 24) & 0x1); |
| 106 | msg_pspew("ALE2WrExt=0x%01x\n", (tmp >> 25) & 0x1); |
| 107 | msg_pspew("WrLowExt=0x%01x\n", (tmp >> 26) & 0x1); |
| 108 | msg_pspew("WrHighExt=0x%01x\n", (tmp >> 27) & 0x1); |
| 109 | msg_pspew("Reserved[31:28]=0x%01x\n", (tmp >> 28) & 0xf); |
| 110 | |
| 111 | tmp = pci_mmio_readl(mv_bar + EXPANSION_ROM_BAR_CONTROL); |
| 112 | msg_pspew("Expansion ROM BAR Control:\n"); |
| 113 | msg_pspew("ExpROMSz=0x%01x\n", (tmp >> 19) & 0x7); |
| 114 | |
| 115 | /* Enable BAR2 mapping to flash */ |
| 116 | tmp = pci_mmio_readl(mv_bar + PCI_BAR2_CONTROL); |
| 117 | msg_pspew("PCI BAR2 (Flash/NVRAM) Control:\n"); |
| 118 | msg_pspew("Bar2En=0x%01x\n", (tmp >> 0) & 0x1); |
| 119 | msg_pspew("BAR2TransAttr=0x%01x\n", (tmp >> 1) & 0x1f); |
| 120 | msg_pspew("BAR2Sz=0x%01x\n", (tmp >> 19) & 0x7); |
| 121 | tmp &= 0xffffffc0; |
| 122 | tmp |= 0x0000001f; |
Carl-Daniel Hailfinger | 54ce73a | 2011-05-03 21:49:41 +0000 | [diff] [blame] | 123 | pci_rmmio_writel(tmp, mv_bar + PCI_BAR2_CONTROL); |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 124 | |
| 125 | /* Enable flash: GPIO Port Control Register 0x104f0 */ |
| 126 | tmp = pci_mmio_readl(mv_bar + GPIO_PORT_CONTROL); |
| 127 | msg_pspew("GPIOPortMode=0x%01x\n", (tmp >> 0) & 0x3); |
| 128 | if (((tmp >> 0) & 0x3) != 0x2) |
| 129 | msg_pinfo("Warning! Either the straps are incorrect or you " |
| 130 | "have no flash or someone overwrote the strap " |
| 131 | "values!\n"); |
| 132 | tmp &= 0xfffffffc; |
| 133 | tmp |= 0x2; |
Carl-Daniel Hailfinger | 54ce73a | 2011-05-03 21:49:41 +0000 | [diff] [blame] | 134 | pci_rmmio_writel(tmp, mv_bar + GPIO_PORT_CONTROL); |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 135 | |
| 136 | /* Get I/O BAR location. */ |
Stefan Reinauer | 789ea5e | 2014-04-26 16:12:15 +0000 | [diff] [blame] | 137 | addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_2); |
Niklas Söderlund | 89edf36 | 2013-08-23 23:29:23 +0000 | [diff] [blame] | 138 | if (!addr) |
| 139 | return 1; |
| 140 | |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 141 | /* Truncate to reachable range. |
| 142 | * FIXME: Check if the I/O BAR is actually reachable. |
| 143 | * This is an arch specific check. |
| 144 | */ |
Stefan Reinauer | 789ea5e | 2014-04-26 16:12:15 +0000 | [diff] [blame] | 145 | mv_iobar = addr & 0xffff; |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 146 | msg_pspew("Activating I/O BAR at 0x%04x\n", mv_iobar); |
| 147 | |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 148 | /* 512 kByte with two 8-bit latches, and |
| 149 | * 4 MByte with additional 3-bit latch. */ |
| 150 | max_rom_decode.parallel = 4 * 1024 * 1024; |
Carl-Daniel Hailfinger | a5bcbce | 2014-07-19 22:03:29 +0000 | [diff] [blame] | 151 | register_par_master(&par_master_satamv, BUS_PARALLEL); |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 152 | |
| 153 | return 0; |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 156 | /* BAR2 (MEM) can map NVRAM and flash. We set it to flash in the init function. |
| 157 | * If BAR2 is disabled, it still can be accessed indirectly via BAR1 (I/O). |
| 158 | * This code only supports indirect accesses for now. |
| 159 | */ |
| 160 | |
| 161 | /* Indirect access to via the I/O BAR1. */ |
| 162 | static void satamv_indirect_chip_writeb(uint8_t val, chipaddr addr) |
| 163 | { |
| 164 | /* 0x80000000 selects BAR2 for remapping. */ |
| 165 | OUTL(((uint32_t)addr | 0x80000000) & 0xfffffffc, mv_iobar); |
| 166 | OUTB(val, mv_iobar + 0x80 + (addr & 0x3)); |
| 167 | } |
| 168 | |
| 169 | /* Indirect access to via the I/O BAR1. */ |
| 170 | static uint8_t satamv_indirect_chip_readb(const chipaddr addr) |
| 171 | { |
| 172 | /* 0x80000000 selects BAR2 for remapping. */ |
| 173 | OUTL(((uint32_t)addr | 0x80000000) & 0xfffffffc, mv_iobar); |
| 174 | return INB(mv_iobar + 0x80 + (addr & 0x3)); |
| 175 | } |
| 176 | |
| 177 | /* FIXME: Prefer direct access to BAR2 if BAR2 is active. */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 178 | static void satamv_chip_writeb(const struct flashctx *flash, uint8_t val, |
| 179 | chipaddr addr) |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 180 | { |
| 181 | satamv_indirect_chip_writeb(val, addr); |
| 182 | } |
| 183 | |
| 184 | /* FIXME: Prefer direct access to BAR2 if BAR2 is active. */ |
Carl-Daniel Hailfinger | 8a3c60c | 2011-12-18 15:01:24 +0000 | [diff] [blame] | 185 | static uint8_t satamv_chip_readb(const struct flashctx *flash, |
| 186 | const chipaddr addr) |
Carl-Daniel Hailfinger | 9a1105c | 2011-02-04 21:37:59 +0000 | [diff] [blame] | 187 | { |
| 188 | return satamv_indirect_chip_readb(addr); |
| 189 | } |
Andrew Morgan | a074383 | 2011-07-25 22:07:05 +0000 | [diff] [blame] | 190 | |
| 191 | #else |
| 192 | #error PCI port I/O access is not supported on this architecture yet. |
| 193 | #endif |