blob: 8766372d0907f96567da8fe0c066d655307ba63c [file] [log] [blame]
hailfinger935365d2011-02-04 21:37:59 +00001/*
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/* Datasheets are not public (yet?) */
hailfingera49e9c12011-07-25 22:07:05 +000022#if defined(__i386__) || defined(__x86_64__)
hailfinger935365d2011-02-04 21:37:59 +000023
24#include <stdlib.h>
25#include "flash.h"
26#include "programmer.h"
27
28uint8_t *mv_bar;
29uint16_t mv_iobar;
30
Patrick Georgi8ae16572017-03-09 15:59:25 +010031const struct dev_entry satas_mv[] = {
hailfinger935365d2011-02-04 21:37:59 +000032 /* 88SX6041 and 88SX6042 are the same according to the datasheet. */
33 {0x11ab, 0x7042, OK, "Marvell", "88SX7042 PCI-e 4-port SATA-II"},
34
Patrick Georgi8ddfee92017-03-20 14:54:28 +010035 {0},
hailfinger935365d2011-02-04 21:37:59 +000036};
37
38#define NVRAM_PARAM 0x1045c
39#define FLASH_PARAM 0x1046c
40#define EXPANSION_ROM_BAR_CONTROL 0x00d2c
41#define PCI_BAR2_CONTROL 0x00c08
42#define GPIO_PORT_CONTROL 0x104f0
43
Souvik Ghoshd75cd672016-06-17 14:21:39 -070044static void satamv_chip_writeb(const struct flashctx *flash, uint8_t val,
45 chipaddr addr);
46static uint8_t satamv_chip_readb(const struct flashctx *flash,
47 const chipaddr addr);
Patrick Georgi0a9533a2017-02-03 19:28:38 +010048static const struct par_master par_master_satamv = {
hailfinger76bb7e92011-11-09 23:40:00 +000049 .chip_readb = satamv_chip_readb,
50 .chip_readw = fallback_chip_readw,
51 .chip_readl = fallback_chip_readl,
52 .chip_readn = fallback_chip_readn,
53 .chip_writeb = satamv_chip_writeb,
54 .chip_writew = fallback_chip_writew,
55 .chip_writel = fallback_chip_writel,
56 .chip_writen = fallback_chip_writen,
57};
58
hailfinger935365d2011-02-04 21:37:59 +000059/*
60 * Random notes:
61 * FCE# Flash Chip Enable
62 * FWE# Flash Write Enable
63 * FOE# Flash Output Enable
64 * FALE[1:0] Flash Address Latch Enable
65 * FAD[7:0] Flash Multiplexed Address/Data Bus
66 * FA[2:0] Flash Address Low
67 *
68 * GPIO[15,2] GPIO Port Mode
69 * GPIO[4:3] Flash Size
70 *
71 * 0xd2c Expansion ROM BAR Control
72 * 0xc08 PCI BAR2 (Flash/NVRAM) Control
73 * 0x1046c Flash Parameters
74 */
David Hendricksac1d25c2016-08-09 17:00:58 -070075int satamv_init(void)
hailfinger935365d2011-02-04 21:37:59 +000076{
Patrick Georgi7c30fa92017-03-28 22:47:12 +020077 struct pci_dev *dev = NULL;
hailfinger935365d2011-02-04 21:37:59 +000078 uintptr_t addr;
79 uint32_t tmp;
80
Patrick Georgi2a2d67f2017-03-09 10:15:39 +010081 if (rget_io_perms())
82 return 1;
hailfinger935365d2011-02-04 21:37:59 +000083
84 /* BAR0 has all internal registers memory mapped. */
Patrick Georgi7c30fa92017-03-28 22:47:12 +020085 dev = pcidev_init(satas_mv, PCI_BASE_ADDRESS_0);
86 if (!dev)
87 return 1;
88
89 addr = pcidev_readbar(dev, PCI_BASE_ADDRESS_0);
90 if (!addr)
91 return 1;
hailfinger935365d2011-02-04 21:37:59 +000092
Patrick Georgi124bd002017-03-21 17:25:59 +010093 mv_bar = rphysmap("Marvell 88SX7042 registers", addr, 0x20000);
hailfinger935365d2011-02-04 21:37:59 +000094 if (mv_bar == ERROR_PTR)
95 goto error_out;
96
97 tmp = pci_mmio_readl(mv_bar + FLASH_PARAM);
98 msg_pspew("Flash Parameters:\n");
99 msg_pspew("TurnOff=0x%01x\n", (tmp >> 0) & 0x7);
100 msg_pspew("Acc2First=0x%01x\n", (tmp >> 3) & 0xf);
101 msg_pspew("Acc2Next=0x%01x\n", (tmp >> 7) & 0xf);
102 msg_pspew("ALE2Wr=0x%01x\n", (tmp >> 11) & 0x7);
103 msg_pspew("WrLow=0x%01x\n", (tmp >> 14) & 0x7);
104 msg_pspew("WrHigh=0x%01x\n", (tmp >> 17) & 0x7);
105 msg_pspew("Reserved[21:20]=0x%01x\n", (tmp >> 20) & 0x3);
106 msg_pspew("TurnOffExt=0x%01x\n", (tmp >> 22) & 0x1);
107 msg_pspew("Acc2FirstExt=0x%01x\n", (tmp >> 23) & 0x1);
108 msg_pspew("Acc2NextExt=0x%01x\n", (tmp >> 24) & 0x1);
109 msg_pspew("ALE2WrExt=0x%01x\n", (tmp >> 25) & 0x1);
110 msg_pspew("WrLowExt=0x%01x\n", (tmp >> 26) & 0x1);
111 msg_pspew("WrHighExt=0x%01x\n", (tmp >> 27) & 0x1);
112 msg_pspew("Reserved[31:28]=0x%01x\n", (tmp >> 28) & 0xf);
113
114 tmp = pci_mmio_readl(mv_bar + EXPANSION_ROM_BAR_CONTROL);
115 msg_pspew("Expansion ROM BAR Control:\n");
116 msg_pspew("ExpROMSz=0x%01x\n", (tmp >> 19) & 0x7);
117
118 /* Enable BAR2 mapping to flash */
119 tmp = pci_mmio_readl(mv_bar + PCI_BAR2_CONTROL);
120 msg_pspew("PCI BAR2 (Flash/NVRAM) Control:\n");
121 msg_pspew("Bar2En=0x%01x\n", (tmp >> 0) & 0x1);
122 msg_pspew("BAR2TransAttr=0x%01x\n", (tmp >> 1) & 0x1f);
123 msg_pspew("BAR2Sz=0x%01x\n", (tmp >> 19) & 0x7);
124 tmp &= 0xffffffc0;
125 tmp |= 0x0000001f;
hailfinger1e2e3442011-05-03 21:49:41 +0000126 pci_rmmio_writel(tmp, mv_bar + PCI_BAR2_CONTROL);
hailfinger935365d2011-02-04 21:37:59 +0000127
128 /* Enable flash: GPIO Port Control Register 0x104f0 */
129 tmp = pci_mmio_readl(mv_bar + GPIO_PORT_CONTROL);
130 msg_pspew("GPIOPortMode=0x%01x\n", (tmp >> 0) & 0x3);
131 if (((tmp >> 0) & 0x3) != 0x2)
132 msg_pinfo("Warning! Either the straps are incorrect or you "
133 "have no flash or someone overwrote the strap "
134 "values!\n");
135 tmp &= 0xfffffffc;
136 tmp |= 0x2;
hailfinger1e2e3442011-05-03 21:49:41 +0000137 pci_rmmio_writel(tmp, mv_bar + GPIO_PORT_CONTROL);
hailfinger935365d2011-02-04 21:37:59 +0000138
139 /* Get I/O BAR location. */
140 tmp = pci_read_long(pcidev_dev, PCI_BASE_ADDRESS_2) &
141 PCI_BASE_ADDRESS_IO_MASK;
142 /* Truncate to reachable range.
143 * FIXME: Check if the I/O BAR is actually reachable.
144 * This is an arch specific check.
145 */
146 mv_iobar = tmp & 0xffff;
147 msg_pspew("Activating I/O BAR at 0x%04x\n", mv_iobar);
148
hailfinger935365d2011-02-04 21:37:59 +0000149 /* 512 kByte with two 8-bit latches, and
150 * 4 MByte with additional 3-bit latch. */
151 max_rom_decode.parallel = 4 * 1024 * 1024;
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100152 register_par_master(&par_master_satamv, BUS_PARALLEL);
hailfinger935365d2011-02-04 21:37:59 +0000153
154 return 0;
155
156error_out:
hailfinger935365d2011-02-04 21:37:59 +0000157 return 1;
158}
159
hailfinger935365d2011-02-04 21:37:59 +0000160/* BAR2 (MEM) can map NVRAM and flash. We set it to flash in the init function.
161 * If BAR2 is disabled, it still can be accessed indirectly via BAR1 (I/O).
162 * This code only supports indirect accesses for now.
163 */
164
165/* Indirect access to via the I/O BAR1. */
166static void satamv_indirect_chip_writeb(uint8_t val, chipaddr addr)
167{
168 /* 0x80000000 selects BAR2 for remapping. */
169 OUTL(((uint32_t)addr | 0x80000000) & 0xfffffffc, mv_iobar);
170 OUTB(val, mv_iobar + 0x80 + (addr & 0x3));
171}
172
173/* Indirect access to via the I/O BAR1. */
174static uint8_t satamv_indirect_chip_readb(const chipaddr addr)
175{
176 /* 0x80000000 selects BAR2 for remapping. */
177 OUTL(((uint32_t)addr | 0x80000000) & 0xfffffffc, mv_iobar);
178 return INB(mv_iobar + 0x80 + (addr & 0x3));
179}
180
181/* FIXME: Prefer direct access to BAR2 if BAR2 is active. */
Patrick Georgid4caa6b2017-03-28 21:22:55 +0200182static void satamv_chip_writeb(const struct flashctx *flash, uint8_t val,
183 chipaddr addr)
hailfinger935365d2011-02-04 21:37:59 +0000184{
185 satamv_indirect_chip_writeb(val, addr);
186}
187
188/* FIXME: Prefer direct access to BAR2 if BAR2 is active. */
Patrick Georgid4caa6b2017-03-28 21:22:55 +0200189static uint8_t satamv_chip_readb(const struct flashctx *flash,
190 const chipaddr addr)
hailfinger935365d2011-02-04 21:37:59 +0000191{
192 return satamv_indirect_chip_readb(addr);
193}
hailfingera49e9c12011-07-25 22:07:05 +0000194
195#else
196#error PCI port I/O access is not supported on this architecture yet.
197#endif