blob: be95bf94be8cfae99188ace2aefd2bc4b1a3119e [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>
6 * Copyright (C) 2005-2007 coresystems GmbH <stepan@coresystems.de>
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 Hailfinger702218d2009-05-08 17:43:22 +000083extern int programmer;
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +000084#define PROGRAMMER_INTERNAL 0x00
85#define PROGRAMMER_DUMMY 0x01
Uwe Hermannb4dcb712009-05-13 11:36:06 +000086#define PROGRAMMER_NIC3COM 0x02
Rudolf Marek68720c72009-05-17 19:39:27 +000087#define PROGRAMMER_SATASII 0x03
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +000088#define PROGRAMMER_IT87SPI 0x04
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +000089
90struct programmer_entry {
91 const char *vendor;
92 const char *name;
93
94 int (*init) (void);
95 int (*shutdown) (void);
96
Uwe Hermannd1129ac2009-05-28 15:07:42 +000097 void * (*map_flash_region) (const char *descr, unsigned long phys_addr,
98 size_t len);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +000099 void (*unmap_flash_region) (void *virt_addr, size_t len);
100
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000101 void (*chip_writeb) (uint8_t val, chipaddr addr);
102 void (*chip_writew) (uint16_t val, chipaddr addr);
103 void (*chip_writel) (uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000104 void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000105 uint8_t (*chip_readb) (const chipaddr addr);
106 uint16_t (*chip_readw) (const chipaddr addr);
107 uint32_t (*chip_readl) (const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000108 void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000109 void (*delay) (int usecs);
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000110};
111
112extern const struct programmer_entry programmer_table[];
113
Uwe Hermann09e04f72009-05-16 22:36:00 +0000114int programmer_init(void);
115int programmer_shutdown(void);
116void *programmer_map_flash_region(const char *descr, unsigned long phys_addr,
117 size_t len);
118void programmer_unmap_flash_region(void *virt_addr, size_t len);
119void chip_writeb(uint8_t val, chipaddr addr);
120void chip_writew(uint16_t val, chipaddr addr);
121void chip_writel(uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000122void chip_writen(uint8_t *buf, chipaddr addr, size_t len);
Uwe Hermann09e04f72009-05-16 22:36:00 +0000123uint8_t chip_readb(const chipaddr addr);
124uint16_t chip_readw(const chipaddr addr);
125uint32_t chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000126void chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000127void programmer_delay(int usecs);
Carl-Daniel Hailfinger61a8bd22009-03-05 19:24:22 +0000128
Uwe Hermanne5ac1642008-03-12 11:54:51 +0000129#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
130
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000131enum chipbustype {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000132 CHIP_BUSTYPE_NONE = 0,
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000133 CHIP_BUSTYPE_PARALLEL = 1 << 0,
134 CHIP_BUSTYPE_LPC = 1 << 1,
135 CHIP_BUSTYPE_FWH = 1 << 2,
136 CHIP_BUSTYPE_SPI = 1 << 3,
137 CHIP_BUSTYPE_NONSPI = CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH,
138 CHIP_BUSTYPE_UNKNOWN = CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI,
139};
140
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000141struct flashchip {
Uwe Hermann76158682008-03-14 23:55:58 +0000142 const char *vendor;
Uwe Hermann372eeb52007-12-04 21:49:06 +0000143 const char *name;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000144
145 enum chipbustype bustype;
146
Uwe Hermann394131e2008-10-18 21:14:13 +0000147 /*
148 * With 32bit manufacture_id and model_id we can cover IDs up to
Carl-Daniel Hailfingerae8afa92007-12-31 01:49:00 +0000149 * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's
150 * Identification code.
151 */
152 uint32_t manufacture_id;
153 uint32_t model_id;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000154
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000155 int total_size;
156 int page_size;
157
Uwe Hermann394131e2008-10-18 21:14:13 +0000158 /*
159 * Indicate if flashrom has been tested with this flash chip and if
Peter Stuge1159d582008-05-03 04:34:37 +0000160 * everything worked correctly.
161 */
162 uint32_t tested;
163
Uwe Hermann0b7afe62007-04-01 19:44:21 +0000164 int (*probe) (struct flashchip *flash);
Maciej Pijankac6e11112009-06-03 14:46:22 +0000165
166 /* Delay after "enter/exit ID mode" commands in microseconds. */
167 int probe_timing;
Uwe Hermann0b7afe62007-04-01 19:44:21 +0000168 int (*erase) (struct flashchip *flash);
169 int (*write) (struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000170 int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000171
Uwe Hermann372eeb52007-12-04 21:49:06 +0000172 /* Some flash devices have an additional register space. */
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000173 chipaddr virtual_memory;
174 chipaddr virtual_registers;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000175};
176
Peter Stuge1159d582008-05-03 04:34:37 +0000177#define TEST_UNTESTED 0
178
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000179#define TEST_OK_PROBE (1 << 0)
180#define TEST_OK_READ (1 << 1)
181#define TEST_OK_ERASE (1 << 2)
182#define TEST_OK_WRITE (1 << 3)
183#define TEST_OK_PR (TEST_OK_PROBE | TEST_OK_READ)
184#define TEST_OK_PRE (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE)
185#define TEST_OK_PREW (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_WRITE)
Peter Stuge1159d582008-05-03 04:34:37 +0000186#define TEST_OK_MASK 0x0f
187
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000188#define TEST_BAD_PROBE (1 << 4)
189#define TEST_BAD_READ (1 << 5)
190#define TEST_BAD_ERASE (1 << 6)
191#define TEST_BAD_WRITE (1 << 7)
192#define TEST_BAD_PREW (TEST_BAD_PROBE | TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE)
Peter Stuge1159d582008-05-03 04:34:37 +0000193#define TEST_BAD_MASK 0xf0
194
Maciej Pijankac6e11112009-06-03 14:46:22 +0000195/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
196 * field and zero delay.
197 *
198 * SPI devices will always have zero delay and ignore this field.
199 */
200#define TIMING_FIXME -1
201/* this is intentionally same value as fixme */
202#define TIMING_IGNORED -1
203#define TIMING_ZERO -2
204
Ollie Lho184a4042005-11-26 21:55:36 +0000205extern struct flashchip flashchips[];
206
Uwe Hermann05fab752009-05-16 23:42:17 +0000207struct penable {
208 uint16_t vendor_id;
209 uint16_t device_id;
210 int status;
211 const char *vendor_name;
212 const char *device_name;
213 int (*doit) (struct pci_dev *dev, const char *name);
214};
215
216extern const struct penable chipset_enables[];
217
218struct board_pciid_enable {
219 /* Any device, but make it sensible, like the ISA bridge. */
220 uint16_t first_vendor;
221 uint16_t first_device;
222 uint16_t first_card_vendor;
223 uint16_t first_card_device;
224
225 /* Any device, but make it sensible, like
226 * the host bridge. May be NULL.
227 */
228 uint16_t second_vendor;
229 uint16_t second_device;
230 uint16_t second_card_vendor;
231 uint16_t second_card_device;
232
233 /* The vendor / part name from the coreboot table. */
234 const char *lb_vendor;
235 const char *lb_part;
236
237 const char *vendor_name;
238 const char *board_name;
239
240 int (*enable) (const char *name);
241};
242
243extern struct board_pciid_enable board_pciid_enables[];
244
245struct board_info {
246 const char *vendor;
247 const char *name;
248};
249
250extern const struct board_info boards_ok[];
251extern const struct board_info boards_bad[];
252
Uwe Hermann372eeb52007-12-04 21:49:06 +0000253/* udelay.c */
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000254void myusec_delay(int usecs);
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000255void myusec_calibrate_delay(void);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000256
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000257/* pcidev.c */
258#define PCI_OK 0
259#define PCI_NT 1 /* Not tested */
Rudolf Marek68720c72009-05-17 19:39:27 +0000260
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000261extern uint32_t io_base_addr;
262extern struct pci_access *pacc;
263extern struct pci_filter filter;
Uwe Hermann8403ccb2009-05-16 21:39:19 +0000264extern struct pci_dev *pcidev_dev;
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000265struct pcidev_status {
266 uint16_t vendor_id;
267 uint16_t device_id;
268 int status;
269 const char *vendor_name;
270 const char *device_name;
271};
272uint32_t pcidev_validate(struct pci_dev *dev, struct pcidev_status *devs);
273uint32_t pcidev_init(uint16_t vendor_id, struct pcidev_status *devs);
274void print_supported_pcidevs(struct pcidev_status *devs);
275
Uwe Hermann372eeb52007-12-04 21:49:06 +0000276/* board_enable.c */
Peter Stuge9d9399c2009-01-26 02:34:51 +0000277void w836xx_ext_enter(uint16_t port);
278void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +0000279uint8_t sio_read(uint16_t port, uint8_t reg);
280void sio_write(uint16_t port, uint8_t reg, uint8_t data);
281void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Uwe Hermann372eeb52007-12-04 21:49:06 +0000282int board_flash_enable(const char *vendor, const char *part);
Uwe Hermanne5ac1642008-03-12 11:54:51 +0000283void print_supported_boards(void);
Adam Kaufman064b1f22007-02-06 19:47:50 +0000284
Uwe Hermann372eeb52007-12-04 21:49:06 +0000285/* chipset_enable.c */
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000286extern enum chipbustype buses_supported;
Uwe Hermann372eeb52007-12-04 21:49:06 +0000287int chipset_flash_enable(void);
Uwe Hermanne5ac1642008-03-12 11:54:51 +0000288void print_supported_chipsets(void);
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000289
Stefan Reinauer9a6d1762008-12-03 21:24:40 +0000290extern unsigned long flashbase;
291
Stefan Reinauer0593f212009-01-26 01:10:48 +0000292/* physmap.c */
293void *physmap(const char *descr, unsigned long phys_addr, size_t len);
294void physunmap(void *virt_addr, size_t len);
295
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000296/* internal.c */
Uwe Hermann2cac6862009-05-16 22:05:42 +0000297struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
298struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
299struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
300 uint16_t card_vendor, uint16_t card_device);
Carl-Daniel Hailfinger3b7e75a2009-05-14 21:41:10 +0000301void get_io_perms(void);
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000302int internal_init(void);
303int internal_shutdown(void);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000304void internal_chip_writeb(uint8_t val, chipaddr addr);
305void internal_chip_writew(uint16_t val, chipaddr addr);
306void internal_chip_writel(uint32_t val, chipaddr addr);
307uint8_t internal_chip_readb(const chipaddr addr);
308uint16_t internal_chip_readw(const chipaddr addr);
309uint32_t internal_chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000310void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000311void mmio_writeb(uint8_t val, void *addr);
312void mmio_writew(uint16_t val, void *addr);
313void mmio_writel(uint32_t val, void *addr);
314uint8_t mmio_readb(void *addr);
315uint16_t mmio_readw(void *addr);
316uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000317void internal_delay(int usecs);
Uwe Hermannc6915932009-05-17 23:12:17 +0000318void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
319void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000320void fallback_chip_writew(uint16_t val, chipaddr addr);
321void fallback_chip_writel(uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000322void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000323uint16_t fallback_chip_readw(const chipaddr addr);
324uint32_t fallback_chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000325void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Uwe Hermanna0869322009-05-14 20:41:57 +0000326#if defined(__FreeBSD__) || defined(__DragonFly__)
327extern int io_fd;
328#endif
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000329
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000330/* dummyflasher.c */
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000331extern char *dummytype;
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000332int dummy_init(void);
333int dummy_shutdown(void);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000334void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
335void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000336void dummy_chip_writeb(uint8_t val, chipaddr addr);
337void dummy_chip_writew(uint16_t val, chipaddr addr);
338void dummy_chip_writel(uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000339void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000340uint8_t dummy_chip_readb(const chipaddr addr);
341uint16_t dummy_chip_readw(const chipaddr addr);
342uint32_t dummy_chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000343void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000344int dummy_spi_command(unsigned int writecnt, unsigned int readcnt,
345 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000346
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000347/* nic3com.c */
348int nic3com_init(void);
349int nic3com_shutdown(void);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000350void nic3com_chip_writeb(uint8_t val, chipaddr addr);
351uint8_t nic3com_chip_readb(const chipaddr addr);
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000352extern struct pcidev_status nics_3com[];
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000353
Rudolf Marek68720c72009-05-17 19:39:27 +0000354/* satasii.c */
355int satasii_init(void);
356int satasii_shutdown(void);
Rudolf Marek68720c72009-05-17 19:39:27 +0000357void satasii_chip_writeb(uint8_t val, chipaddr addr);
358uint8_t satasii_chip_readb(const chipaddr addr);
359extern struct pcidev_status satas_sii[];
360
Uwe Hermann0846f892007-08-23 13:34:59 +0000361/* flashrom.c */
Uwe Hermannad216bf2009-04-24 16:17:41 +0000362extern int verbose;
363#define printf_debug(x...) { if (verbose) printf(x); }
Peter Stuge776d2022009-01-26 00:39:57 +0000364void map_flash_registers(struct flashchip *flash);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000365int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger38a059d2009-06-13 12:04:03 +0000366int min(int a, int b);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000367int max(int a, int b);
368int check_erased_range(struct flashchip *flash, int start, int len);
369int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message);
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000370extern char *pcidev_bdf;
Uwe Hermann0846f892007-08-23 13:34:59 +0000371
372/* layout.c */
Peter Stuge7ffbc6f2008-06-18 02:08:40 +0000373int show_id(uint8_t *bios, int size, int force);
Uwe Hermann0846f892007-08-23 13:34:59 +0000374int read_romlayout(char *name);
375int find_romentry(char *name);
376int handle_romentries(uint8_t *buffer, uint8_t *content);
377
Uwe Hermannad216bf2009-04-24 16:17:41 +0000378/* cbtable.c */
Stefan Reinauere3f3e2e2008-01-18 15:33:10 +0000379int coreboot_init(void);
Uwe Hermann0846f892007-08-23 13:34:59 +0000380extern char *lb_part, *lb_vendor;
381
Carl-Daniel Hailfinger00f911e2007-10-15 21:44:47 +0000382/* spi.c */
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000383enum spi_controller {
384 SPI_CONTROLLER_NONE,
385 SPI_CONTROLLER_ICH7,
386 SPI_CONTROLLER_ICH9,
387 SPI_CONTROLLER_IT87XX,
388 SPI_CONTROLLER_SB600,
389 SPI_CONTROLLER_VIA,
390 SPI_CONTROLLER_WBSIO,
391 SPI_CONTROLLER_DUMMY,
392};
393extern enum spi_controller spi_controller;
394extern void *spibar;
Carl-Daniel Hailfinger42c54972008-05-15 03:19:49 +0000395int probe_spi_rdid(struct flashchip *flash);
Rudolf Marek48a85e42008-06-30 21:45:17 +0000396int probe_spi_rdid4(struct flashchip *flash);
Carl-Daniel Hailfinger14e50ac2008-11-28 01:25:00 +0000397int probe_spi_rems(struct flashchip *flash);
Carl-Daniel Hailfinger42c54972008-05-15 03:19:49 +0000398int probe_spi_res(struct flashchip *flash);
Uwe Hermann394131e2008-10-18 21:14:13 +0000399int spi_command(unsigned int writecnt, unsigned int readcnt,
400 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000401int spi_write_enable(void);
402int spi_write_disable(void);
Carl-Daniel Hailfinger6afb6132008-11-03 00:02:11 +0000403int spi_chip_erase_60(struct flashchip *flash);
Peter Stugefa8c5502008-05-10 23:07:52 +0000404int spi_chip_erase_c7(struct flashchip *flash);
Carl-Daniel Hailfinger598ec582008-11-18 00:41:02 +0000405int spi_chip_erase_60_c7(struct flashchip *flash);
Stefan Reinauer424ed222008-10-29 22:13:20 +0000406int spi_chip_erase_d8(struct flashchip *flash);
Carl-Daniel Hailfinger6afb6132008-11-03 00:02:11 +0000407int spi_block_erase_52(const struct flashchip *flash, unsigned long addr);
408int spi_block_erase_d8(const struct flashchip *flash, unsigned long addr);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000409int spi_chip_write_1(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger8d497012009-05-09 02:34:18 +0000410int spi_chip_write_256(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000411int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000412uint8_t spi_read_status_register(void);
Carl-Daniel Hailfinger598ec582008-11-18 00:41:02 +0000413int spi_disable_blockprotect(void);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000414void spi_byte_program(int address, uint8_t byte);
Paul Foxeb3acef2009-06-12 08:10:33 +0000415int spi_nbyte_program(int address, uint8_t *bytes, int len);
Carl-Daniel Hailfinger598ec582008-11-18 00:41:02 +0000416int spi_nbyte_read(int address, uint8_t *bytes, int len);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000417int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize);
Peter Stugefd9217d2009-01-26 03:37:40 +0000418int spi_aai_write(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger3e9dbea2009-05-13 11:40:08 +0000419uint32_t spi_get_valid_read_addr(void);
Carl-Daniel Hailfingere1514992007-10-02 15:49:25 +0000420
Uwe Hermann0846f892007-08-23 13:34:59 +0000421/* 82802ab.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000422int probe_82802ab(struct flashchip *flash);
423int erase_82802ab(struct flashchip *flash);
424int write_82802ab(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000425
426/* am29f040b.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000427int probe_29f040b(struct flashchip *flash);
428int erase_29f040b(struct flashchip *flash);
429int write_29f040b(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000430
Uwe Hermannf983d9f2009-06-14 21:53:26 +0000431/* pm29f002.c */
432int write_pm29f002(struct flashchip *flash, uint8_t *buf);
433
Mats Erik Andersson44e1a192008-09-26 13:19:02 +0000434/* en29f002a.c */
435int probe_en29f002a(struct flashchip *flash);
436int erase_en29f002a(struct flashchip *flash);
437int write_en29f002a(struct flashchip *flash, uint8_t *buf);
438
Dominik Geyerb46acba2008-05-16 12:55:55 +0000439/* ichspi.c */
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000440int ich_init_opcodes(void);
Uwe Hermann394131e2008-10-18 21:14:13 +0000441int ich_spi_command(unsigned int writecnt, unsigned int readcnt,
442 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000443int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000444int ich_spi_write_256(struct flashchip *flash, uint8_t * buf);
Dominik Geyerb46acba2008-05-16 12:55:55 +0000445
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000446/* it87spi.c */
447extern uint16_t it8716f_flashport;
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +0000448void enter_conf_mode_ite(uint16_t port);
449void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000450int it87spi_init(void);
Dominik Geyerb46acba2008-05-16 12:55:55 +0000451int it87xx_probe_spi_flash(const char *name);
Uwe Hermann394131e2008-10-18 21:14:13 +0000452int it8716f_spi_command(unsigned int writecnt, unsigned int readcnt,
453 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000454int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000455int it8716f_spi_chip_write_1(struct flashchip *flash, uint8_t *buf);
456int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000457
Jason Wanga3f04be2008-11-28 21:36:51 +0000458/* sb600spi.c */
459int sb600_spi_command(unsigned int writecnt, unsigned int readcnt,
460 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000461int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000462int sb600_spi_write_1(struct flashchip *flash, uint8_t *buf);
Jason Wanga3f04be2008-11-28 21:36:51 +0000463uint8_t sb600_read_status_register(void);
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000464extern uint8_t *sb600_spibar;
Jason Wanga3f04be2008-11-28 21:36:51 +0000465
Uwe Hermann0846f892007-08-23 13:34:59 +0000466/* jedec.c */
Carl-Daniel Hailfingera758f512008-05-14 12:03:06 +0000467uint8_t oddparity(uint8_t val);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000468void toggle_ready_jedec(chipaddr dst);
469void data_polling_jedec(chipaddr dst, uint8_t data);
470void unprotect_jedec(chipaddr bios);
471void protect_jedec(chipaddr bios);
472int write_byte_program_jedec(chipaddr bios, uint8_t *src,
473 chipaddr dst);
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000474int probe_jedec(struct flashchip *flash);
475int erase_chip_jedec(struct flashchip *flash);
476int write_jedec(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000477int erase_sector_jedec(struct flashchip *flash, unsigned int page, int pagesize);
478int erase_block_jedec(struct flashchip *flash, unsigned int page, int blocksize);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000479int write_sector_jedec(chipaddr bios, uint8_t *src,
480 chipaddr dst, unsigned int page_size);
Uwe Hermann0846f892007-08-23 13:34:59 +0000481
Peter Stugeaf8ffac2009-01-26 06:42:02 +0000482/* m29f002.c */
483int erase_m29f002(struct flashchip *flash);
484int write_m29f002t(struct flashchip *flash, uint8_t *buf);
485int write_m29f002b(struct flashchip *flash, uint8_t *buf);
486
Uwe Hermann0846f892007-08-23 13:34:59 +0000487/* m29f400bt.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000488int probe_m29f400bt(struct flashchip *flash);
489int erase_m29f400bt(struct flashchip *flash);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000490int block_erase_m29f400bt(struct flashchip *flash, int start, int len);
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000491int write_m29f400bt(struct flashchip *flash, uint8_t *buf);
Stefan Reinauere3f3e2e2008-01-18 15:33:10 +0000492int write_coreboot_m29f400bt(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000493void toggle_ready_m29f400bt(chipaddr dst);
494void data_polling_m29f400bt(chipaddr dst, uint8_t data);
495void protect_m29f400bt(chipaddr bios);
496void write_page_m29f400bt(chipaddr bios, uint8_t *src,
497 chipaddr dst, int page_size);
Uwe Hermann0846f892007-08-23 13:34:59 +0000498
499/* mx29f002.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000500int probe_29f002(struct flashchip *flash);
501int erase_29f002(struct flashchip *flash);
502int write_29f002(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000503
Nikolay Petukhov4784c472008-05-17 01:08:58 +0000504/* pm49fl00x.c */
505int probe_49fl00x(struct flashchip *flash);
506int erase_49fl00x(struct flashchip *flash);
507int write_49fl00x(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000508
509/* sharplhf00l04.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000510int probe_lhf00l04(struct flashchip *flash);
511int erase_lhf00l04(struct flashchip *flash);
512int write_lhf00l04(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000513void toggle_ready_lhf00l04(chipaddr dst);
514void data_polling_lhf00l04(chipaddr dst, uint8_t data);
515void protect_lhf00l04(chipaddr bios);
Uwe Hermann0846f892007-08-23 13:34:59 +0000516
517/* sst28sf040.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000518int probe_28sf040(struct flashchip *flash);
519int erase_28sf040(struct flashchip *flash);
520int write_28sf040(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000521
522/* sst39sf020.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000523int probe_39sf020(struct flashchip *flash);
524int write_39sf020(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000525
526/* sst49lf040.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000527int erase_49lf040(struct flashchip *flash);
528int write_49lf040(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000529
530/* sst49lfxxxc.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000531int probe_49lfxxxc(struct flashchip *flash);
532int erase_49lfxxxc(struct flashchip *flash);
533int write_49lfxxxc(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000534
535/* sst_fwhub.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000536int probe_sst_fwhub(struct flashchip *flash);
537int erase_sst_fwhub(struct flashchip *flash);
538int write_sst_fwhub(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000539
Peter Stugecce26822008-07-21 17:48:40 +0000540/* w39v040c.c */
541int probe_w39v040c(struct flashchip *flash);
542int erase_w39v040c(struct flashchip *flash);
543int write_w39v040c(struct flashchip *flash, uint8_t *buf);
544
Stefan Reinauerac378972008-03-17 22:59:40 +0000545/* w39V080fa.c */
546int probe_winbond_fwhub(struct flashchip *flash);
547int erase_winbond_fwhub(struct flashchip *flash);
548int write_winbond_fwhub(struct flashchip *flash, uint8_t *buf);
549
Markus Boasd2ac6fc2007-08-30 10:17:50 +0000550/* w29ee011.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000551int probe_w29ee011(struct flashchip *flash);
Markus Boasd2ac6fc2007-08-30 10:17:50 +0000552
Uwe Hermann0846f892007-08-23 13:34:59 +0000553/* w49f002u.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000554int write_49f002(struct flashchip *flash, uint8_t *buf);
Stefan Reinauerff4f1972007-05-24 08:48:10 +0000555
Peter Stugebf196e92009-01-26 03:08:45 +0000556/* wbsio_spi.c */
557int wbsio_check_for_spi(const char *name);
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000558int wbsio_spi_command(unsigned int writecnt, unsigned int readcnt,
559 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000560int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000561int wbsio_spi_write_1(struct flashchip *flash, uint8_t *buf);
Peter Stugebf196e92009-01-26 03:08:45 +0000562
Claus Gindharta7b35512008-04-28 17:51:09 +0000563/* stm50flw0x0x.c */
564int probe_stm50flw0x0x(struct flashchip *flash);
565int erase_stm50flw0x0x(struct flashchip *flash);
566int write_stm50flw0x0x(struct flashchip *flash, uint8_t *buf);
Dominik Geyerb46acba2008-05-16 12:55:55 +0000567
Ollie Lho761bf1b2004-03-20 16:46:10 +0000568#endif /* !__FLASH_H__ */