blob: d9b3b7d42c2de0aff654d2e3b2e15b842537ac39 [file] [log] [blame]
Adam Kaufman064b1f22007-02-06 19:47:50 +00001/*
Uwe Hermannd1107642007-08-29 17:52:32 +00002 * This file is part of the flashrom project.
Adam Kaufman064b1f22007-02-06 19:47:50 +00003 *
Uwe Hermannd22a1d42007-09-09 20:21:05 +00004 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
Stefan Reinauer8fa64812009-08-12 09:27:45 +00006 * Copyright (C) 2005-2009 coresystems GmbH
Carl-Daniel Hailfingera0a6ae92009-06-15 12:10:57 +00007 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
Adam Kaufman064b1f22007-02-06 19:47:50 +00008 *
Uwe Hermannd1107642007-08-29 17:52:32 +00009 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
Adam Kaufman064b1f22007-02-06 19:47:50 +000013 *
Uwe Hermannd1107642007-08-29 17:52:32 +000014 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
Adam Kaufman064b1f22007-02-06 19:47:50 +000018 *
Uwe Hermannd1107642007-08-29 17:52:32 +000019 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Adam Kaufman064b1f22007-02-06 19:47:50 +000022 */
23
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000024#ifndef __FLASH_H__
25#define __FLASH_H__ 1
26
Adam Kaufman064b1f22007-02-06 19:47:50 +000027#if defined(__GLIBC__)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000028#include <sys/io.h>
Adam Kaufman064b1f22007-02-06 19:47:50 +000029#endif
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000030#include <unistd.h>
Ollie Lho184a4042005-11-26 21:55:36 +000031#include <stdint.h>
Uwe Hermann0846f892007-08-23 13:34:59 +000032#include <stdio.h>
Christian Ruppert0cdb0312009-05-14 18:57:26 +000033#include <pci/pci.h>
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000034
Carl-Daniel Hailfinger9abf5292009-05-01 16:34:32 +000035/* for iopl and outb under Solaris */
36#if defined (__sun) && (defined(__i386) || defined(__amd64))
37#include <strings.h>
38#include <sys/sysi86.h>
39#include <sys/psw.h>
40#include <asm/sunddi.h>
41#endif
42
Stefan Reinauerf79edb92009-01-26 01:23:31 +000043#if (defined(__MACH__) && defined(__APPLE__))
44#define __DARWIN__
45#endif
46
Patrick Georgi60622e22009-04-28 12:56:04 +000047#if defined(__FreeBSD__) || defined(__DragonFly__)
Andriy Gapon65c1b862008-05-22 13:22:45 +000048 #include <machine/cpufunc.h>
49 #define off64_t off_t
50 #define lseek64 lseek
51 #define OUTB(x, y) do { u_int tmp = (y); outb(tmp, (x)); } while (0)
52 #define OUTW(x, y) do { u_int tmp = (y); outw(tmp, (x)); } while (0)
53 #define OUTL(x, y) do { u_int tmp = (y); outl(tmp, (x)); } while (0)
54 #define INB(x) __extension__ ({ u_int tmp = (x); inb(tmp); })
55 #define INW(x) __extension__ ({ u_int tmp = (x); inw(tmp); })
56 #define INL(x) __extension__ ({ u_int tmp = (x); inl(tmp); })
57#else
Stefan Reinauerf79edb92009-01-26 01:23:31 +000058#if defined(__DARWIN__)
59 #include <DirectIO/darwinio.h>
60 #define off64_t off_t
61 #define lseek64 lseek
62#endif
Carl-Daniel Hailfinger9abf5292009-05-01 16:34:32 +000063#if defined (__sun) && (defined(__i386) || defined(__amd64))
64 /* Note different order for outb */
65 #define OUTB(x,y) outb(y, x)
66 #define OUTW(x,y) outw(y, x)
67 #define OUTL(x,y) outl(y, x)
68 #define INB inb
69 #define INW inw
70 #define INL inl
71#else
Andriy Gapon65c1b862008-05-22 13:22:45 +000072 #define OUTB outb
73 #define OUTW outw
74 #define OUTL outl
75 #define INB inb
76 #define INW inw
77 #define INL inl
78#endif
Carl-Daniel Hailfinger9abf5292009-05-01 16:34:32 +000079#endif
Andriy Gapon65c1b862008-05-22 13:22:45 +000080
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +000081typedef unsigned long chipaddr;
82
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +000083enum programmer {
84 PROGRAMMER_INTERNAL,
85 PROGRAMMER_DUMMY,
86 PROGRAMMER_NIC3COM,
87 PROGRAMMER_SATASII,
88 PROGRAMMER_IT87SPI,
89 PROGRAMMER_FT2232SPI,
90 PROGRAMMER_SERPROG,
91};
92
93extern enum programmer programmer;
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +000094
95struct programmer_entry {
96 const char *vendor;
97 const char *name;
98
99 int (*init) (void);
100 int (*shutdown) (void);
101
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000102 void * (*map_flash_region) (const char *descr, unsigned long phys_addr,
103 size_t len);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000104 void (*unmap_flash_region) (void *virt_addr, size_t len);
105
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000106 void (*chip_writeb) (uint8_t val, chipaddr addr);
107 void (*chip_writew) (uint16_t val, chipaddr addr);
108 void (*chip_writel) (uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000109 void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000110 uint8_t (*chip_readb) (const chipaddr addr);
111 uint16_t (*chip_readw) (const chipaddr addr);
112 uint32_t (*chip_readl) (const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000113 void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000114 void (*delay) (int usecs);
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000115};
116
117extern const struct programmer_entry programmer_table[];
118
Uwe Hermann09e04f72009-05-16 22:36:00 +0000119int programmer_init(void);
120int programmer_shutdown(void);
121void *programmer_map_flash_region(const char *descr, unsigned long phys_addr,
122 size_t len);
123void programmer_unmap_flash_region(void *virt_addr, size_t len);
124void chip_writeb(uint8_t val, chipaddr addr);
125void chip_writew(uint16_t val, chipaddr addr);
126void chip_writel(uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000127void chip_writen(uint8_t *buf, chipaddr addr, size_t len);
Uwe Hermann09e04f72009-05-16 22:36:00 +0000128uint8_t chip_readb(const chipaddr addr);
129uint16_t chip_readw(const chipaddr addr);
130uint32_t chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000131void chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000132void programmer_delay(int usecs);
Carl-Daniel Hailfinger61a8bd22009-03-05 19:24:22 +0000133
Uwe Hermanne5ac1642008-03-12 11:54:51 +0000134#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
135
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000136enum chipbustype {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000137 CHIP_BUSTYPE_NONE = 0,
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000138 CHIP_BUSTYPE_PARALLEL = 1 << 0,
139 CHIP_BUSTYPE_LPC = 1 << 1,
140 CHIP_BUSTYPE_FWH = 1 << 2,
141 CHIP_BUSTYPE_SPI = 1 << 3,
142 CHIP_BUSTYPE_NONSPI = CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH,
143 CHIP_BUSTYPE_UNKNOWN = CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI,
144};
145
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000146struct flashchip {
Uwe Hermann76158682008-03-14 23:55:58 +0000147 const char *vendor;
Uwe Hermann372eeb52007-12-04 21:49:06 +0000148 const char *name;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000149
150 enum chipbustype bustype;
151
Uwe Hermann394131e2008-10-18 21:14:13 +0000152 /*
153 * With 32bit manufacture_id and model_id we can cover IDs up to
Carl-Daniel Hailfingerae8afa92007-12-31 01:49:00 +0000154 * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's
155 * Identification code.
156 */
157 uint32_t manufacture_id;
158 uint32_t model_id;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000159
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000160 int total_size;
161 int page_size;
162
Uwe Hermann394131e2008-10-18 21:14:13 +0000163 /*
164 * Indicate if flashrom has been tested with this flash chip and if
Peter Stuge1159d582008-05-03 04:34:37 +0000165 * everything worked correctly.
166 */
167 uint32_t tested;
168
Uwe Hermann0b7afe62007-04-01 19:44:21 +0000169 int (*probe) (struct flashchip *flash);
Maciej Pijankac6e11112009-06-03 14:46:22 +0000170
171 /* Delay after "enter/exit ID mode" commands in microseconds. */
172 int probe_timing;
Uwe Hermann0b7afe62007-04-01 19:44:21 +0000173 int (*erase) (struct flashchip *flash);
174 int (*write) (struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000175 int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000176
Uwe Hermann372eeb52007-12-04 21:49:06 +0000177 /* Some flash devices have an additional register space. */
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000178 chipaddr virtual_memory;
179 chipaddr virtual_registers;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000180};
181
Peter Stuge1159d582008-05-03 04:34:37 +0000182#define TEST_UNTESTED 0
183
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000184#define TEST_OK_PROBE (1 << 0)
185#define TEST_OK_READ (1 << 1)
186#define TEST_OK_ERASE (1 << 2)
187#define TEST_OK_WRITE (1 << 3)
188#define TEST_OK_PR (TEST_OK_PROBE | TEST_OK_READ)
189#define TEST_OK_PRE (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE)
190#define TEST_OK_PREW (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_WRITE)
Peter Stuge1159d582008-05-03 04:34:37 +0000191#define TEST_OK_MASK 0x0f
192
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000193#define TEST_BAD_PROBE (1 << 4)
194#define TEST_BAD_READ (1 << 5)
195#define TEST_BAD_ERASE (1 << 6)
196#define TEST_BAD_WRITE (1 << 7)
197#define TEST_BAD_PREW (TEST_BAD_PROBE | TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE)
Peter Stuge1159d582008-05-03 04:34:37 +0000198#define TEST_BAD_MASK 0xf0
199
Maciej Pijankac6e11112009-06-03 14:46:22 +0000200/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
201 * field and zero delay.
202 *
203 * SPI devices will always have zero delay and ignore this field.
204 */
205#define TIMING_FIXME -1
206/* this is intentionally same value as fixme */
207#define TIMING_IGNORED -1
208#define TIMING_ZERO -2
209
Ollie Lho184a4042005-11-26 21:55:36 +0000210extern struct flashchip flashchips[];
211
Uwe Hermann05fab752009-05-16 23:42:17 +0000212struct penable {
213 uint16_t vendor_id;
214 uint16_t device_id;
215 int status;
216 const char *vendor_name;
217 const char *device_name;
218 int (*doit) (struct pci_dev *dev, const char *name);
219};
220
221extern const struct penable chipset_enables[];
222
223struct board_pciid_enable {
224 /* Any device, but make it sensible, like the ISA bridge. */
225 uint16_t first_vendor;
226 uint16_t first_device;
227 uint16_t first_card_vendor;
228 uint16_t first_card_device;
229
230 /* Any device, but make it sensible, like
231 * the host bridge. May be NULL.
232 */
233 uint16_t second_vendor;
234 uint16_t second_device;
235 uint16_t second_card_vendor;
236 uint16_t second_card_device;
237
238 /* The vendor / part name from the coreboot table. */
239 const char *lb_vendor;
240 const char *lb_part;
241
242 const char *vendor_name;
243 const char *board_name;
244
245 int (*enable) (const char *name);
246};
247
248extern struct board_pciid_enable board_pciid_enables[];
249
250struct board_info {
251 const char *vendor;
252 const char *name;
253};
254
255extern const struct board_info boards_ok[];
256extern const struct board_info boards_bad[];
Uwe Hermanne1aa75e2009-06-18 14:04:44 +0000257extern const struct board_info laptops_ok[];
258extern const struct board_info laptops_bad[];
Uwe Hermann05fab752009-05-16 23:42:17 +0000259
Uwe Hermann372eeb52007-12-04 21:49:06 +0000260/* udelay.c */
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000261void myusec_delay(int usecs);
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000262void myusec_calibrate_delay(void);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000263
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000264/* pcidev.c */
265#define PCI_OK 0
266#define PCI_NT 1 /* Not tested */
Rudolf Marek68720c72009-05-17 19:39:27 +0000267
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000268extern uint32_t io_base_addr;
269extern struct pci_access *pacc;
270extern struct pci_filter filter;
Uwe Hermann8403ccb2009-05-16 21:39:19 +0000271extern struct pci_dev *pcidev_dev;
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000272struct pcidev_status {
273 uint16_t vendor_id;
274 uint16_t device_id;
275 int status;
276 const char *vendor_name;
277 const char *device_name;
278};
279uint32_t pcidev_validate(struct pci_dev *dev, struct pcidev_status *devs);
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +0000280uint32_t pcidev_init(uint16_t vendor_id, struct pcidev_status *devs, char *pcidev_bdf);
Uwe Hermannba290d12009-06-17 12:07:12 +0000281
282/* print.c */
283char *flashbuses_to_text(enum chipbustype bustype);
284void print_supported_chips(void);
285void print_supported_chipsets(void);
286void print_supported_boards(void);
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000287void print_supported_pcidevs(struct pcidev_status *devs);
Uwe Hermanna2d05012009-06-20 01:21:38 +0000288void print_wiki_tables(void);
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000289
Uwe Hermann372eeb52007-12-04 21:49:06 +0000290/* board_enable.c */
Peter Stuge9d9399c2009-01-26 02:34:51 +0000291void w836xx_ext_enter(uint16_t port);
292void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +0000293uint8_t sio_read(uint16_t port, uint8_t reg);
294void sio_write(uint16_t port, uint8_t reg, uint8_t data);
295void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Uwe Hermann372eeb52007-12-04 21:49:06 +0000296int board_flash_enable(const char *vendor, const char *part);
Adam Kaufman064b1f22007-02-06 19:47:50 +0000297
Uwe Hermann372eeb52007-12-04 21:49:06 +0000298/* chipset_enable.c */
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000299extern enum chipbustype buses_supported;
Uwe Hermann372eeb52007-12-04 21:49:06 +0000300int chipset_flash_enable(void);
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000301
Stefan Reinauer9a6d1762008-12-03 21:24:40 +0000302extern unsigned long flashbase;
303
Stefan Reinauer0593f212009-01-26 01:10:48 +0000304/* physmap.c */
305void *physmap(const char *descr, unsigned long phys_addr, size_t len);
306void physunmap(void *virt_addr, size_t len);
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000307int setup_cpu_msr(int cpu);
308void cleanup_cpu_msr(void);
309#ifndef __DARWIN__
310typedef struct { uint32_t hi, lo; } msr_t;
311msr_t rdmsr(int addr);
312int wrmsr(int addr, msr_t msr);
313#endif
Stefan Reinauer0593f212009-01-26 01:10:48 +0000314
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000315/* internal.c */
Uwe Hermann2cac6862009-05-16 22:05:42 +0000316struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
317struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
318struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
319 uint16_t card_vendor, uint16_t card_device);
Carl-Daniel Hailfinger3b7e75a2009-05-14 21:41:10 +0000320void get_io_perms(void);
Carl-Daniel Hailfingerdb41c592009-08-09 21:50:24 +0000321void release_io_perms(void);
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000322int internal_init(void);
323int internal_shutdown(void);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000324void internal_chip_writeb(uint8_t val, chipaddr addr);
325void internal_chip_writew(uint16_t val, chipaddr addr);
326void internal_chip_writel(uint32_t val, chipaddr addr);
327uint8_t internal_chip_readb(const chipaddr addr);
328uint16_t internal_chip_readw(const chipaddr addr);
329uint32_t internal_chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000330void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000331void mmio_writeb(uint8_t val, void *addr);
332void mmio_writew(uint16_t val, void *addr);
333void mmio_writel(uint32_t val, void *addr);
334uint8_t mmio_readb(void *addr);
335uint16_t mmio_readw(void *addr);
336uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000337void internal_delay(int usecs);
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +0000338int fallback_shutdown(void);
Uwe Hermannc6915932009-05-17 23:12:17 +0000339void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
340void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +0000341void fallback_chip_writeb(uint8_t val, chipaddr addr);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000342void fallback_chip_writew(uint16_t val, chipaddr addr);
343void fallback_chip_writel(uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000344void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000345uint16_t fallback_chip_readw(const chipaddr addr);
346uint32_t fallback_chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000347void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Uwe Hermanna0869322009-05-14 20:41:57 +0000348#if defined(__FreeBSD__) || defined(__DragonFly__)
349extern int io_fd;
350#endif
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000351
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000352/* dummyflasher.c */
353int dummy_init(void);
354int dummy_shutdown(void);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000355void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
356void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000357void dummy_chip_writeb(uint8_t val, chipaddr addr);
358void dummy_chip_writew(uint16_t val, chipaddr addr);
359void dummy_chip_writel(uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000360void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000361uint8_t dummy_chip_readb(const chipaddr addr);
362uint16_t dummy_chip_readw(const chipaddr addr);
363uint32_t dummy_chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000364void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000365int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000366 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000367
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000368/* nic3com.c */
369int nic3com_init(void);
370int nic3com_shutdown(void);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000371void nic3com_chip_writeb(uint8_t val, chipaddr addr);
372uint8_t nic3com_chip_readb(const chipaddr addr);
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000373extern struct pcidev_status nics_3com[];
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000374
Rudolf Marek68720c72009-05-17 19:39:27 +0000375/* satasii.c */
376int satasii_init(void);
377int satasii_shutdown(void);
Rudolf Marek68720c72009-05-17 19:39:27 +0000378void satasii_chip_writeb(uint8_t val, chipaddr addr);
379uint8_t satasii_chip_readb(const chipaddr addr);
380extern struct pcidev_status satas_sii[];
381
Paul Fox05dfbe62009-06-16 21:08:06 +0000382/* ft2232_spi.c */
Carl-Daniel Hailfingerfeea2722009-07-01 00:02:23 +0000383#define FTDI_FT2232H 0x6010
384#define FTDI_FT4232H 0x6011
Paul Fox05dfbe62009-06-16 21:08:06 +0000385int ft2232_spi_init(void);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000386int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
Paul Fox05dfbe62009-06-16 21:08:06 +0000387int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Paul Fox05dfbe62009-06-16 21:08:06 +0000388int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf);
389
Uwe Hermann0846f892007-08-23 13:34:59 +0000390/* flashrom.c */
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +0000391extern char *programmer_param;
Uwe Hermannad216bf2009-04-24 16:17:41 +0000392extern int verbose;
Carl-Daniel Hailfingera80cfbc2009-07-22 20:13:00 +0000393extern const char *flashrom_version;
Uwe Hermannad216bf2009-04-24 16:17:41 +0000394#define printf_debug(x...) { if (verbose) printf(x); }
Peter Stuge776d2022009-01-26 00:39:57 +0000395void map_flash_registers(struct flashchip *flash);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000396int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger38a059d2009-06-13 12:04:03 +0000397int min(int a, int b);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000398int max(int a, int b);
399int check_erased_range(struct flashchip *flash, int start, int len);
400int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message);
Uwe Hermannba290d12009-06-17 12:07:12 +0000401char *strcat_realloc(char *dest, const char *src);
402
403#define OK 0
404#define NT 1 /* Not tested */
Uwe Hermann0846f892007-08-23 13:34:59 +0000405
406/* layout.c */
Peter Stuge7ffbc6f2008-06-18 02:08:40 +0000407int show_id(uint8_t *bios, int size, int force);
Uwe Hermann0846f892007-08-23 13:34:59 +0000408int read_romlayout(char *name);
409int find_romentry(char *name);
410int handle_romentries(uint8_t *buffer, uint8_t *content);
411
Uwe Hermannad216bf2009-04-24 16:17:41 +0000412/* cbtable.c */
Stefan Reinauere3f3e2e2008-01-18 15:33:10 +0000413int coreboot_init(void);
Uwe Hermann0846f892007-08-23 13:34:59 +0000414extern char *lb_part, *lb_vendor;
Carl-Daniel Hailfingerbc25f942009-07-30 13:30:17 +0000415extern int partvendor_from_cbtable;
Uwe Hermann0846f892007-08-23 13:34:59 +0000416
Carl-Daniel Hailfinger00f911e2007-10-15 21:44:47 +0000417/* spi.c */
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000418enum spi_controller {
419 SPI_CONTROLLER_NONE,
420 SPI_CONTROLLER_ICH7,
421 SPI_CONTROLLER_ICH9,
422 SPI_CONTROLLER_IT87XX,
423 SPI_CONTROLLER_SB600,
424 SPI_CONTROLLER_VIA,
425 SPI_CONTROLLER_WBSIO,
Paul Fox05dfbe62009-06-16 21:08:06 +0000426 SPI_CONTROLLER_FT2232,
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000427 SPI_CONTROLLER_DUMMY,
428};
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000429struct spi_command {
430 unsigned int writecnt;
431 unsigned int readcnt;
432 const unsigned char *writearr;
433 unsigned char *readarr;
434};
Carl-Daniel Hailfinger02487aa2009-07-22 15:36:50 +0000435struct spi_programmer {
436 int (*command)(unsigned int writecnt, unsigned int readcnt,
437 const unsigned char *writearr, unsigned char *readarr);
438 int (*multicommand)(struct spi_command *spicommands);
439
440 /* Optimized functions for this programmer */
441 int (*read)(struct flashchip *flash, uint8_t *buf, int start, int len);
442 int (*write_256)(struct flashchip *flash, uint8_t *buf);
443};
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000444
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000445extern enum spi_controller spi_controller;
Carl-Daniel Hailfinger02487aa2009-07-22 15:36:50 +0000446extern const struct spi_programmer spi_programmer[];
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000447extern void *spibar;
Carl-Daniel Hailfinger42c54972008-05-15 03:19:49 +0000448int probe_spi_rdid(struct flashchip *flash);
Rudolf Marek48a85e42008-06-30 21:45:17 +0000449int probe_spi_rdid4(struct flashchip *flash);
Carl-Daniel Hailfinger14e50ac2008-11-28 01:25:00 +0000450int probe_spi_rems(struct flashchip *flash);
Carl-Daniel Hailfinger42c54972008-05-15 03:19:49 +0000451int probe_spi_res(struct flashchip *flash);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000452int spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermann394131e2008-10-18 21:14:13 +0000453 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000454int spi_send_multicommand(struct spi_command *spicommands);
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000455int spi_write_enable(void);
456int spi_write_disable(void);
Carl-Daniel Hailfinger6afb6132008-11-03 00:02:11 +0000457int spi_chip_erase_60(struct flashchip *flash);
Peter Stugefa8c5502008-05-10 23:07:52 +0000458int spi_chip_erase_c7(struct flashchip *flash);
Carl-Daniel Hailfinger598ec582008-11-18 00:41:02 +0000459int spi_chip_erase_60_c7(struct flashchip *flash);
Stefan Reinauer424ed222008-10-29 22:13:20 +0000460int spi_chip_erase_d8(struct flashchip *flash);
Carl-Daniel Hailfinger3431bb72009-06-24 08:28:39 +0000461int spi_block_erase_20(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
462int spi_block_erase_52(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
463int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
464int spi_block_erase_60(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
465int spi_block_erase_c7(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000466int spi_chip_write_1(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger8d497012009-05-09 02:34:18 +0000467int spi_chip_write_256(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000468int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000469uint8_t spi_read_status_register(void);
Carl-Daniel Hailfinger598ec582008-11-18 00:41:02 +0000470int spi_disable_blockprotect(void);
Carl-Daniel Hailfinger2f1b36f2009-07-12 12:06:18 +0000471int spi_byte_program(int addr, uint8_t byte);
472int spi_nbyte_program(int addr, uint8_t *bytes, int len);
473int spi_nbyte_read(int addr, uint8_t *bytes, int len);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000474int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize);
Peter Stugefd9217d2009-01-26 03:37:40 +0000475int spi_aai_write(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger3e9dbea2009-05-13 11:40:08 +0000476uint32_t spi_get_valid_read_addr(void);
Carl-Daniel Hailfinger02487aa2009-07-22 15:36:50 +0000477int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
478 const unsigned char *writearr, unsigned char *readarr);
479int default_spi_send_multicommand(struct spi_command *spicommands);
Carl-Daniel Hailfingere1514992007-10-02 15:49:25 +0000480
Uwe Hermann0846f892007-08-23 13:34:59 +0000481/* 82802ab.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000482int probe_82802ab(struct flashchip *flash);
483int erase_82802ab(struct flashchip *flash);
484int write_82802ab(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000485
486/* am29f040b.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000487int probe_29f040b(struct flashchip *flash);
488int erase_29f040b(struct flashchip *flash);
489int write_29f040b(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000490
Uwe Hermannf983d9f2009-06-14 21:53:26 +0000491/* pm29f002.c */
492int write_pm29f002(struct flashchip *flash, uint8_t *buf);
493
Mats Erik Andersson44e1a192008-09-26 13:19:02 +0000494/* en29f002a.c */
495int probe_en29f002a(struct flashchip *flash);
496int erase_en29f002a(struct flashchip *flash);
497int write_en29f002a(struct flashchip *flash, uint8_t *buf);
498
Dominik Geyerb46acba2008-05-16 12:55:55 +0000499/* ichspi.c */
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000500int ich_init_opcodes(void);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000501int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermann394131e2008-10-18 21:14:13 +0000502 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000503int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000504int ich_spi_write_256(struct flashchip *flash, uint8_t * buf);
Carl-Daniel Hailfinger02487aa2009-07-22 15:36:50 +0000505int ich_spi_send_multicommand(struct spi_command *spicommands);
Dominik Geyerb46acba2008-05-16 12:55:55 +0000506
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000507/* it87spi.c */
508extern uint16_t it8716f_flashport;
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +0000509void enter_conf_mode_ite(uint16_t port);
510void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000511int it87spi_init(void);
Dominik Geyerb46acba2008-05-16 12:55:55 +0000512int it87xx_probe_spi_flash(const char *name);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000513int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermann394131e2008-10-18 21:14:13 +0000514 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000515int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000516int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000517
Jason Wanga3f04be2008-11-28 21:36:51 +0000518/* sb600spi.c */
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000519int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Jason Wanga3f04be2008-11-28 21:36:51 +0000520 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000521int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000522int sb600_spi_write_1(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000523extern uint8_t *sb600_spibar;
Jason Wanga3f04be2008-11-28 21:36:51 +0000524
Uwe Hermann0846f892007-08-23 13:34:59 +0000525/* jedec.c */
Carl-Daniel Hailfingera758f512008-05-14 12:03:06 +0000526uint8_t oddparity(uint8_t val);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000527void toggle_ready_jedec(chipaddr dst);
528void data_polling_jedec(chipaddr dst, uint8_t data);
529void unprotect_jedec(chipaddr bios);
530void protect_jedec(chipaddr bios);
531int write_byte_program_jedec(chipaddr bios, uint8_t *src,
532 chipaddr dst);
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000533int probe_jedec(struct flashchip *flash);
534int erase_chip_jedec(struct flashchip *flash);
535int write_jedec(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000536int erase_sector_jedec(struct flashchip *flash, unsigned int page, int pagesize);
537int erase_block_jedec(struct flashchip *flash, unsigned int page, int blocksize);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000538int write_sector_jedec(chipaddr bios, uint8_t *src,
539 chipaddr dst, unsigned int page_size);
Uwe Hermann0846f892007-08-23 13:34:59 +0000540
Peter Stugeaf8ffac2009-01-26 06:42:02 +0000541/* m29f002.c */
542int erase_m29f002(struct flashchip *flash);
543int write_m29f002t(struct flashchip *flash, uint8_t *buf);
544int write_m29f002b(struct flashchip *flash, uint8_t *buf);
545
Uwe Hermann0846f892007-08-23 13:34:59 +0000546/* m29f400bt.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000547int probe_m29f400bt(struct flashchip *flash);
548int erase_m29f400bt(struct flashchip *flash);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000549int block_erase_m29f400bt(struct flashchip *flash, int start, int len);
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000550int write_m29f400bt(struct flashchip *flash, uint8_t *buf);
Stefan Reinauere3f3e2e2008-01-18 15:33:10 +0000551int write_coreboot_m29f400bt(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000552void toggle_ready_m29f400bt(chipaddr dst);
553void data_polling_m29f400bt(chipaddr dst, uint8_t data);
554void protect_m29f400bt(chipaddr bios);
555void write_page_m29f400bt(chipaddr bios, uint8_t *src,
556 chipaddr dst, int page_size);
Uwe Hermann0846f892007-08-23 13:34:59 +0000557
558/* mx29f002.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000559int probe_29f002(struct flashchip *flash);
560int erase_29f002(struct flashchip *flash);
561int write_29f002(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000562
Nikolay Petukhov4784c472008-05-17 01:08:58 +0000563/* pm49fl00x.c */
564int probe_49fl00x(struct flashchip *flash);
565int erase_49fl00x(struct flashchip *flash);
566int write_49fl00x(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000567
568/* sharplhf00l04.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000569int probe_lhf00l04(struct flashchip *flash);
570int erase_lhf00l04(struct flashchip *flash);
571int write_lhf00l04(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000572void toggle_ready_lhf00l04(chipaddr dst);
573void data_polling_lhf00l04(chipaddr dst, uint8_t data);
574void protect_lhf00l04(chipaddr bios);
Uwe Hermann0846f892007-08-23 13:34:59 +0000575
576/* sst28sf040.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000577int probe_28sf040(struct flashchip *flash);
578int erase_28sf040(struct flashchip *flash);
579int write_28sf040(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000580
581/* sst39sf020.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000582int probe_39sf020(struct flashchip *flash);
583int write_39sf020(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000584
585/* sst49lf040.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000586int erase_49lf040(struct flashchip *flash);
587int write_49lf040(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000588
589/* sst49lfxxxc.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000590int probe_49lfxxxc(struct flashchip *flash);
591int erase_49lfxxxc(struct flashchip *flash);
592int write_49lfxxxc(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000593
594/* sst_fwhub.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000595int probe_sst_fwhub(struct flashchip *flash);
596int erase_sst_fwhub(struct flashchip *flash);
597int write_sst_fwhub(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000598
Peter Stugecce26822008-07-21 17:48:40 +0000599/* w39v040c.c */
600int probe_w39v040c(struct flashchip *flash);
601int erase_w39v040c(struct flashchip *flash);
602int write_w39v040c(struct flashchip *flash, uint8_t *buf);
603
Stefan Reinauerac378972008-03-17 22:59:40 +0000604/* w39V080fa.c */
605int probe_winbond_fwhub(struct flashchip *flash);
606int erase_winbond_fwhub(struct flashchip *flash);
607int write_winbond_fwhub(struct flashchip *flash, uint8_t *buf);
608
Markus Boasd2ac6fc2007-08-30 10:17:50 +0000609/* w29ee011.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000610int probe_w29ee011(struct flashchip *flash);
Markus Boasd2ac6fc2007-08-30 10:17:50 +0000611
Uwe Hermann0846f892007-08-23 13:34:59 +0000612/* w49f002u.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000613int write_49f002(struct flashchip *flash, uint8_t *buf);
Stefan Reinauerff4f1972007-05-24 08:48:10 +0000614
Peter Stugebf196e92009-01-26 03:08:45 +0000615/* wbsio_spi.c */
616int wbsio_check_for_spi(const char *name);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000617int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000618 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000619int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000620int wbsio_spi_write_1(struct flashchip *flash, uint8_t *buf);
Peter Stugebf196e92009-01-26 03:08:45 +0000621
Claus Gindharta7b35512008-04-28 17:51:09 +0000622/* stm50flw0x0x.c */
623int probe_stm50flw0x0x(struct flashchip *flash);
624int erase_stm50flw0x0x(struct flashchip *flash);
625int write_stm50flw0x0x(struct flashchip *flash, uint8_t *buf);
Dominik Geyerb46acba2008-05-16 12:55:55 +0000626
Urja Rannikko22915352009-06-23 11:33:43 +0000627/* serprog.c */
Urja Rannikko22915352009-06-23 11:33:43 +0000628int serprog_init(void);
629int serprog_shutdown(void);
630void serprog_chip_writeb(uint8_t val, chipaddr addr);
631uint8_t serprog_chip_readb(const chipaddr addr);
632void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
633void serprog_delay(int delay);
Uwe Hermann1432a602009-06-28 23:26:37 +0000634
Ollie Lho761bf1b2004-03-20 16:46:10 +0000635#endif /* !__FLASH_H__ */