blob: 920a8e23b555937d4fb746c4eb90f5d1c3ad2660 [file] [log] [blame]
hailfinger428f6852010-07-27 22:41:39 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
6 * Copyright (C) 2005-2009 coresystems GmbH
7 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
8 *
9 * 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.
13 *
14 * 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.
18 *
19 * 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
22 */
23
24#ifndef __PROGRAMMER_H__
25#define __PROGRAMMER_H__ 1
26
Souvik Ghoshd75cd672016-06-17 14:21:39 -070027#include "flash.h" /* for chipaddr and flashctx */
hailfingerfe7cd9e2011-11-04 21:35:26 +000028
hailfinger428f6852010-07-27 22:41:39 +000029enum programmer {
30#if CONFIG_INTERNAL == 1
31 PROGRAMMER_INTERNAL,
32#endif
33#if CONFIG_DUMMY == 1
34 PROGRAMMER_DUMMY,
35#endif
36#if CONFIG_NIC3COM == 1
37 PROGRAMMER_NIC3COM,
38#endif
39#if CONFIG_NICREALTEK == 1
40 PROGRAMMER_NICREALTEK,
uwe6764e922010-09-03 18:21:21 +000041#endif
hailfinger428f6852010-07-27 22:41:39 +000042#if CONFIG_NICNATSEMI == 1
43 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000044#endif
hailfinger428f6852010-07-27 22:41:39 +000045#if CONFIG_GFXNVIDIA == 1
46 PROGRAMMER_GFXNVIDIA,
47#endif
48#if CONFIG_DRKAISER == 1
49 PROGRAMMER_DRKAISER,
50#endif
51#if CONFIG_SATASII == 1
52 PROGRAMMER_SATASII,
53#endif
54#if CONFIG_ATAHPT == 1
55 PROGRAMMER_ATAHPT,
56#endif
hailfinger428f6852010-07-27 22:41:39 +000057#if CONFIG_FT2232_SPI == 1
58 PROGRAMMER_FT2232_SPI,
59#endif
60#if CONFIG_SERPROG == 1
61 PROGRAMMER_SERPROG,
62#endif
63#if CONFIG_BUSPIRATE_SPI == 1
64 PROGRAMMER_BUSPIRATE_SPI,
65#endif
Anton Staafb2647882014-09-17 15:13:43 -070066#if CONFIG_RAIDEN_DEBUG_SPI == 1
67 PROGRAMMER_RAIDEN_DEBUG_SPI,
68#endif
hailfinger428f6852010-07-27 22:41:39 +000069#if CONFIG_DEDIPROG == 1
70 PROGRAMMER_DEDIPROG,
71#endif
72#if CONFIG_RAYER_SPI == 1
73 PROGRAMMER_RAYER_SPI,
74#endif
hailfinger7949b652011-05-08 00:24:18 +000075#if CONFIG_NICINTEL == 1
76 PROGRAMMER_NICINTEL,
77#endif
uwe6764e922010-09-03 18:21:21 +000078#if CONFIG_NICINTEL_SPI == 1
79 PROGRAMMER_NICINTEL_SPI,
80#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000081#if CONFIG_OGP_SPI == 1
82 PROGRAMMER_OGP_SPI,
83#endif
hailfinger935365d2011-02-04 21:37:59 +000084#if CONFIG_SATAMV == 1
85 PROGRAMMER_SATAMV,
86#endif
David Hendrickscebee892015-05-23 20:30:30 -070087#if CONFIG_LINUX_MTD == 1
88 PROGRAMMER_LINUX_MTD,
89#endif
uwe7df6dda2011-09-03 18:37:52 +000090#if CONFIG_LINUX_SPI == 1
91 PROGRAMMER_LINUX_SPI,
92#endif
hailfinger428f6852010-07-27 22:41:39 +000093 PROGRAMMER_INVALID /* This must always be the last entry. */
94};
95
David Hendricksba0827a2013-05-03 20:25:40 -070096enum alias_type {
97 ALIAS_NONE = 0, /* no alias (default) */
98 ALIAS_EC, /* embedded controller */
99 ALIAS_HOST, /* chipset / PCH / SoC / etc. */
100};
101
102struct programmer_alias {
103 const char *name;
104 enum alias_type type;
105};
106
107extern struct programmer_alias *alias;
108extern struct programmer_alias aliases[];
109
hailfinger428f6852010-07-27 22:41:39 +0000110struct programmer_entry {
111 const char *vendor;
112 const char *name;
113
114 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000115
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700116 void *(*map_flash_region) (const char *descr, unsigned long phys_addr,
117 size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000118 void (*unmap_flash_region) (void *virt_addr, size_t len);
119
hailfinger428f6852010-07-27 22:41:39 +0000120 void (*delay) (int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800121
122 /*
123 * If set, use extra precautions such as erasing with small block sizes
124 * and verifying more rigorously. This will incur a performance penalty
125 * but is good for programming the ROM in-system on a live machine.
126 */
127 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000128};
129
130extern const struct programmer_entry programmer_table[];
131
hailfinger969e2f32011-09-08 00:00:29 +0000132int programmer_init(enum programmer prog, char *param);
hailfinger428f6852010-07-27 22:41:39 +0000133int programmer_shutdown(void);
134
135enum bitbang_spi_master_type {
136 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
137#if CONFIG_RAYER_SPI == 1
138 BITBANG_SPI_MASTER_RAYER,
139#endif
uwe6764e922010-09-03 18:21:21 +0000140#if CONFIG_NICINTEL_SPI == 1
141 BITBANG_SPI_MASTER_NICINTEL,
142#endif
hailfinger52384c92010-07-28 15:08:35 +0000143#if CONFIG_INTERNAL == 1
144#if defined(__i386__) || defined(__x86_64__)
145 BITBANG_SPI_MASTER_MCP,
146#endif
147#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000148#if CONFIG_OGP_SPI == 1
149 BITBANG_SPI_MASTER_OGP,
150#endif
hailfinger428f6852010-07-27 22:41:39 +0000151};
152
153struct bitbang_spi_master {
154 enum bitbang_spi_master_type type;
155
156 /* Note that CS# is active low, so val=0 means the chip is active. */
157 void (*set_cs) (int val);
158 void (*set_sck) (int val);
159 void (*set_mosi) (int val);
160 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000161 void (*request_bus) (void);
162 void (*release_bus) (void);
hailfinger428f6852010-07-27 22:41:39 +0000163};
164
165#if CONFIG_INTERNAL == 1
166struct penable {
167 uint16_t vendor_id;
168 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000169 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000170 const char *vendor_name;
171 const char *device_name;
172 int (*doit) (struct pci_dev *dev, const char *name);
173};
174
175extern const struct penable chipset_enables[];
176
hailfingere52e9f82011-05-05 07:12:40 +0000177enum board_match_phase {
178 P1,
179 P2,
180 P3
181};
182
hailfinger4640bdb2011-08-31 16:19:50 +0000183struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000184 /* Any device, but make it sensible, like the ISA bridge. */
185 uint16_t first_vendor;
186 uint16_t first_device;
187 uint16_t first_card_vendor;
188 uint16_t first_card_device;
189
190 /* Any device, but make it sensible, like
191 * the host bridge. May be NULL.
192 */
193 uint16_t second_vendor;
194 uint16_t second_device;
195 uint16_t second_card_vendor;
196 uint16_t second_card_device;
197
stefanct6d836ba2011-05-26 01:35:19 +0000198 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000199 const char *dmi_pattern;
200
stefanct6d836ba2011-05-26 01:35:19 +0000201 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000202 const char *lb_vendor;
203 const char *lb_part;
204
hailfingere52e9f82011-05-05 07:12:40 +0000205 enum board_match_phase phase;
206
hailfinger428f6852010-07-27 22:41:39 +0000207 const char *vendor_name;
208 const char *board_name;
209
210 int max_rom_decode_parallel;
211 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000212 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000213};
214
hailfinger4640bdb2011-08-31 16:19:50 +0000215extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000216
217struct board_info {
218 const char *vendor;
219 const char *name;
220 const int working;
221#ifdef CONFIG_PRINT_WIKI
222 const char *url;
223 const char *note;
224#endif
225};
226
227extern const struct board_info boards_known[];
228extern const struct board_info laptops_known[];
229#endif
230
231/* udelay.c */
232void myusec_delay(int usecs);
233void myusec_calibrate_delay(void);
234void internal_delay(int usecs);
235
236#if NEED_PCI == 1
237/* pcidev.c */
238extern uint32_t io_base_addr;
239extern struct pci_access *pacc;
240extern struct pci_dev *pcidev_dev;
241struct pcidev_status {
242 uint16_t vendor_id;
243 uint16_t device_id;
244 int status;
245 const char *vendor_name;
246 const char *device_name;
247};
hailfingerbf923c32011-02-15 22:44:27 +0000248uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct pcidev_status *devs);
hailfinger0d703d42011-03-07 01:08:09 +0000249uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
hailfingerf31cbdc2010-11-10 15:25:18 +0000250/* rpci_write_* are reversible writes. The original PCI config space register
251 * contents will be restored on shutdown.
252 */
mkarcher08a24552010-12-26 23:55:19 +0000253int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
254int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
255int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000256#endif
257
258/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000259#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT+CONFIG_NICINTEL+CONFIG_NICINTEL_SPI+CONFIG_OGP_SPI+CONFIG_SATAMV >= 1
hailfinger428f6852010-07-27 22:41:39 +0000260void print_supported_pcidevs(const struct pcidev_status *devs);
261#endif
262
hailfingere20dc562011-06-09 20:06:34 +0000263#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000264/* board_enable.c */
265void w836xx_ext_enter(uint16_t port);
266void w836xx_ext_leave(uint16_t port);
267int it8705f_write_enable(uint8_t port);
268uint8_t sio_read(uint16_t port, uint8_t reg);
269void sio_write(uint16_t port, uint8_t reg, uint8_t data);
270void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000271void board_handle_before_superio(void);
272void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000273int board_flash_enable(const char *vendor, const char *part);
274
275/* chipset_enable.c */
276int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800277int get_target_bus_from_chipset(enum chipbustype *target_bus);
Ramya Vijaykumare6a7ca82015-05-12 14:27:29 +0530278enum ich_chipset ich_generation;
hailfinger428f6852010-07-27 22:41:39 +0000279
280/* processor_enable.c */
281int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000282#endif
hailfinger428f6852010-07-27 22:41:39 +0000283
284/* physmap.c */
285void *physmap(const char *descr, unsigned long phys_addr, size_t len);
286void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
287void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000288#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000289int setup_cpu_msr(int cpu);
290void cleanup_cpu_msr(void);
291
292/* cbtable.c */
293void lb_vendor_dev_from_string(char *boardstring);
294int coreboot_init(void);
295extern char *lb_part, *lb_vendor;
296extern int partvendor_from_cbtable;
297
298/* dmi.c */
299extern int has_dmi_support;
300void dmi_init(void);
301int dmi_match(const char *pattern);
302
303/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000304struct superio {
305 uint16_t vendor;
306 uint16_t port;
307 uint16_t model;
308};
hailfinger94e090c2011-04-27 14:34:08 +0000309extern struct superio superios[];
310extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000311#define SUPERIO_VENDOR_NONE 0x0
312#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000313#endif
314#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000315struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000316struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000317struct 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);
320#endif
321void get_io_perms(void);
322void release_io_perms(void);
323#if CONFIG_INTERNAL == 1
324extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000325extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000326extern int force_boardenable;
327extern int force_boardmismatch;
328void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000329int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000330extern enum chipbustype internal_buses_supported;
hailfinger428f6852010-07-27 22:41:39 +0000331int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000332#endif
333
334/* hwaccess.c */
335void mmio_writeb(uint8_t val, void *addr);
336void mmio_writew(uint16_t val, void *addr);
337void mmio_writel(uint32_t val, void *addr);
338uint8_t mmio_readb(void *addr);
339uint16_t mmio_readw(void *addr);
340uint32_t mmio_readl(void *addr);
341void mmio_le_writeb(uint8_t val, void *addr);
342void mmio_le_writew(uint16_t val, void *addr);
343void mmio_le_writel(uint32_t val, void *addr);
344uint8_t mmio_le_readb(void *addr);
345uint16_t mmio_le_readw(void *addr);
346uint32_t mmio_le_readl(void *addr);
347#define pci_mmio_writeb mmio_le_writeb
348#define pci_mmio_writew mmio_le_writew
349#define pci_mmio_writel mmio_le_writel
350#define pci_mmio_readb mmio_le_readb
351#define pci_mmio_readw mmio_le_readw
352#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000353void rmmio_writeb(uint8_t val, void *addr);
354void rmmio_writew(uint16_t val, void *addr);
355void rmmio_writel(uint32_t val, void *addr);
356void rmmio_le_writeb(uint8_t val, void *addr);
357void rmmio_le_writew(uint16_t val, void *addr);
358void rmmio_le_writel(uint32_t val, void *addr);
359#define pci_rmmio_writeb rmmio_le_writeb
360#define pci_rmmio_writew rmmio_le_writew
361#define pci_rmmio_writel rmmio_le_writel
362void rmmio_valb(void *addr);
363void rmmio_valw(void *addr);
364void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000365
hailfinger428f6852010-07-27 22:41:39 +0000366/* dummyflasher.c */
367#if CONFIG_DUMMY == 1
368int dummy_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000369void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
370void dummy_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700371
hailfinger428f6852010-07-27 22:41:39 +0000372#endif
373
374/* nic3com.c */
375#if CONFIG_NIC3COM == 1
376int nic3com_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000377extern const struct pcidev_status nics_3com[];
378#endif
379
380/* gfxnvidia.c */
381#if CONFIG_GFXNVIDIA == 1
382int gfxnvidia_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000383extern const struct pcidev_status gfx_nvidia[];
384#endif
385
386/* drkaiser.c */
387#if CONFIG_DRKAISER == 1
388int drkaiser_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000389extern const struct pcidev_status drkaiser_pcidev[];
390#endif
391
392/* nicrealtek.c */
393#if CONFIG_NICREALTEK == 1
394int nicrealtek_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000395extern const struct pcidev_status nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000396#endif
397
398/* nicnatsemi.c */
399#if CONFIG_NICNATSEMI == 1
400int nicnatsemi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000401extern const struct pcidev_status nics_natsemi[];
402#endif
403
hailfinger7949b652011-05-08 00:24:18 +0000404/* nicintel.c */
405#if CONFIG_NICINTEL == 1
406int nicintel_init(void);
hailfinger7949b652011-05-08 00:24:18 +0000407extern const struct pcidev_status nics_intel[];
408#endif
409
uwe6764e922010-09-03 18:21:21 +0000410/* nicintel_spi.c */
411#if CONFIG_NICINTEL_SPI == 1
412int nicintel_spi_init(void);
uwe6764e922010-09-03 18:21:21 +0000413extern const struct pcidev_status nics_intel_spi[];
414#endif
415
hailfingerfb1f31f2010-12-03 14:48:11 +0000416/* ogp_spi.c */
417#if CONFIG_OGP_SPI == 1
418int ogp_spi_init(void);
hailfingerfb1f31f2010-12-03 14:48:11 +0000419extern const struct pcidev_status ogp_spi[];
420#endif
421
hailfinger935365d2011-02-04 21:37:59 +0000422/* satamv.c */
423#if CONFIG_SATAMV == 1
424int satamv_init(void);
hailfinger935365d2011-02-04 21:37:59 +0000425extern const struct pcidev_status satas_mv[];
426#endif
427
hailfinger428f6852010-07-27 22:41:39 +0000428/* satasii.c */
429#if CONFIG_SATASII == 1
430int satasii_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000431extern const struct pcidev_status satas_sii[];
432#endif
433
434/* atahpt.c */
435#if CONFIG_ATAHPT == 1
436int atahpt_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000437extern const struct pcidev_status ata_hpt[];
438#endif
439
440/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000441#if CONFIG_FT2232_SPI == 1
442struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000443 uint16_t vendor_id;
444 uint16_t device_id;
445 int status;
446 const char *vendor_name;
447 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000448};
hailfinger428f6852010-07-27 22:41:39 +0000449int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000450extern const struct usbdev_status devs_ft2232spi[];
451void print_supported_usbdevs(const struct usbdev_status *devs);
452#endif
hailfinger428f6852010-07-27 22:41:39 +0000453
454/* rayer_spi.c */
455#if CONFIG_RAYER_SPI == 1
456int rayer_spi_init(void);
457#endif
458
459/* bitbang_spi.c */
460int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
hailfinger12cba9a2010-09-15 00:17:37 +0000461int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000462
463/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000464#if CONFIG_BUSPIRATE_SPI == 1
hailfinger428f6852010-07-27 22:41:39 +0000465int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000466#endif
hailfinger428f6852010-07-27 22:41:39 +0000467
Anton Staafb2647882014-09-17 15:13:43 -0700468/* raiden_debug_spi.c */
469#if CONFIG_RAIDEN_DEBUG_SPI == 1
470int raiden_debug_spi_init(void);
471#endif
472
David Hendricks7e449602013-05-17 19:21:36 -0700473/* linux_i2c.c */
474#if CONFIG_LINUX_I2C == 1
475int linux_i2c_shutdown(void *data);
476int linux_i2c_init(void);
477int linux_i2c_open(int bus, int addr, int force);
478void linux_i2c_close(void);
479int linux_i2c_xfer(int bus, int addr, const void *inbuf,
480 int insize, const void *outbuf, int outsize);
481#endif
482
David Hendrickscebee892015-05-23 20:30:30 -0700483/* linux_mtd.c */
484#if CONFIG_LINUX_MTD == 1
485int linux_mtd_init(void);
486#endif
487
uwe7df6dda2011-09-03 18:37:52 +0000488/* linux_spi.c */
489#if CONFIG_LINUX_SPI == 1
490int linux_spi_init(void);
491#endif
492
hailfinger428f6852010-07-27 22:41:39 +0000493/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000494#if CONFIG_DEDIPROG == 1
hailfinger428f6852010-07-27 22:41:39 +0000495int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000496#endif
hailfinger428f6852010-07-27 22:41:39 +0000497
498/* flashrom.c */
499struct decode_sizes {
500 uint32_t parallel;
501 uint32_t lpc;
502 uint32_t fwh;
503 uint32_t spi;
504};
505extern struct decode_sizes max_rom_decode;
506extern int programmer_may_write;
507extern unsigned long flashbase;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700508void check_chip_supported(const struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000509int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000510char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000511
512/* layout.c */
513int show_id(uint8_t *bios, int size, int force);
514
515/* spi.c */
516enum spi_controller {
517 SPI_CONTROLLER_NONE,
518#if CONFIG_INTERNAL == 1
519#if defined(__i386__) || defined(__x86_64__)
520 SPI_CONTROLLER_ICH7,
521 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700522 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000523 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000524 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800525 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000526 SPI_CONTROLLER_SB600,
527 SPI_CONTROLLER_VIA,
528 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800529 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800530 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700531#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800532#if defined(__arm__)
533 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000534#endif
535#endif
536#if CONFIG_FT2232_SPI == 1
537 SPI_CONTROLLER_FT2232,
538#endif
539#if CONFIG_DUMMY == 1
540 SPI_CONTROLLER_DUMMY,
541#endif
542#if CONFIG_BUSPIRATE_SPI == 1
543 SPI_CONTROLLER_BUSPIRATE,
544#endif
Anton Staafb2647882014-09-17 15:13:43 -0700545#if CONFIG_RAIDEN_DEBUG_SPI == 1
546 SPI_CONTROLLER_RAIDEN_DEBUG,
547#endif
hailfinger428f6852010-07-27 22:41:39 +0000548#if CONFIG_DEDIPROG == 1
549 SPI_CONTROLLER_DEDIPROG,
550#endif
David Hendricks91040832011-07-08 20:01:09 -0700551#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__) || defined(__arm__)))
mkarcherd264e9e2011-05-11 17:07:07 +0000552 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000553#endif
uwe7df6dda2011-09-03 18:37:52 +0000554#if CONFIG_LINUX_SPI == 1
555 SPI_CONTROLLER_LINUX,
556#endif
stefanct69965b62011-09-15 23:38:14 +0000557#if CONFIG_SERPROG == 1
558 SPI_CONTROLLER_SERPROG,
559#endif
hailfinger428f6852010-07-27 22:41:39 +0000560};
561extern const int spi_programmer_count;
mkarcher8fb57592011-05-11 17:07:02 +0000562
563#define MAX_DATA_UNSPECIFIED 0
564#define MAX_DATA_READ_UNLIMITED 64 * 1024
565#define MAX_DATA_WRITE_UNLIMITED 256
hailfinger428f6852010-07-27 22:41:39 +0000566struct spi_programmer {
mkarcherd264e9e2011-05-11 17:07:07 +0000567 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000568 unsigned int max_data_read;
569 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700570 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000571 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700572 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000573
574 /* Optimized functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700575 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
576 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000577};
578
mkarcherd264e9e2011-05-11 17:07:07 +0000579extern const struct spi_programmer *spi_programmer;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700580int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000581 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700582int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
583int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
584int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
mkarcherd264e9e2011-05-11 17:07:07 +0000585void register_spi_programmer(const struct spi_programmer *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000586
587/* ichspi.c */
588#if CONFIG_INTERNAL == 1
stefanctc035c192011-11-06 23:51:09 +0000589enum ich_chipset {
590 CHIPSET_ICH_UNKNOWN,
591 CHIPSET_ICH7 = 7,
592 CHIPSET_ICH8,
593 CHIPSET_ICH9,
594 CHIPSET_ICH10,
595 CHIPSET_5_SERIES_IBEX_PEAK,
596 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800597 CHIPSET_7_SERIES_PANTHER_POINT,
598 CHIPSET_8_SERIES_LYNX_POINT,
599 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700600 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530601 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800602 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700603 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000604};
605
hailfinger428f6852010-07-27 22:41:39 +0000606extern uint32_t ichspi_bbar;
607int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000608 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000609int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000610
Rong Changaaa1acf2012-06-21 19:21:18 +0800611/* ene_lpc.c */
612int ene_probe_spi_flash(const char *name);
613
hailfinger2b46a862011-02-28 23:58:15 +0000614/* it85spi.c */
hailfinger94e090c2011-04-27 14:34:08 +0000615int it85xx_spi_init(struct superio s);
Shawn Nematbakhsh3404b1a2012-07-26 15:19:58 -0700616int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000617
hailfinger428f6852010-07-27 22:41:39 +0000618/* it87spi.c */
619void enter_conf_mode_ite(uint16_t port);
620void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000621void probe_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000622int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000623
hailfingere20dc562011-06-09 20:06:34 +0000624/* mcp6x_spi.c */
625int mcp6x_spi_init(int want_spi);
626
David Hendricks46d32e32011-01-19 16:01:52 -0800627/* mec1308.c */
David Hendricks46d32e32011-01-19 16:01:52 -0800628int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800629
hailfinger428f6852010-07-27 22:41:39 +0000630/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000631int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000632
633/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000634int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000635#endif
636
hailfingerfe7cd9e2011-11-04 21:35:26 +0000637/* opaque.c */
638struct opaque_programmer {
639 int max_data_read;
640 int max_data_write;
641 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700642 int (*probe) (struct flashctx *flash);
643 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
644 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
645 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
646 uint8_t (*read_status) (const struct flashctx *flash);
647 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks5d481e12012-05-24 14:14:14 -0700648 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000649};
David Hendricks292edf02013-07-11 16:12:58 -0700650extern struct opaque_programmer *opaque_programmer;
651void register_opaque_programmer(struct opaque_programmer *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000652
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700653/* programmer.c */
654int noop_shutdown(void);
655void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
656void fallback_unmap(void *virt_addr, size_t len);
657uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
658void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
659void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
660void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
661void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
662uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
663uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
664void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
665struct par_programmer {
666 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
667 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
668 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
669 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
670 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
671 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
672 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
673 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
674};
675extern const struct par_programmer *par_programmer;
676void register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
677
hailfinger428f6852010-07-27 22:41:39 +0000678/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000679#if CONFIG_SERPROG == 1
hailfinger428f6852010-07-27 22:41:39 +0000680int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000681void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000682#endif
hailfinger428f6852010-07-27 22:41:39 +0000683
684/* serial.c */
685#if _WIN32
686typedef HANDLE fdtype;
687#else
688typedef int fdtype;
689#endif
690
David Hendricksc801adb2010-12-09 16:58:56 -0800691/* wpce775x.c */
David Hendricksc801adb2010-12-09 16:58:56 -0800692int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800693
David Hendricksb907de32014-08-11 16:47:09 -0700694/* cros_ec.c */
695int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700696
697/**
698 * Probe the Google Chrome OS EC device
699 *
700 * @return 0 if found correct, non-zero if not found or error
701 */
David Hendricksb907de32014-08-11 16:47:09 -0700702int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700703
David Hendricksb907de32014-08-11 16:47:09 -0700704int cros_ec_probe_lpc(const char *name);
705int cros_ec_need_2nd_pass(void);
706int cros_ec_finish(void);
707int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800708
hailfinger428f6852010-07-27 22:41:39 +0000709void sp_flush_incoming(void);
710fdtype sp_openserport(char *dev, unsigned int baud);
711void __attribute__((noreturn)) sp_die(char *msg);
712extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000713/* expose serialport_shutdown as it's currently used by buspirate */
714int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000715int serialport_write(unsigned char *buf, unsigned int writecnt);
716int serialport_read(unsigned char *buf, unsigned int readcnt);
717
718#endif /* !__PROGRAMMER_H__ */