blob: b271b8ac0853ec8bc1013ea7ca210c1698c2589b [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,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +000085#if DUMMY_SUPPORT == 1
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +000086 PROGRAMMER_DUMMY,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +000087#endif
88#if NIC3COM_SUPPORT == 1
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +000089 PROGRAMMER_NIC3COM,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +000090#endif
Uwe Hermann2bc98f62009-09-30 18:29:55 +000091#if GFXNVIDIA_SUPPORT == 1
92 PROGRAMMER_GFXNVIDIA,
93#endif
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +000094#if DRKAISER_SUPPORT == 1
TURBO Jb0912c02009-09-02 23:00:46 +000095 PROGRAMMER_DRKAISER,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +000096#endif
97#if SATASII_SUPPORT == 1
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +000098 PROGRAMMER_SATASII,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +000099#endif
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +0000100 PROGRAMMER_IT87SPI,
Carl-Daniel Hailfinger3426ef62009-08-19 13:27:58 +0000101#if FT2232_SPI_SUPPORT == 1
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +0000102 PROGRAMMER_FT2232SPI,
Carl-Daniel Hailfinger3426ef62009-08-19 13:27:58 +0000103#endif
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000104#if SERPROG_SUPPORT == 1
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +0000105 PROGRAMMER_SERPROG,
Carl-Daniel Hailfinger6be74112009-08-12 16:17:41 +0000106#endif
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000107#if BUSPIRATE_SPI_SUPPORT == 1
108 PROGRAMMER_BUSPIRATESPI,
109#endif
Carl-Daniel Hailfinger37fc4692009-08-12 14:34:35 +0000110 PROGRAMMER_INVALID /* This must always be the last entry. */
Carl-Daniel Hailfinger415e5132009-08-12 11:39:29 +0000111};
112
113extern enum programmer programmer;
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000114
115struct programmer_entry {
116 const char *vendor;
117 const char *name;
118
119 int (*init) (void);
120 int (*shutdown) (void);
121
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000122 void * (*map_flash_region) (const char *descr, unsigned long phys_addr,
123 size_t len);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000124 void (*unmap_flash_region) (void *virt_addr, size_t len);
125
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000126 void (*chip_writeb) (uint8_t val, chipaddr addr);
127 void (*chip_writew) (uint16_t val, chipaddr addr);
128 void (*chip_writel) (uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000129 void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000130 uint8_t (*chip_readb) (const chipaddr addr);
131 uint16_t (*chip_readw) (const chipaddr addr);
132 uint32_t (*chip_readl) (const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000133 void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000134 void (*delay) (int usecs);
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000135};
136
137extern const struct programmer_entry programmer_table[];
138
Uwe Hermann09e04f72009-05-16 22:36:00 +0000139int programmer_init(void);
140int programmer_shutdown(void);
141void *programmer_map_flash_region(const char *descr, unsigned long phys_addr,
142 size_t len);
143void programmer_unmap_flash_region(void *virt_addr, size_t len);
144void chip_writeb(uint8_t val, chipaddr addr);
145void chip_writew(uint16_t val, chipaddr addr);
146void chip_writel(uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000147void chip_writen(uint8_t *buf, chipaddr addr, size_t len);
Uwe Hermann09e04f72009-05-16 22:36:00 +0000148uint8_t chip_readb(const chipaddr addr);
149uint16_t chip_readw(const chipaddr addr);
150uint32_t chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000151void chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000152void programmer_delay(int usecs);
Carl-Daniel Hailfinger61a8bd22009-03-05 19:24:22 +0000153
Carl-Daniel Hailfinger3a4781e2009-10-01 14:51:25 +0000154enum bitbang_spi_master {
155 BITBANG_SPI_INVALID /* This must always be the last entry. */
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000156};
157
Carl-Daniel Hailfinger3a4781e2009-10-01 14:51:25 +0000158extern const int bitbang_spi_master_count;
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000159
Carl-Daniel Hailfinger3a4781e2009-10-01 14:51:25 +0000160extern enum bitbang_spi_master bitbang_spi_master;
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000161
Carl-Daniel Hailfinger3a4781e2009-10-01 14:51:25 +0000162struct bitbang_spi_master_entry {
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000163 void (*set_cs) (int val);
164 void (*set_sck) (int val);
165 void (*set_mosi) (int val);
166 int (*get_miso) (void);
167};
168
Uwe Hermanne5ac1642008-03-12 11:54:51 +0000169#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
170
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000171enum chipbustype {
Carl-Daniel Hailfinger3504b532009-06-01 00:02:11 +0000172 CHIP_BUSTYPE_NONE = 0,
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000173 CHIP_BUSTYPE_PARALLEL = 1 << 0,
174 CHIP_BUSTYPE_LPC = 1 << 1,
175 CHIP_BUSTYPE_FWH = 1 << 2,
176 CHIP_BUSTYPE_SPI = 1 << 3,
177 CHIP_BUSTYPE_NONSPI = CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH,
178 CHIP_BUSTYPE_UNKNOWN = CHIP_BUSTYPE_PARALLEL | CHIP_BUSTYPE_LPC | CHIP_BUSTYPE_FWH | CHIP_BUSTYPE_SPI,
179};
180
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +0000181/*
182 * How many different contiguous runs of erase blocks with one size each do
183 * we have for a given erase function?
184 */
185#define NUM_ERASEREGIONS 5
186
187/*
188 * How many different erase functions do we have per chip?
189 */
190#define NUM_ERASEFUNCTIONS 5
191
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000192struct flashchip {
Uwe Hermann76158682008-03-14 23:55:58 +0000193 const char *vendor;
Uwe Hermann372eeb52007-12-04 21:49:06 +0000194 const char *name;
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000195
196 enum chipbustype bustype;
197
Uwe Hermann394131e2008-10-18 21:14:13 +0000198 /*
199 * With 32bit manufacture_id and model_id we can cover IDs up to
Carl-Daniel Hailfingerae8afa92007-12-31 01:49:00 +0000200 * (including) the 4th bank of JEDEC JEP106W Standard Manufacturer's
201 * Identification code.
202 */
203 uint32_t manufacture_id;
204 uint32_t model_id;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000205
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000206 int total_size;
207 int page_size;
208
Uwe Hermann394131e2008-10-18 21:14:13 +0000209 /*
210 * Indicate if flashrom has been tested with this flash chip and if
Peter Stuge1159d582008-05-03 04:34:37 +0000211 * everything worked correctly.
212 */
213 uint32_t tested;
214
Uwe Hermann0b7afe62007-04-01 19:44:21 +0000215 int (*probe) (struct flashchip *flash);
Maciej Pijankac6e11112009-06-03 14:46:22 +0000216
217 /* Delay after "enter/exit ID mode" commands in microseconds. */
218 int probe_timing;
Uwe Hermann0b7afe62007-04-01 19:44:21 +0000219 int (*erase) (struct flashchip *flash);
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +0000220
221 /*
222 * Erase blocks and associated erase function. The default entry is a
223 * chip-sized virtual block together with the chip erase function.
224 */
225 struct block_eraser {
226 struct eraseblock{
227 unsigned int size; /* Eraseblock size */
228 unsigned int count; /* Number of contiguous blocks with that size */
229 } eraseblocks[NUM_ERASEREGIONS];
230 int (*block_erase) (struct flashchip *flash, unsigned int blockaddr, unsigned int blocklen);
231 } block_erasers[NUM_ERASEFUNCTIONS];
232
Uwe Hermann0b7afe62007-04-01 19:44:21 +0000233 int (*write) (struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000234 int (*read) (struct flashchip *flash, uint8_t *buf, int start, int len);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +0000235
Uwe Hermann372eeb52007-12-04 21:49:06 +0000236 /* Some flash devices have an additional register space. */
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000237 chipaddr virtual_memory;
238 chipaddr virtual_registers;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +0000239};
240
Peter Stuge1159d582008-05-03 04:34:37 +0000241#define TEST_UNTESTED 0
242
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000243#define TEST_OK_PROBE (1 << 0)
244#define TEST_OK_READ (1 << 1)
245#define TEST_OK_ERASE (1 << 2)
246#define TEST_OK_WRITE (1 << 3)
247#define TEST_OK_PR (TEST_OK_PROBE | TEST_OK_READ)
248#define TEST_OK_PRE (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE)
Carl-Daniel Hailfingera06287c2009-09-23 22:01:33 +0000249#define TEST_OK_PRW (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_WRITE)
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000250#define TEST_OK_PREW (TEST_OK_PROBE | TEST_OK_READ | TEST_OK_ERASE | TEST_OK_WRITE)
Peter Stuge1159d582008-05-03 04:34:37 +0000251#define TEST_OK_MASK 0x0f
252
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000253#define TEST_BAD_PROBE (1 << 4)
254#define TEST_BAD_READ (1 << 5)
255#define TEST_BAD_ERASE (1 << 6)
256#define TEST_BAD_WRITE (1 << 7)
257#define TEST_BAD_PREW (TEST_BAD_PROBE | TEST_BAD_READ | TEST_BAD_ERASE | TEST_BAD_WRITE)
Peter Stuge1159d582008-05-03 04:34:37 +0000258#define TEST_BAD_MASK 0xf0
259
Maciej Pijankac6e11112009-06-03 14:46:22 +0000260/* Timing used in probe routines. ZERO is -2 to differentiate between an unset
261 * field and zero delay.
262 *
263 * SPI devices will always have zero delay and ignore this field.
264 */
265#define TIMING_FIXME -1
266/* this is intentionally same value as fixme */
267#define TIMING_IGNORED -1
268#define TIMING_ZERO -2
269
Ollie Lho184a4042005-11-26 21:55:36 +0000270extern struct flashchip flashchips[];
271
Uwe Hermann05fab752009-05-16 23:42:17 +0000272struct penable {
273 uint16_t vendor_id;
274 uint16_t device_id;
275 int status;
276 const char *vendor_name;
277 const char *device_name;
278 int (*doit) (struct pci_dev *dev, const char *name);
279};
280
281extern const struct penable chipset_enables[];
282
283struct board_pciid_enable {
284 /* Any device, but make it sensible, like the ISA bridge. */
285 uint16_t first_vendor;
286 uint16_t first_device;
287 uint16_t first_card_vendor;
288 uint16_t first_card_device;
289
290 /* Any device, but make it sensible, like
291 * the host bridge. May be NULL.
292 */
293 uint16_t second_vendor;
294 uint16_t second_device;
295 uint16_t second_card_vendor;
296 uint16_t second_card_device;
297
298 /* The vendor / part name from the coreboot table. */
299 const char *lb_vendor;
300 const char *lb_part;
301
302 const char *vendor_name;
303 const char *board_name;
304
305 int (*enable) (const char *name);
306};
307
308extern struct board_pciid_enable board_pciid_enables[];
309
310struct board_info {
311 const char *vendor;
312 const char *name;
313};
314
315extern const struct board_info boards_ok[];
316extern const struct board_info boards_bad[];
Uwe Hermanne1aa75e2009-06-18 14:04:44 +0000317extern const struct board_info laptops_ok[];
318extern const struct board_info laptops_bad[];
Uwe Hermann05fab752009-05-16 23:42:17 +0000319
Uwe Hermann372eeb52007-12-04 21:49:06 +0000320/* udelay.c */
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000321void myusec_delay(int usecs);
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000322void myusec_calibrate_delay(void);
Luc Verhaegen8e3a6002007-04-04 22:45:58 +0000323
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000324/* pcidev.c */
325#define PCI_OK 0
326#define PCI_NT 1 /* Not tested */
Rudolf Marek68720c72009-05-17 19:39:27 +0000327
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000328extern uint32_t io_base_addr;
329extern struct pci_access *pacc;
330extern struct pci_filter filter;
Uwe Hermann8403ccb2009-05-16 21:39:19 +0000331extern struct pci_dev *pcidev_dev;
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000332struct pcidev_status {
333 uint16_t vendor_id;
334 uint16_t device_id;
335 int status;
336 const char *vendor_name;
337 const char *device_name;
338};
TURBO Jb0912c02009-09-02 23:00:46 +0000339uint32_t pcidev_validate(struct pci_dev *dev, uint32_t bar, struct pcidev_status *devs);
340uint32_t pcidev_init(uint16_t vendor_id, uint32_t bar, struct pcidev_status *devs, char *pcidev_bdf);
Uwe Hermannba290d12009-06-17 12:07:12 +0000341
342/* print.c */
343char *flashbuses_to_text(enum chipbustype bustype);
Carl-Daniel Hailfingerf5292052009-11-17 09:57:34 +0000344void print_supported(void);
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000345void print_supported_pcidevs(struct pcidev_status *devs);
Carl-Daniel Hailfingerf5292052009-11-17 09:57:34 +0000346void print_supported_wiki(void);
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000347
Uwe Hermann372eeb52007-12-04 21:49:06 +0000348/* board_enable.c */
Peter Stuge9d9399c2009-01-26 02:34:51 +0000349void w836xx_ext_enter(uint16_t port);
350void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +0000351uint8_t sio_read(uint16_t port, uint8_t reg);
352void sio_write(uint16_t port, uint8_t reg, uint8_t data);
353void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Uwe Hermann372eeb52007-12-04 21:49:06 +0000354int board_flash_enable(const char *vendor, const char *part);
Adam Kaufman064b1f22007-02-06 19:47:50 +0000355
Carl-Daniel Hailfinger115d3902009-10-31 01:53:09 +0000356struct decode_sizes {
357 uint32_t parallel;
358 uint32_t lpc;
359 uint32_t fwh;
360 uint32_t spi;
361};
362
Uwe Hermann372eeb52007-12-04 21:49:06 +0000363/* chipset_enable.c */
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000364extern enum chipbustype buses_supported;
Uwe Hermann372eeb52007-12-04 21:49:06 +0000365int chipset_flash_enable(void);
Carl-Daniel Hailfinger115d3902009-10-31 01:53:09 +0000366extern struct decode_sizes max_rom_decode;
Stefan Reinauer2cb94e12008-06-30 23:45:22 +0000367
Stefan Reinauer9a6d1762008-12-03 21:24:40 +0000368extern unsigned long flashbase;
369
Stefan Reinauer0593f212009-01-26 01:10:48 +0000370/* physmap.c */
371void *physmap(const char *descr, unsigned long phys_addr, size_t len);
372void physunmap(void *virt_addr, size_t len);
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000373int setup_cpu_msr(int cpu);
374void cleanup_cpu_msr(void);
Stefan Reinauer173e3ea2009-08-19 10:46:23 +0000375#if !defined(__DARWIN__) && !defined(__FreeBSD__) && !defined(__DragonFly__)
Stefan Reinauer8fa64812009-08-12 09:27:45 +0000376typedef struct { uint32_t hi, lo; } msr_t;
377msr_t rdmsr(int addr);
378int wrmsr(int addr, msr_t msr);
379#endif
Stefan Reinauer173e3ea2009-08-19 10:46:23 +0000380#if defined(__FreeBSD__) || defined(__DragonFly__)
381/* FreeBSD already has conflicting definitions for wrmsr/rdmsr. */
382#undef rdmsr
383#undef wrmsr
384#define rdmsr freebsd_rdmsr
385#define wrmsr freebsd_wrmsr
386typedef struct { uint32_t hi, lo; } msr_t;
387msr_t freebsd_rdmsr(int addr);
388int freebsd_wrmsr(int addr, msr_t msr);
389#endif
Stefan Reinauer0593f212009-01-26 01:10:48 +0000390
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000391/* internal.c */
Uwe Hermann2cac6862009-05-16 22:05:42 +0000392struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
Carl-Daniel Hailfinger9f46cfc2009-11-15 17:13:29 +0000393struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t class);
Uwe Hermann2cac6862009-05-16 22:05:42 +0000394struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
395struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
396 uint16_t card_vendor, uint16_t card_device);
Carl-Daniel Hailfinger3b7e75a2009-05-14 21:41:10 +0000397void get_io_perms(void);
Carl-Daniel Hailfingerdb41c592009-08-09 21:50:24 +0000398void release_io_perms(void);
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000399int internal_init(void);
400int internal_shutdown(void);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000401void internal_chip_writeb(uint8_t val, chipaddr addr);
402void internal_chip_writew(uint16_t val, chipaddr addr);
403void internal_chip_writel(uint32_t val, chipaddr addr);
404uint8_t internal_chip_readb(const chipaddr addr);
405uint16_t internal_chip_readw(const chipaddr addr);
406uint32_t internal_chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000407void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000408void mmio_writeb(uint8_t val, void *addr);
409void mmio_writew(uint16_t val, void *addr);
410void mmio_writel(uint32_t val, void *addr);
411uint8_t mmio_readb(void *addr);
412uint16_t mmio_readw(void *addr);
413uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerca8bfc62009-06-05 17:48:08 +0000414void internal_delay(int usecs);
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000415int noop_shutdown(void);
Uwe Hermannc6915932009-05-17 23:12:17 +0000416void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
417void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000418uint8_t noop_chip_readb(const chipaddr addr);
419void noop_chip_writeb(uint8_t val, chipaddr addr);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000420void fallback_chip_writew(uint16_t val, chipaddr addr);
421void fallback_chip_writel(uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000422void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000423uint16_t fallback_chip_readw(const chipaddr addr);
424uint32_t fallback_chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000425void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Uwe Hermanna0869322009-05-14 20:41:57 +0000426#if defined(__FreeBSD__) || defined(__DragonFly__)
427extern int io_fd;
428#endif
Carl-Daniel Hailfinger702218d2009-05-08 17:43:22 +0000429
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000430/* dummyflasher.c */
431int dummy_init(void);
432int dummy_shutdown(void);
Carl-Daniel Hailfinger1455b2b2009-05-11 14:13:25 +0000433void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
434void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000435void dummy_chip_writeb(uint8_t val, chipaddr addr);
436void dummy_chip_writew(uint16_t val, chipaddr addr);
437void dummy_chip_writel(uint32_t val, chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000438void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000439uint8_t dummy_chip_readb(const chipaddr addr);
440uint16_t dummy_chip_readw(const chipaddr addr);
441uint32_t dummy_chip_readl(const chipaddr addr);
Carl-Daniel Hailfinger0bd2a2b2009-06-05 18:32:07 +0000442void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000443int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfingerbfe2e0c2009-05-14 12:59:36 +0000444 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingerc3129202009-05-09 00:54:55 +0000445
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000446/* nic3com.c */
447int nic3com_init(void);
448int nic3com_shutdown(void);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000449void nic3com_chip_writeb(uint8_t val, chipaddr addr);
450uint8_t nic3com_chip_readb(const chipaddr addr);
Uwe Hermann515ab3d2009-05-15 17:02:34 +0000451extern struct pcidev_status nics_3com[];
Uwe Hermannb4dcb712009-05-13 11:36:06 +0000452
Uwe Hermann2bc98f62009-09-30 18:29:55 +0000453/* gfxnvidia.c */
454int gfxnvidia_init(void);
455int gfxnvidia_shutdown(void);
456void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr);
457uint8_t gfxnvidia_chip_readb(const chipaddr addr);
458extern struct pcidev_status gfx_nvidia[];
459
TURBO Jb0912c02009-09-02 23:00:46 +0000460/* drkaiser.c */
461int drkaiser_init(void);
462int drkaiser_shutdown(void);
463void drkaiser_chip_writeb(uint8_t val, chipaddr addr);
464uint8_t drkaiser_chip_readb(const chipaddr addr);
465extern struct pcidev_status drkaiser_pcidev[];
466
Rudolf Marek68720c72009-05-17 19:39:27 +0000467/* satasii.c */
468int satasii_init(void);
469int satasii_shutdown(void);
Rudolf Marek68720c72009-05-17 19:39:27 +0000470void satasii_chip_writeb(uint8_t val, chipaddr addr);
471uint8_t satasii_chip_readb(const chipaddr addr);
472extern struct pcidev_status satas_sii[];
473
Paul Fox05dfbe62009-06-16 21:08:06 +0000474/* ft2232_spi.c */
Carl-Daniel Hailfingerfeea2722009-07-01 00:02:23 +0000475#define FTDI_FT2232H 0x6010
476#define FTDI_FT4232H 0x6011
Paul Fox05dfbe62009-06-16 21:08:06 +0000477int ft2232_spi_init(void);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000478int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
Paul Fox05dfbe62009-06-16 21:08:06 +0000479int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Paul Fox05dfbe62009-06-16 21:08:06 +0000480int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf);
481
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000482/* bitbang_spi.c */
Carl-Daniel Hailfinger3a4781e2009-10-01 14:51:25 +0000483extern int bitbang_spi_half_period;
484extern const struct bitbang_spi_master_entry bitbang_spi_master_table[];
Carl-Daniel Hailfinger547872b2009-09-28 13:15:16 +0000485int bitbang_spi_init(void);
486int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
487int bitbang_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
488int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf);
489
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000490/* buspirate_spi.c */
491int buspirate_spi_init(void);
492int buspirate_spi_shutdown(void);
493int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
494int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
495
Uwe Hermann0846f892007-08-23 13:34:59 +0000496/* flashrom.c */
Carl-Daniel Hailfingeref58a9c2009-08-12 13:32:56 +0000497extern char *programmer_param;
Uwe Hermannad216bf2009-04-24 16:17:41 +0000498extern int verbose;
Carl-Daniel Hailfingera80cfbc2009-07-22 20:13:00 +0000499extern const char *flashrom_version;
Uwe Hermannad216bf2009-04-24 16:17:41 +0000500#define printf_debug(x...) { if (verbose) printf(x); }
Peter Stuge776d2022009-01-26 00:39:57 +0000501void map_flash_registers(struct flashchip *flash);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000502int read_memmapped(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfingerf38431a2009-09-05 02:30:58 +0000503int erase_flash(struct flashchip *flash);
Carl-Daniel Hailfinger38a059d2009-06-13 12:04:03 +0000504int min(int a, int b);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000505int max(int a, int b);
506int check_erased_range(struct flashchip *flash, int start, int len);
507int verify_range(struct flashchip *flash, uint8_t *cmpbuf, int start, int len, char *message);
Uwe Hermannba290d12009-06-17 12:07:12 +0000508char *strcat_realloc(char *dest, const char *src);
509
510#define OK 0
511#define NT 1 /* Not tested */
Uwe Hermann0846f892007-08-23 13:34:59 +0000512
513/* layout.c */
Peter Stuge7ffbc6f2008-06-18 02:08:40 +0000514int show_id(uint8_t *bios, int size, int force);
Uwe Hermann0846f892007-08-23 13:34:59 +0000515int read_romlayout(char *name);
516int find_romentry(char *name);
Carl-Daniel Hailfingerf5fb51c2009-08-19 15:19:18 +0000517int handle_romentries(uint8_t *buffer, struct flashchip *flash);
Uwe Hermann0846f892007-08-23 13:34:59 +0000518
Uwe Hermannad216bf2009-04-24 16:17:41 +0000519/* cbtable.c */
Stefan Reinauere3f3e2e2008-01-18 15:33:10 +0000520int coreboot_init(void);
Uwe Hermann0846f892007-08-23 13:34:59 +0000521extern char *lb_part, *lb_vendor;
Carl-Daniel Hailfingerbc25f942009-07-30 13:30:17 +0000522extern int partvendor_from_cbtable;
Uwe Hermann0846f892007-08-23 13:34:59 +0000523
Carl-Daniel Hailfinger00f911e2007-10-15 21:44:47 +0000524/* spi.c */
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000525enum spi_controller {
526 SPI_CONTROLLER_NONE,
527 SPI_CONTROLLER_ICH7,
528 SPI_CONTROLLER_ICH9,
529 SPI_CONTROLLER_IT87XX,
530 SPI_CONTROLLER_SB600,
531 SPI_CONTROLLER_VIA,
532 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger3426ef62009-08-19 13:27:58 +0000533#if FT2232_SPI_SUPPORT == 1
Paul Fox05dfbe62009-06-16 21:08:06 +0000534 SPI_CONTROLLER_FT2232,
Carl-Daniel Hailfinger3426ef62009-08-19 13:27:58 +0000535#endif
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000536#if DUMMY_SUPPORT == 1
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000537 SPI_CONTROLLER_DUMMY,
Carl-Daniel Hailfinger4740c6f2009-09-16 10:09:21 +0000538#endif
Carl-Daniel Hailfinger5cca01f2009-11-24 00:20:03 +0000539#if BUSPIRATE_SPI_SUPPORT == 1
540 SPI_CONTROLLER_BUSPIRATE,
541#endif
Carl-Daniel Hailfinger3426ef62009-08-19 13:27:58 +0000542 SPI_CONTROLLER_INVALID /* This must always be the last entry. */
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000543};
Carl-Daniel Hailfinger3426ef62009-08-19 13:27:58 +0000544extern const int spi_programmer_count;
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000545struct spi_command {
546 unsigned int writecnt;
547 unsigned int readcnt;
548 const unsigned char *writearr;
549 unsigned char *readarr;
550};
Carl-Daniel Hailfinger02487aa2009-07-22 15:36:50 +0000551struct spi_programmer {
552 int (*command)(unsigned int writecnt, unsigned int readcnt,
553 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger26f7e642009-09-18 15:50:56 +0000554 int (*multicommand)(struct spi_command *cmds);
Carl-Daniel Hailfinger02487aa2009-07-22 15:36:50 +0000555
556 /* Optimized functions for this programmer */
557 int (*read)(struct flashchip *flash, uint8_t *buf, int start, int len);
558 int (*write_256)(struct flashchip *flash, uint8_t *buf);
559};
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000560
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000561extern enum spi_controller spi_controller;
Carl-Daniel Hailfinger02487aa2009-07-22 15:36:50 +0000562extern const struct spi_programmer spi_programmer[];
Carl-Daniel Hailfinger1dfe0ff2009-05-31 17:57:34 +0000563extern void *spibar;
Carl-Daniel Hailfinger42c54972008-05-15 03:19:49 +0000564int probe_spi_rdid(struct flashchip *flash);
Rudolf Marek48a85e42008-06-30 21:45:17 +0000565int probe_spi_rdid4(struct flashchip *flash);
Carl-Daniel Hailfinger14e50ac2008-11-28 01:25:00 +0000566int probe_spi_rems(struct flashchip *flash);
Carl-Daniel Hailfinger42c54972008-05-15 03:19:49 +0000567int probe_spi_res(struct flashchip *flash);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000568int spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermann394131e2008-10-18 21:14:13 +0000569 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger26f7e642009-09-18 15:50:56 +0000570int spi_send_multicommand(struct spi_command *cmds);
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000571int spi_write_enable(void);
572int spi_write_disable(void);
Carl-Daniel Hailfinger6afb6132008-11-03 00:02:11 +0000573int spi_chip_erase_60(struct flashchip *flash);
Peter Stugefa8c5502008-05-10 23:07:52 +0000574int spi_chip_erase_c7(struct flashchip *flash);
Carl-Daniel Hailfinger598ec582008-11-18 00:41:02 +0000575int spi_chip_erase_60_c7(struct flashchip *flash);
Stefan Reinauer424ed222008-10-29 22:13:20 +0000576int spi_chip_erase_d8(struct flashchip *flash);
Carl-Daniel Hailfinger3431bb72009-06-24 08:28:39 +0000577int spi_block_erase_20(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
578int spi_block_erase_52(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
579int spi_block_erase_d8(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
580int spi_block_erase_60(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
581int spi_block_erase_c7(struct flashchip *flash, unsigned int addr, unsigned int blocklen);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000582int spi_chip_write_1(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger8d497012009-05-09 02:34:18 +0000583int spi_chip_write_256(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000584int spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000585uint8_t spi_read_status_register(void);
Carl-Daniel Hailfinger598ec582008-11-18 00:41:02 +0000586int spi_disable_blockprotect(void);
Carl-Daniel Hailfinger2f1b36f2009-07-12 12:06:18 +0000587int spi_byte_program(int addr, uint8_t byte);
588int spi_nbyte_program(int addr, uint8_t *bytes, int len);
589int spi_nbyte_read(int addr, uint8_t *bytes, int len);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000590int spi_read_chunked(struct flashchip *flash, uint8_t *buf, int start, int len, int chunksize);
Peter Stugefd9217d2009-01-26 03:37:40 +0000591int spi_aai_write(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger3e9dbea2009-05-13 11:40:08 +0000592uint32_t spi_get_valid_read_addr(void);
Carl-Daniel Hailfinger02487aa2009-07-22 15:36:50 +0000593int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
594 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger26f7e642009-09-18 15:50:56 +0000595int default_spi_send_multicommand(struct spi_command *cmds);
Carl-Daniel Hailfingere1514992007-10-02 15:49:25 +0000596
Uwe Hermann0846f892007-08-23 13:34:59 +0000597/* 82802ab.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000598int probe_82802ab(struct flashchip *flash);
599int erase_82802ab(struct flashchip *flash);
600int write_82802ab(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000601
602/* am29f040b.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000603int probe_29f040b(struct flashchip *flash);
604int erase_29f040b(struct flashchip *flash);
605int write_29f040b(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000606
Uwe Hermannf983d9f2009-06-14 21:53:26 +0000607/* pm29f002.c */
608int write_pm29f002(struct flashchip *flash, uint8_t *buf);
609
Mats Erik Andersson44e1a192008-09-26 13:19:02 +0000610/* en29f002a.c */
611int probe_en29f002a(struct flashchip *flash);
612int erase_en29f002a(struct flashchip *flash);
613int write_en29f002a(struct flashchip *flash, uint8_t *buf);
614
Dominik Geyerb46acba2008-05-16 12:55:55 +0000615/* ichspi.c */
Carl-Daniel Hailfinger43634392009-05-01 12:22:17 +0000616int ich_init_opcodes(void);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000617int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermann394131e2008-10-18 21:14:13 +0000618 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000619int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000620int ich_spi_write_256(struct flashchip *flash, uint8_t * buf);
Carl-Daniel Hailfinger26f7e642009-09-18 15:50:56 +0000621int ich_spi_send_multicommand(struct spi_command *cmds);
Dominik Geyerb46acba2008-05-16 12:55:55 +0000622
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000623/* it87spi.c */
624extern uint16_t it8716f_flashport;
Carl-Daniel Hailfinger24c1a162009-05-25 23:26:50 +0000625void enter_conf_mode_ite(uint16_t port);
626void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerb8afecd2009-05-31 18:00:57 +0000627int it87spi_init(void);
Dominik Geyerb46acba2008-05-16 12:55:55 +0000628int it87xx_probe_spi_flash(const char *name);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000629int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermann394131e2008-10-18 21:14:13 +0000630 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000631int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000632int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingerbfe5b4a2008-05-13 23:03:12 +0000633
Jason Wanga3f04be2008-11-28 21:36:51 +0000634/* sb600spi.c */
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000635int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Jason Wanga3f04be2008-11-28 21:36:51 +0000636 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000637int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000638int sb600_spi_write_1(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger78185dc2009-05-17 15:49:24 +0000639extern uint8_t *sb600_spibar;
Jason Wanga3f04be2008-11-28 21:36:51 +0000640
Uwe Hermann0846f892007-08-23 13:34:59 +0000641/* jedec.c */
Carl-Daniel Hailfingera758f512008-05-14 12:03:06 +0000642uint8_t oddparity(uint8_t val);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000643void toggle_ready_jedec(chipaddr dst);
644void data_polling_jedec(chipaddr dst, uint8_t data);
645void unprotect_jedec(chipaddr bios);
646void protect_jedec(chipaddr bios);
647int write_byte_program_jedec(chipaddr bios, uint8_t *src,
648 chipaddr dst);
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000649int probe_jedec(struct flashchip *flash);
650int erase_chip_jedec(struct flashchip *flash);
651int write_jedec(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfingera06287c2009-09-23 22:01:33 +0000652int erase_sector_jedec(struct flashchip *flash, unsigned int page, unsigned int pagesize);
653int erase_block_jedec(struct flashchip *flash, unsigned int page, unsigned int blocksize);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000654int write_sector_jedec(chipaddr bios, uint8_t *src,
655 chipaddr dst, unsigned int page_size);
Uwe Hermann0846f892007-08-23 13:34:59 +0000656
Peter Stugeaf8ffac2009-01-26 06:42:02 +0000657/* m29f002.c */
658int erase_m29f002(struct flashchip *flash);
659int write_m29f002t(struct flashchip *flash, uint8_t *buf);
660int write_m29f002b(struct flashchip *flash, uint8_t *buf);
661
Uwe Hermann0846f892007-08-23 13:34:59 +0000662/* m29f400bt.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000663int probe_m29f400bt(struct flashchip *flash);
664int erase_m29f400bt(struct flashchip *flash);
Carl-Daniel Hailfinger30f7cb22009-06-15 17:23:36 +0000665int block_erase_m29f400bt(struct flashchip *flash, int start, int len);
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000666int write_m29f400bt(struct flashchip *flash, uint8_t *buf);
Stefan Reinauere3f3e2e2008-01-18 15:33:10 +0000667int write_coreboot_m29f400bt(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000668void toggle_ready_m29f400bt(chipaddr dst);
669void data_polling_m29f400bt(chipaddr dst, uint8_t data);
670void protect_m29f400bt(chipaddr bios);
671void write_page_m29f400bt(chipaddr bios, uint8_t *src,
672 chipaddr dst, int page_size);
Uwe Hermann0846f892007-08-23 13:34:59 +0000673
674/* mx29f002.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000675int probe_29f002(struct flashchip *flash);
676int erase_29f002(struct flashchip *flash);
677int write_29f002(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000678
Nikolay Petukhov4784c472008-05-17 01:08:58 +0000679/* pm49fl00x.c */
680int probe_49fl00x(struct flashchip *flash);
681int erase_49fl00x(struct flashchip *flash);
682int write_49fl00x(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000683
684/* sharplhf00l04.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000685int probe_lhf00l04(struct flashchip *flash);
686int erase_lhf00l04(struct flashchip *flash);
687int write_lhf00l04(struct flashchip *flash, uint8_t *buf);
Carl-Daniel Hailfinger5820f422009-05-16 21:22:56 +0000688void toggle_ready_lhf00l04(chipaddr dst);
689void data_polling_lhf00l04(chipaddr dst, uint8_t data);
690void protect_lhf00l04(chipaddr bios);
Uwe Hermann0846f892007-08-23 13:34:59 +0000691
692/* sst28sf040.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000693int probe_28sf040(struct flashchip *flash);
694int erase_28sf040(struct flashchip *flash);
695int write_28sf040(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000696
697/* sst39sf020.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000698int probe_39sf020(struct flashchip *flash);
699int write_39sf020(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000700
701/* sst49lf040.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000702int erase_49lf040(struct flashchip *flash);
703int write_49lf040(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000704
705/* sst49lfxxxc.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000706int probe_49lfxxxc(struct flashchip *flash);
707int erase_49lfxxxc(struct flashchip *flash);
708int write_49lfxxxc(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000709
710/* sst_fwhub.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000711int probe_sst_fwhub(struct flashchip *flash);
712int erase_sst_fwhub(struct flashchip *flash);
Carl-Daniel Hailfingera06287c2009-09-23 22:01:33 +0000713int erase_sst_fwhub_block(struct flashchip *flash, unsigned int offset, unsigned int page_size);
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000714int write_sst_fwhub(struct flashchip *flash, uint8_t *buf);
Uwe Hermann0846f892007-08-23 13:34:59 +0000715
Peter Stugecce26822008-07-21 17:48:40 +0000716/* w39v040c.c */
717int probe_w39v040c(struct flashchip *flash);
718int erase_w39v040c(struct flashchip *flash);
719int write_w39v040c(struct flashchip *flash, uint8_t *buf);
720
Stefan Reinauerac378972008-03-17 22:59:40 +0000721/* w39V080fa.c */
722int probe_winbond_fwhub(struct flashchip *flash);
723int erase_winbond_fwhub(struct flashchip *flash);
724int write_winbond_fwhub(struct flashchip *flash, uint8_t *buf);
725
Markus Boasd2ac6fc2007-08-30 10:17:50 +0000726/* w29ee011.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000727int probe_w29ee011(struct flashchip *flash);
Markus Boasd2ac6fc2007-08-30 10:17:50 +0000728
Uwe Hermann0846f892007-08-23 13:34:59 +0000729/* w49f002u.c */
Uwe Hermanna0cc53d2007-09-09 20:24:29 +0000730int write_49f002(struct flashchip *flash, uint8_t *buf);
Stefan Reinauerff4f1972007-05-24 08:48:10 +0000731
Peter Stugebf196e92009-01-26 03:08:45 +0000732/* wbsio_spi.c */
733int wbsio_check_for_spi(const char *name);
Carl-Daniel Hailfingerd0478292009-07-10 21:08:55 +0000734int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt,
Uwe Hermannd1129ac2009-05-28 15:07:42 +0000735 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfingercbf563c2009-06-16 08:55:44 +0000736int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
Carl-Daniel Hailfinger96930c32009-05-09 02:30:21 +0000737int wbsio_spi_write_1(struct flashchip *flash, uint8_t *buf);
Peter Stugebf196e92009-01-26 03:08:45 +0000738
Claus Gindharta7b35512008-04-28 17:51:09 +0000739/* stm50flw0x0x.c */
740int probe_stm50flw0x0x(struct flashchip *flash);
741int erase_stm50flw0x0x(struct flashchip *flash);
742int write_stm50flw0x0x(struct flashchip *flash, uint8_t *buf);
Dominik Geyerb46acba2008-05-16 12:55:55 +0000743
Urja Rannikko22915352009-06-23 11:33:43 +0000744/* serprog.c */
Urja Rannikko22915352009-06-23 11:33:43 +0000745int serprog_init(void);
746int serprog_shutdown(void);
747void serprog_chip_writeb(uint8_t val, chipaddr addr);
748uint8_t serprog_chip_readb(const chipaddr addr);
749void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
750void serprog_delay(int delay);
Carl-Daniel Hailfingere51ea102009-11-23 19:20:11 +0000751
752/* serial.c */
Carl-Daniel Hailfingera4a9bfb2009-11-21 11:02:48 +0000753void sp_flush_incoming(void);
754int sp_openserport(char *dev, unsigned int baud);
Carl-Daniel Hailfingere51ea102009-11-23 19:20:11 +0000755void __attribute__((noreturn)) sp_die(char *msg);
Carl-Daniel Hailfingera4a9bfb2009-11-21 11:02:48 +0000756extern int sp_fd;
Uwe Hermann1432a602009-06-28 23:26:37 +0000757
Ollie Lho761bf1b2004-03-20 16:46:10 +0000758#endif /* !__FLASH_H__ */