blob: 880e9cd974cb2a02ff32b51664f9ce9f0b4b368e [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
Vadim Bendebury066143d2018-07-16 18:20:33 -0700110/*
111 * This function returns 'true' if current flashrom invocation is programming
112 * the EC.
113 */
114static inline int programming_ec(void) {
115 return alias && (alias->type == ALIAS_EC);
116}
117
hailfinger428f6852010-07-27 22:41:39 +0000118struct programmer_entry {
119 const char *vendor;
120 const char *name;
121
David Hendricksac1d25c2016-08-09 17:00:58 -0700122 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000123
Patrick Georgi4befc162017-02-03 18:32:01 +0100124 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000125 void (*unmap_flash_region) (void *virt_addr, size_t len);
126
hailfinger428f6852010-07-27 22:41:39 +0000127 void (*delay) (int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800128
129 /*
130 * If set, use extra precautions such as erasing with small block sizes
131 * and verifying more rigorously. This will incur a performance penalty
132 * but is good for programming the ROM in-system on a live machine.
133 */
134 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000135};
136
137extern const struct programmer_entry programmer_table[];
138
David Hendricksac1d25c2016-08-09 17:00:58 -0700139int programmer_init(enum programmer prog, char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700140int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000141
142enum bitbang_spi_master_type {
143 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
144#if CONFIG_RAYER_SPI == 1
145 BITBANG_SPI_MASTER_RAYER,
146#endif
uwe6764e922010-09-03 18:21:21 +0000147#if CONFIG_NICINTEL_SPI == 1
148 BITBANG_SPI_MASTER_NICINTEL,
149#endif
hailfinger52384c92010-07-28 15:08:35 +0000150#if CONFIG_INTERNAL == 1
151#if defined(__i386__) || defined(__x86_64__)
152 BITBANG_SPI_MASTER_MCP,
153#endif
154#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000155#if CONFIG_OGP_SPI == 1
156 BITBANG_SPI_MASTER_OGP,
157#endif
hailfinger428f6852010-07-27 22:41:39 +0000158};
159
160struct bitbang_spi_master {
161 enum bitbang_spi_master_type type;
162
163 /* Note that CS# is active low, so val=0 means the chip is active. */
164 void (*set_cs) (int val);
165 void (*set_sck) (int val);
166 void (*set_mosi) (int val);
167 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000168 void (*request_bus) (void);
169 void (*release_bus) (void);
Patrick Georgie081d5d2017-03-22 21:18:18 +0100170
171 /* Length of half a clock period in usecs. */
172 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000173};
174
175#if CONFIG_INTERNAL == 1
176struct penable {
177 uint16_t vendor_id;
178 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000179 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000180 const char *vendor_name;
181 const char *device_name;
182 int (*doit) (struct pci_dev *dev, const char *name);
183};
184
185extern const struct penable chipset_enables[];
186
hailfingere52e9f82011-05-05 07:12:40 +0000187enum board_match_phase {
188 P1,
189 P2,
190 P3
191};
192
hailfinger4640bdb2011-08-31 16:19:50 +0000193struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000194 /* Any device, but make it sensible, like the ISA bridge. */
195 uint16_t first_vendor;
196 uint16_t first_device;
197 uint16_t first_card_vendor;
198 uint16_t first_card_device;
199
200 /* Any device, but make it sensible, like
201 * the host bridge. May be NULL.
202 */
203 uint16_t second_vendor;
204 uint16_t second_device;
205 uint16_t second_card_vendor;
206 uint16_t second_card_device;
207
stefanct6d836ba2011-05-26 01:35:19 +0000208 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000209 const char *dmi_pattern;
210
stefanct6d836ba2011-05-26 01:35:19 +0000211 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000212 const char *lb_vendor;
213 const char *lb_part;
214
hailfingere52e9f82011-05-05 07:12:40 +0000215 enum board_match_phase phase;
216
hailfinger428f6852010-07-27 22:41:39 +0000217 const char *vendor_name;
218 const char *board_name;
219
220 int max_rom_decode_parallel;
221 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000222 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000223};
224
hailfinger4640bdb2011-08-31 16:19:50 +0000225extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000226
227struct board_info {
228 const char *vendor;
229 const char *name;
230 const int working;
231#ifdef CONFIG_PRINT_WIKI
232 const char *url;
233 const char *note;
234#endif
235};
236
237extern const struct board_info boards_known[];
238extern const struct board_info laptops_known[];
239#endif
240
241/* udelay.c */
242void myusec_delay(int usecs);
243void myusec_calibrate_delay(void);
244void internal_delay(int usecs);
245
246#if NEED_PCI == 1
247/* pcidev.c */
hailfinger428f6852010-07-27 22:41:39 +0000248extern struct pci_access *pacc;
Patrick Georgi8ae16572017-03-09 15:59:25 +0100249struct dev_entry {
hailfinger428f6852010-07-27 22:41:39 +0000250 uint16_t vendor_id;
251 uint16_t device_id;
252 int status;
253 const char *vendor_name;
254 const char *device_name;
255};
Patrick Georgif776a442017-03-28 21:34:33 +0200256uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100257uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_entry *devs);
Patrick Georgi7c30fa92017-03-28 22:47:12 +0200258struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
hailfingerf31cbdc2010-11-10 15:25:18 +0000259/* rpci_write_* are reversible writes. The original PCI config space register
260 * contents will be restored on shutdown.
261 */
mkarcher08a24552010-12-26 23:55:19 +0000262int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
263int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
264int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000265#endif
266
267/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000268#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
Patrick Georgi8ae16572017-03-09 15:59:25 +0100269void print_supported_pcidevs(const struct dev_entry *devs);
hailfinger428f6852010-07-27 22:41:39 +0000270#endif
271
hailfingere20dc562011-06-09 20:06:34 +0000272#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000273/* board_enable.c */
274void w836xx_ext_enter(uint16_t port);
275void w836xx_ext_leave(uint16_t port);
276int it8705f_write_enable(uint8_t port);
277uint8_t sio_read(uint16_t port, uint8_t reg);
278void sio_write(uint16_t port, uint8_t reg, uint8_t data);
279void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000280void board_handle_before_superio(void);
281void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000282int board_flash_enable(const char *vendor, const char *part);
283
284/* chipset_enable.c */
285int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800286int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000287
288/* processor_enable.c */
289int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000290#endif
hailfinger428f6852010-07-27 22:41:39 +0000291
292/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100293void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi220f4b52017-03-21 16:55:04 +0100294void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi4befc162017-02-03 18:32:01 +0100295void *physmap_try_ro(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000296void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000297#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000298int setup_cpu_msr(int cpu);
299void cleanup_cpu_msr(void);
300
301/* cbtable.c */
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700302void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000303int coreboot_init(void);
304extern char *lb_part, *lb_vendor;
305extern int partvendor_from_cbtable;
306
307/* dmi.c */
308extern int has_dmi_support;
309void dmi_init(void);
310int dmi_match(const char *pattern);
311
312/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000313struct superio {
314 uint16_t vendor;
315 uint16_t port;
316 uint16_t model;
317};
hailfinger94e090c2011-04-27 14:34:08 +0000318extern struct superio superios[];
319extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000320#define SUPERIO_VENDOR_NONE 0x0
321#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000322#endif
323#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000324struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000325struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000326struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
327struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
328 uint16_t card_vendor, uint16_t card_device);
329#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100330int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000331#if CONFIG_INTERNAL == 1
332extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000333extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000334extern int force_boardenable;
335extern int force_boardmismatch;
336void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000337int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000338extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700339int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000340#endif
341
342/* hwaccess.c */
343void mmio_writeb(uint8_t val, void *addr);
344void mmio_writew(uint16_t val, void *addr);
345void mmio_writel(uint32_t val, void *addr);
346uint8_t mmio_readb(void *addr);
347uint16_t mmio_readw(void *addr);
348uint32_t mmio_readl(void *addr);
349void mmio_le_writeb(uint8_t val, void *addr);
350void mmio_le_writew(uint16_t val, void *addr);
351void mmio_le_writel(uint32_t val, void *addr);
352uint8_t mmio_le_readb(void *addr);
353uint16_t mmio_le_readw(void *addr);
354uint32_t mmio_le_readl(void *addr);
355#define pci_mmio_writeb mmio_le_writeb
356#define pci_mmio_writew mmio_le_writew
357#define pci_mmio_writel mmio_le_writel
358#define pci_mmio_readb mmio_le_readb
359#define pci_mmio_readw mmio_le_readw
360#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000361void rmmio_writeb(uint8_t val, void *addr);
362void rmmio_writew(uint16_t val, void *addr);
363void rmmio_writel(uint32_t val, void *addr);
364void rmmio_le_writeb(uint8_t val, void *addr);
365void rmmio_le_writew(uint16_t val, void *addr);
366void rmmio_le_writel(uint32_t val, void *addr);
367#define pci_rmmio_writeb rmmio_le_writeb
368#define pci_rmmio_writew rmmio_le_writew
369#define pci_rmmio_writel rmmio_le_writel
370void rmmio_valb(void *addr);
371void rmmio_valw(void *addr);
372void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000373
hailfinger428f6852010-07-27 22:41:39 +0000374/* dummyflasher.c */
375#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700376int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100377void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000378void dummy_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700379
hailfinger428f6852010-07-27 22:41:39 +0000380#endif
381
382/* nic3com.c */
383#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700384int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100385extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000386#endif
387
388/* gfxnvidia.c */
389#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700390int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100391extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000392#endif
393
394/* drkaiser.c */
395#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700396int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100397extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000398#endif
399
400/* nicrealtek.c */
401#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700402int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100403extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000404#endif
405
406/* nicnatsemi.c */
407#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700408int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100409extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000410#endif
411
hailfinger7949b652011-05-08 00:24:18 +0000412/* nicintel.c */
413#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700414int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100415extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000416#endif
417
uwe6764e922010-09-03 18:21:21 +0000418/* nicintel_spi.c */
419#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700420int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100421extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000422#endif
423
hailfingerfb1f31f2010-12-03 14:48:11 +0000424/* ogp_spi.c */
425#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700426int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100427extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000428#endif
429
hailfinger935365d2011-02-04 21:37:59 +0000430/* satamv.c */
431#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700432int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100433extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000434#endif
435
hailfinger428f6852010-07-27 22:41:39 +0000436/* satasii.c */
437#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700438int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100439extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000440#endif
441
442/* atahpt.c */
443#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700444int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100445extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000446#endif
447
448/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000449#if CONFIG_FT2232_SPI == 1
450struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000451 uint16_t vendor_id;
452 uint16_t device_id;
453 int status;
454 const char *vendor_name;
455 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000456};
David Hendricksac1d25c2016-08-09 17:00:58 -0700457int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000458extern const struct usbdev_status devs_ft2232spi[];
459void print_supported_usbdevs(const struct usbdev_status *devs);
460#endif
hailfinger428f6852010-07-27 22:41:39 +0000461
462/* rayer_spi.c */
463#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700464int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000465#endif
466
467/* bitbang_spi.c */
Patrick Georgie081d5d2017-03-22 21:18:18 +0100468int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700469int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000470
471/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000472#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700473int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000474#endif
hailfinger428f6852010-07-27 22:41:39 +0000475
Anton Staafb2647882014-09-17 15:13:43 -0700476/* raiden_debug_spi.c */
477#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700478int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700479#endif
480
David Hendricks7e449602013-05-17 19:21:36 -0700481/* linux_i2c.c */
482#if CONFIG_LINUX_I2C == 1
David Hendricks93784b42016-08-09 17:00:38 -0700483int linux_i2c_shutdown(void *data);
David Hendricksac1d25c2016-08-09 17:00:58 -0700484int linux_i2c_init(void);
David Hendricks7e449602013-05-17 19:21:36 -0700485int linux_i2c_open(int bus, int addr, int force);
486void linux_i2c_close(void);
487int linux_i2c_xfer(int bus, int addr, const void *inbuf,
488 int insize, const void *outbuf, int outsize);
489#endif
490
David Hendrickscebee892015-05-23 20:30:30 -0700491/* linux_mtd.c */
492#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700493int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700494#endif
495
uwe7df6dda2011-09-03 18:37:52 +0000496/* linux_spi.c */
497#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700498int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000499#endif
500
hailfinger428f6852010-07-27 22:41:39 +0000501/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000502#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700503int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000504#endif
hailfinger428f6852010-07-27 22:41:39 +0000505
506/* flashrom.c */
507struct decode_sizes {
508 uint32_t parallel;
509 uint32_t lpc;
510 uint32_t fwh;
511 uint32_t spi;
512};
513extern struct decode_sizes max_rom_decode;
514extern int programmer_may_write;
515extern unsigned long flashbase;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700516void check_chip_supported(const struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000517int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000518char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000519
520/* layout.c */
521int show_id(uint8_t *bios, int size, int force);
522
523/* spi.c */
524enum spi_controller {
525 SPI_CONTROLLER_NONE,
526#if CONFIG_INTERNAL == 1
527#if defined(__i386__) || defined(__x86_64__)
528 SPI_CONTROLLER_ICH7,
529 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700530 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000531 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000532 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800533 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000534 SPI_CONTROLLER_SB600,
ivy_jian8e0c4e52017-08-23 09:17:56 +0800535 SPI_CONTROLLER_YANGTZE,
hailfinger428f6852010-07-27 22:41:39 +0000536 SPI_CONTROLLER_VIA,
537 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800538 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800539 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700540#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800541#if defined(__arm__)
542 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000543#endif
544#endif
545#if CONFIG_FT2232_SPI == 1
546 SPI_CONTROLLER_FT2232,
547#endif
548#if CONFIG_DUMMY == 1
549 SPI_CONTROLLER_DUMMY,
550#endif
551#if CONFIG_BUSPIRATE_SPI == 1
552 SPI_CONTROLLER_BUSPIRATE,
553#endif
Anton Staafb2647882014-09-17 15:13:43 -0700554#if CONFIG_RAIDEN_DEBUG_SPI == 1
555 SPI_CONTROLLER_RAIDEN_DEBUG,
556#endif
hailfinger428f6852010-07-27 22:41:39 +0000557#if CONFIG_DEDIPROG == 1
558 SPI_CONTROLLER_DEDIPROG,
559#endif
William A. Kennington III852ebf72017-04-05 12:16:06 -0700560#if CONFIG_BITBANG_SPI == 1
mkarcherd264e9e2011-05-11 17:07:07 +0000561 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000562#endif
uwe7df6dda2011-09-03 18:37:52 +0000563#if CONFIG_LINUX_SPI == 1
564 SPI_CONTROLLER_LINUX,
565#endif
stefanct69965b62011-09-15 23:38:14 +0000566#if CONFIG_SERPROG == 1
567 SPI_CONTROLLER_SERPROG,
568#endif
hailfinger428f6852010-07-27 22:41:39 +0000569};
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100570extern const int spi_master_count;
mkarcher8fb57592011-05-11 17:07:02 +0000571
572#define MAX_DATA_UNSPECIFIED 0
573#define MAX_DATA_READ_UNLIMITED 64 * 1024
574#define MAX_DATA_WRITE_UNLIMITED 256
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100575struct spi_master {
mkarcherd264e9e2011-05-11 17:07:07 +0000576 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000577 unsigned int max_data_read;
578 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700579 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000580 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700581 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000582
Patrick Georgie39d6442017-03-22 21:23:35 +0100583 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700584 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100585 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000586};
587
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100588extern const struct spi_master *spi_master;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700589int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000590 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700591int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
592int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100593int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100594void register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000595
596/* ichspi.c */
stefanctc035c192011-11-06 23:51:09 +0000597enum ich_chipset {
598 CHIPSET_ICH_UNKNOWN,
599 CHIPSET_ICH7 = 7,
600 CHIPSET_ICH8,
601 CHIPSET_ICH9,
602 CHIPSET_ICH10,
603 CHIPSET_5_SERIES_IBEX_PEAK,
604 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800605 CHIPSET_7_SERIES_PANTHER_POINT,
606 CHIPSET_8_SERIES_LYNX_POINT,
607 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700608 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530609 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800610 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700611 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000612};
613
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700614#if CONFIG_INTERNAL == 1
Vadim Bendebury622128c2018-06-21 15:50:28 -0700615
616/*
617 * This global variable is used to communicate the type of ICH found on the
618 * device. When running on non-intel platforms default value of
619 * CHIPSET_ICH_UNKNOWN is used.
620*/
Vadim Bendebury066143d2018-07-16 18:20:33 -0700621extern enum ich_chipset ich_generation;
622
623/*
624 * This global variable is set to indicate that the invoked flash programming
625 * command should not be executed, but just verified for validity.
626 *
627 * This is useful when one needs to determine if a certain flash erase command
628 * supported by the chip is allowed by the Intel controller on the device.
629 */
630extern int ich_dry_run;
hailfinger428f6852010-07-27 22:41:39 +0000631extern uint32_t ichspi_bbar;
632int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000633 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000634int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000635
Rong Changaaa1acf2012-06-21 19:21:18 +0800636/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700637int ene_probe_spi_flash(const char *name);
ivy_jian8e0c4e52017-08-23 09:17:56 +0800638/* amd_imc.c */
639int amd_imc_shutdown(struct pci_dev *dev);
Rong Changaaa1acf2012-06-21 19:21:18 +0800640
hailfinger2b46a862011-02-28 23:58:15 +0000641/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700642int it85xx_spi_init(struct superio s);
643int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000644
hailfinger428f6852010-07-27 22:41:39 +0000645/* it87spi.c */
646void enter_conf_mode_ite(uint16_t port);
647void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000648void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700649int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000650
hailfingere20dc562011-06-09 20:06:34 +0000651/* mcp6x_spi.c */
652int mcp6x_spi_init(int want_spi);
653
David Hendricks46d32e32011-01-19 16:01:52 -0800654/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700655int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800656
hailfinger428f6852010-07-27 22:41:39 +0000657/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000658int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000659
660/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000661int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000662#endif
663
hailfingerfe7cd9e2011-11-04 21:35:26 +0000664/* opaque.c */
665struct opaque_programmer {
666 int max_data_read;
667 int max_data_write;
668 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700669 int (*probe) (struct flashctx *flash);
670 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100671 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700672 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
673 uint8_t (*read_status) (const struct flashctx *flash);
674 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks5d481e12012-05-24 14:14:14 -0700675 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000676};
David Hendricksac1d25c2016-08-09 17:00:58 -0700677extern struct opaque_programmer *opaque_programmer;
678void register_opaque_programmer(struct opaque_programmer *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000679
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700680/* programmer.c */
681int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100682void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700683void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700684uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700685void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
686void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
687void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
688void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
689uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
690uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
691void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100692struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700693 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
694 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
695 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
696 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
697 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
698 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
699 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
700 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
701};
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100702extern const struct par_master *par_master;
703void register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700704
hailfinger428f6852010-07-27 22:41:39 +0000705/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000706#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700707int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000708void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000709#endif
hailfinger428f6852010-07-27 22:41:39 +0000710
711/* serial.c */
712#if _WIN32
713typedef HANDLE fdtype;
714#else
715typedef int fdtype;
716#endif
717
David Hendricksc801adb2010-12-09 16:58:56 -0800718/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700719int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800720
David Hendricksb907de32014-08-11 16:47:09 -0700721/* cros_ec.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700722int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700723
724/**
725 * Probe the Google Chrome OS EC device
726 *
727 * @return 0 if found correct, non-zero if not found or error
728 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700729int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700730
David Hendricksac1d25c2016-08-09 17:00:58 -0700731int cros_ec_probe_lpc(const char *name);
732int cros_ec_need_2nd_pass(void);
733int cros_ec_finish(void);
734int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800735
hailfinger428f6852010-07-27 22:41:39 +0000736void sp_flush_incoming(void);
737fdtype sp_openserport(char *dev, unsigned int baud);
738void __attribute__((noreturn)) sp_die(char *msg);
739extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000740/* expose serialport_shutdown as it's currently used by buspirate */
741int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000742int serialport_write(unsigned char *buf, unsigned int writecnt);
743int serialport_read(unsigned char *buf, unsigned int readcnt);
744
745#endif /* !__PROGRAMMER_H__ */