blob: 2efe1ffee49069559e20d41ab596255ec141a8ce [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 *
hailfinger428f6852010-07-27 22:41:39 +000019 */
20
21#ifndef __PROGRAMMER_H__
22#define __PROGRAMMER_H__ 1
23
Souvik Ghoshd75cd672016-06-17 14:21:39 -070024#include "flash.h" /* for chipaddr and flashctx */
hailfingerfe7cd9e2011-11-04 21:35:26 +000025
hailfinger428f6852010-07-27 22:41:39 +000026enum programmer {
27#if CONFIG_INTERNAL == 1
28 PROGRAMMER_INTERNAL,
29#endif
30#if CONFIG_DUMMY == 1
31 PROGRAMMER_DUMMY,
32#endif
33#if CONFIG_NIC3COM == 1
34 PROGRAMMER_NIC3COM,
35#endif
36#if CONFIG_NICREALTEK == 1
37 PROGRAMMER_NICREALTEK,
uwe6764e922010-09-03 18:21:21 +000038#endif
hailfinger428f6852010-07-27 22:41:39 +000039#if CONFIG_NICNATSEMI == 1
40 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000041#endif
hailfinger428f6852010-07-27 22:41:39 +000042#if CONFIG_GFXNVIDIA == 1
43 PROGRAMMER_GFXNVIDIA,
44#endif
45#if CONFIG_DRKAISER == 1
46 PROGRAMMER_DRKAISER,
47#endif
48#if CONFIG_SATASII == 1
49 PROGRAMMER_SATASII,
50#endif
51#if CONFIG_ATAHPT == 1
52 PROGRAMMER_ATAHPT,
53#endif
hailfinger428f6852010-07-27 22:41:39 +000054#if CONFIG_FT2232_SPI == 1
55 PROGRAMMER_FT2232_SPI,
56#endif
57#if CONFIG_SERPROG == 1
58 PROGRAMMER_SERPROG,
59#endif
60#if CONFIG_BUSPIRATE_SPI == 1
61 PROGRAMMER_BUSPIRATE_SPI,
62#endif
Anton Staafb2647882014-09-17 15:13:43 -070063#if CONFIG_RAIDEN_DEBUG_SPI == 1
64 PROGRAMMER_RAIDEN_DEBUG_SPI,
65#endif
hailfinger428f6852010-07-27 22:41:39 +000066#if CONFIG_DEDIPROG == 1
67 PROGRAMMER_DEDIPROG,
68#endif
69#if CONFIG_RAYER_SPI == 1
70 PROGRAMMER_RAYER_SPI,
71#endif
hailfinger7949b652011-05-08 00:24:18 +000072#if CONFIG_NICINTEL == 1
73 PROGRAMMER_NICINTEL,
74#endif
uwe6764e922010-09-03 18:21:21 +000075#if CONFIG_NICINTEL_SPI == 1
76 PROGRAMMER_NICINTEL_SPI,
77#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000078#if CONFIG_OGP_SPI == 1
79 PROGRAMMER_OGP_SPI,
80#endif
hailfinger935365d2011-02-04 21:37:59 +000081#if CONFIG_SATAMV == 1
82 PROGRAMMER_SATAMV,
83#endif
David Hendrickscebee892015-05-23 20:30:30 -070084#if CONFIG_LINUX_MTD == 1
85 PROGRAMMER_LINUX_MTD,
86#endif
uwe7df6dda2011-09-03 18:37:52 +000087#if CONFIG_LINUX_SPI == 1
88 PROGRAMMER_LINUX_SPI,
89#endif
hailfinger428f6852010-07-27 22:41:39 +000090 PROGRAMMER_INVALID /* This must always be the last entry. */
91};
92
David Hendricksba0827a2013-05-03 20:25:40 -070093enum alias_type {
94 ALIAS_NONE = 0, /* no alias (default) */
95 ALIAS_EC, /* embedded controller */
96 ALIAS_HOST, /* chipset / PCH / SoC / etc. */
97};
98
99struct programmer_alias {
100 const char *name;
101 enum alias_type type;
102};
103
104extern struct programmer_alias *alias;
105extern struct programmer_alias aliases[];
106
Vadim Bendebury066143d2018-07-16 18:20:33 -0700107/*
108 * This function returns 'true' if current flashrom invocation is programming
109 * the EC.
110 */
111static inline int programming_ec(void) {
112 return alias && (alias->type == ALIAS_EC);
113}
114
hailfinger428f6852010-07-27 22:41:39 +0000115struct programmer_entry {
116 const char *vendor;
117 const char *name;
118
David Hendricksac1d25c2016-08-09 17:00:58 -0700119 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000120
Patrick Georgi4befc162017-02-03 18:32:01 +0100121 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000122 void (*unmap_flash_region) (void *virt_addr, size_t len);
123
hailfinger428f6852010-07-27 22:41:39 +0000124 void (*delay) (int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800125
126 /*
127 * If set, use extra precautions such as erasing with small block sizes
128 * and verifying more rigorously. This will incur a performance penalty
129 * but is good for programming the ROM in-system on a live machine.
130 */
131 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000132};
133
134extern const struct programmer_entry programmer_table[];
135
David Hendricksac1d25c2016-08-09 17:00:58 -0700136int programmer_init(enum programmer prog, char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700137int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000138
139enum bitbang_spi_master_type {
140 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
141#if CONFIG_RAYER_SPI == 1
142 BITBANG_SPI_MASTER_RAYER,
143#endif
uwe6764e922010-09-03 18:21:21 +0000144#if CONFIG_NICINTEL_SPI == 1
145 BITBANG_SPI_MASTER_NICINTEL,
146#endif
hailfinger52384c92010-07-28 15:08:35 +0000147#if CONFIG_INTERNAL == 1
148#if defined(__i386__) || defined(__x86_64__)
149 BITBANG_SPI_MASTER_MCP,
150#endif
151#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000152#if CONFIG_OGP_SPI == 1
153 BITBANG_SPI_MASTER_OGP,
154#endif
hailfinger428f6852010-07-27 22:41:39 +0000155};
156
157struct bitbang_spi_master {
158 enum bitbang_spi_master_type type;
159
160 /* Note that CS# is active low, so val=0 means the chip is active. */
161 void (*set_cs) (int val);
162 void (*set_sck) (int val);
163 void (*set_mosi) (int val);
164 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000165 void (*request_bus) (void);
166 void (*release_bus) (void);
Patrick Georgie081d5d2017-03-22 21:18:18 +0100167
168 /* Length of half a clock period in usecs. */
169 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000170};
171
172#if CONFIG_INTERNAL == 1
173struct penable {
174 uint16_t vendor_id;
175 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000176 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000177 const char *vendor_name;
178 const char *device_name;
179 int (*doit) (struct pci_dev *dev, const char *name);
180};
181
182extern const struct penable chipset_enables[];
183
hailfingere52e9f82011-05-05 07:12:40 +0000184enum board_match_phase {
185 P1,
186 P2,
187 P3
188};
189
hailfinger4640bdb2011-08-31 16:19:50 +0000190struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000191 /* Any device, but make it sensible, like the ISA bridge. */
192 uint16_t first_vendor;
193 uint16_t first_device;
194 uint16_t first_card_vendor;
195 uint16_t first_card_device;
196
197 /* Any device, but make it sensible, like
198 * the host bridge. May be NULL.
199 */
200 uint16_t second_vendor;
201 uint16_t second_device;
202 uint16_t second_card_vendor;
203 uint16_t second_card_device;
204
stefanct6d836ba2011-05-26 01:35:19 +0000205 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000206 const char *dmi_pattern;
207
stefanct6d836ba2011-05-26 01:35:19 +0000208 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000209 const char *lb_vendor;
210 const char *lb_part;
211
hailfingere52e9f82011-05-05 07:12:40 +0000212 enum board_match_phase phase;
213
hailfinger428f6852010-07-27 22:41:39 +0000214 const char *vendor_name;
215 const char *board_name;
216
217 int max_rom_decode_parallel;
218 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000219 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000220};
221
hailfinger4640bdb2011-08-31 16:19:50 +0000222extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000223
224struct board_info {
225 const char *vendor;
226 const char *name;
227 const int working;
228#ifdef CONFIG_PRINT_WIKI
229 const char *url;
230 const char *note;
231#endif
232};
233
234extern const struct board_info boards_known[];
235extern const struct board_info laptops_known[];
236#endif
237
238/* udelay.c */
239void myusec_delay(int usecs);
240void myusec_calibrate_delay(void);
241void internal_delay(int usecs);
242
243#if NEED_PCI == 1
244/* pcidev.c */
hailfinger428f6852010-07-27 22:41:39 +0000245extern struct pci_access *pacc;
Patrick Georgi8ae16572017-03-09 15:59:25 +0100246struct dev_entry {
hailfinger428f6852010-07-27 22:41:39 +0000247 uint16_t vendor_id;
248 uint16_t device_id;
249 int status;
250 const char *vendor_name;
251 const char *device_name;
252};
Patrick Georgif776a442017-03-28 21:34:33 +0200253uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100254uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_entry *devs);
Patrick Georgi7c30fa92017-03-28 22:47:12 +0200255struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
hailfingerf31cbdc2010-11-10 15:25:18 +0000256/* rpci_write_* are reversible writes. The original PCI config space register
257 * contents will be restored on shutdown.
258 */
mkarcher08a24552010-12-26 23:55:19 +0000259int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
260int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
261int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000262#endif
263
264/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000265#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 +0100266void print_supported_pcidevs(const struct dev_entry *devs);
hailfinger428f6852010-07-27 22:41:39 +0000267#endif
268
hailfingere20dc562011-06-09 20:06:34 +0000269#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000270/* board_enable.c */
271void w836xx_ext_enter(uint16_t port);
272void w836xx_ext_leave(uint16_t port);
273int it8705f_write_enable(uint8_t port);
274uint8_t sio_read(uint16_t port, uint8_t reg);
275void sio_write(uint16_t port, uint8_t reg, uint8_t data);
276void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000277void board_handle_before_superio(void);
278void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000279int board_flash_enable(const char *vendor, const char *part);
280
281/* chipset_enable.c */
282int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800283int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000284
285/* processor_enable.c */
286int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000287#endif
hailfinger428f6852010-07-27 22:41:39 +0000288
289/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100290void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi220f4b52017-03-21 16:55:04 +0100291void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan64a4db22019-05-30 03:13:07 -0400292void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000293void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000294#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000295int setup_cpu_msr(int cpu);
296void cleanup_cpu_msr(void);
297
298/* cbtable.c */
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700299void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000300int coreboot_init(void);
301extern char *lb_part, *lb_vendor;
302extern int partvendor_from_cbtable;
303
304/* dmi.c */
305extern int has_dmi_support;
306void dmi_init(void);
307int dmi_match(const char *pattern);
308
309/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000310struct superio {
311 uint16_t vendor;
312 uint16_t port;
313 uint16_t model;
314};
hailfinger94e090c2011-04-27 14:34:08 +0000315extern struct superio superios[];
316extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000317#define SUPERIO_VENDOR_NONE 0x0
318#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000319#endif
320#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000321struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000322struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000323struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
324struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
325 uint16_t card_vendor, uint16_t card_device);
326#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100327int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000328#if CONFIG_INTERNAL == 1
329extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000330extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000331extern int force_boardenable;
332extern int force_boardmismatch;
333void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000334int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000335extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700336int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000337#endif
338
339/* hwaccess.c */
340void mmio_writeb(uint8_t val, void *addr);
341void mmio_writew(uint16_t val, void *addr);
342void mmio_writel(uint32_t val, void *addr);
343uint8_t mmio_readb(void *addr);
344uint16_t mmio_readw(void *addr);
345uint32_t mmio_readl(void *addr);
346void mmio_le_writeb(uint8_t val, void *addr);
347void mmio_le_writew(uint16_t val, void *addr);
348void mmio_le_writel(uint32_t val, void *addr);
349uint8_t mmio_le_readb(void *addr);
350uint16_t mmio_le_readw(void *addr);
351uint32_t mmio_le_readl(void *addr);
352#define pci_mmio_writeb mmio_le_writeb
353#define pci_mmio_writew mmio_le_writew
354#define pci_mmio_writel mmio_le_writel
355#define pci_mmio_readb mmio_le_readb
356#define pci_mmio_readw mmio_le_readw
357#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000358void rmmio_writeb(uint8_t val, void *addr);
359void rmmio_writew(uint16_t val, void *addr);
360void rmmio_writel(uint32_t val, void *addr);
361void rmmio_le_writeb(uint8_t val, void *addr);
362void rmmio_le_writew(uint16_t val, void *addr);
363void rmmio_le_writel(uint32_t val, void *addr);
364#define pci_rmmio_writeb rmmio_le_writeb
365#define pci_rmmio_writew rmmio_le_writew
366#define pci_rmmio_writel rmmio_le_writel
367void rmmio_valb(void *addr);
368void rmmio_valw(void *addr);
369void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000370
hailfinger428f6852010-07-27 22:41:39 +0000371/* dummyflasher.c */
372#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700373int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100374void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000375void dummy_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700376
hailfinger428f6852010-07-27 22:41:39 +0000377#endif
378
379/* nic3com.c */
380#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700381int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100382extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000383#endif
384
385/* gfxnvidia.c */
386#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700387int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100388extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000389#endif
390
391/* drkaiser.c */
392#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700393int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100394extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000395#endif
396
397/* nicrealtek.c */
398#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700399int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100400extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000401#endif
402
403/* nicnatsemi.c */
404#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700405int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100406extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000407#endif
408
hailfinger7949b652011-05-08 00:24:18 +0000409/* nicintel.c */
410#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700411int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100412extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000413#endif
414
uwe6764e922010-09-03 18:21:21 +0000415/* nicintel_spi.c */
416#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700417int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100418extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000419#endif
420
hailfingerfb1f31f2010-12-03 14:48:11 +0000421/* ogp_spi.c */
422#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700423int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100424extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000425#endif
426
hailfinger935365d2011-02-04 21:37:59 +0000427/* satamv.c */
428#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700429int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100430extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000431#endif
432
hailfinger428f6852010-07-27 22:41:39 +0000433/* satasii.c */
434#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700435int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100436extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000437#endif
438
439/* atahpt.c */
440#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700441int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100442extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000443#endif
444
445/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000446#if CONFIG_FT2232_SPI == 1
447struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000448 uint16_t vendor_id;
449 uint16_t device_id;
450 int status;
451 const char *vendor_name;
452 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000453};
David Hendricksac1d25c2016-08-09 17:00:58 -0700454int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000455extern const struct usbdev_status devs_ft2232spi[];
456void print_supported_usbdevs(const struct usbdev_status *devs);
457#endif
hailfinger428f6852010-07-27 22:41:39 +0000458
459/* rayer_spi.c */
460#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700461int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000462#endif
463
464/* bitbang_spi.c */
Patrick Georgie081d5d2017-03-22 21:18:18 +0100465int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700466int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000467
468/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000469#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700470int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000471#endif
hailfinger428f6852010-07-27 22:41:39 +0000472
Anton Staafb2647882014-09-17 15:13:43 -0700473/* raiden_debug_spi.c */
474#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700475int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700476#endif
477
David Hendricks7e449602013-05-17 19:21:36 -0700478/* linux_i2c.c */
479#if CONFIG_LINUX_I2C == 1
David Hendricks93784b42016-08-09 17:00:38 -0700480int linux_i2c_shutdown(void *data);
David Hendricksac1d25c2016-08-09 17:00:58 -0700481int linux_i2c_init(void);
David Hendricks7e449602013-05-17 19:21:36 -0700482int linux_i2c_open(int bus, int addr, int force);
483void linux_i2c_close(void);
484int linux_i2c_xfer(int bus, int addr, const void *inbuf,
485 int insize, const void *outbuf, int outsize);
486#endif
487
David Hendrickscebee892015-05-23 20:30:30 -0700488/* linux_mtd.c */
489#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700490int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700491#endif
492
uwe7df6dda2011-09-03 18:37:52 +0000493/* linux_spi.c */
494#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700495int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000496#endif
497
hailfinger428f6852010-07-27 22:41:39 +0000498/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000499#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700500int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000501#endif
hailfinger428f6852010-07-27 22:41:39 +0000502
503/* flashrom.c */
504struct decode_sizes {
505 uint32_t parallel;
506 uint32_t lpc;
507 uint32_t fwh;
508 uint32_t spi;
509};
510extern struct decode_sizes max_rom_decode;
511extern int programmer_may_write;
512extern unsigned long flashbase;
hailfinger428f6852010-07-27 22:41:39 +0000513int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000514char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000515
516/* layout.c */
517int show_id(uint8_t *bios, int size, int force);
518
519/* spi.c */
520enum spi_controller {
521 SPI_CONTROLLER_NONE,
522#if CONFIG_INTERNAL == 1
523#if defined(__i386__) || defined(__x86_64__)
524 SPI_CONTROLLER_ICH7,
525 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700526 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000527 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000528 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800529 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000530 SPI_CONTROLLER_SB600,
ivy_jian8e0c4e52017-08-23 09:17:56 +0800531 SPI_CONTROLLER_YANGTZE,
hailfinger428f6852010-07-27 22:41:39 +0000532 SPI_CONTROLLER_VIA,
533 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800534 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800535 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700536#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800537#if defined(__arm__)
538 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000539#endif
540#endif
541#if CONFIG_FT2232_SPI == 1
542 SPI_CONTROLLER_FT2232,
543#endif
544#if CONFIG_DUMMY == 1
545 SPI_CONTROLLER_DUMMY,
546#endif
547#if CONFIG_BUSPIRATE_SPI == 1
548 SPI_CONTROLLER_BUSPIRATE,
549#endif
Anton Staafb2647882014-09-17 15:13:43 -0700550#if CONFIG_RAIDEN_DEBUG_SPI == 1
551 SPI_CONTROLLER_RAIDEN_DEBUG,
552#endif
hailfinger428f6852010-07-27 22:41:39 +0000553#if CONFIG_DEDIPROG == 1
554 SPI_CONTROLLER_DEDIPROG,
555#endif
William A. Kennington III852ebf72017-04-05 12:16:06 -0700556#if CONFIG_BITBANG_SPI == 1
mkarcherd264e9e2011-05-11 17:07:07 +0000557 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000558#endif
uwe7df6dda2011-09-03 18:37:52 +0000559#if CONFIG_LINUX_SPI == 1
560 SPI_CONTROLLER_LINUX,
561#endif
stefanct69965b62011-09-15 23:38:14 +0000562#if CONFIG_SERPROG == 1
563 SPI_CONTROLLER_SERPROG,
564#endif
hailfinger428f6852010-07-27 22:41:39 +0000565};
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100566extern const int spi_master_count;
mkarcher8fb57592011-05-11 17:07:02 +0000567
568#define MAX_DATA_UNSPECIFIED 0
569#define MAX_DATA_READ_UNLIMITED 64 * 1024
570#define MAX_DATA_WRITE_UNLIMITED 256
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100571struct spi_master {
mkarcherd264e9e2011-05-11 17:07:07 +0000572 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000573 unsigned int max_data_read;
574 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700575 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000576 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700577 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000578
Patrick Georgie39d6442017-03-22 21:23:35 +0100579 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700580 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100581 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000582};
583
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100584extern const struct spi_master *spi_master;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700585int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000586 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700587int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
588int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100589int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100590void register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000591
592/* ichspi.c */
stefanctc035c192011-11-06 23:51:09 +0000593enum ich_chipset {
594 CHIPSET_ICH_UNKNOWN,
595 CHIPSET_ICH7 = 7,
596 CHIPSET_ICH8,
597 CHIPSET_ICH9,
598 CHIPSET_ICH10,
599 CHIPSET_5_SERIES_IBEX_PEAK,
600 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800601 CHIPSET_7_SERIES_PANTHER_POINT,
602 CHIPSET_8_SERIES_LYNX_POINT,
603 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700604 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530605 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800606 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700607 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000608};
609
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700610#if CONFIG_INTERNAL == 1
Vadim Bendebury622128c2018-06-21 15:50:28 -0700611
612/*
613 * This global variable is used to communicate the type of ICH found on the
614 * device. When running on non-intel platforms default value of
615 * CHIPSET_ICH_UNKNOWN is used.
616*/
Vadim Bendebury066143d2018-07-16 18:20:33 -0700617extern enum ich_chipset ich_generation;
618
619/*
620 * This global variable is set to indicate that the invoked flash programming
621 * command should not be executed, but just verified for validity.
622 *
623 * This is useful when one needs to determine if a certain flash erase command
624 * supported by the chip is allowed by the Intel controller on the device.
625 */
626extern int ich_dry_run;
hailfinger428f6852010-07-27 22:41:39 +0000627extern uint32_t ichspi_bbar;
628int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000629 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000630int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000631
Rong Changaaa1acf2012-06-21 19:21:18 +0800632/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700633int ene_probe_spi_flash(const char *name);
ivy_jian8e0c4e52017-08-23 09:17:56 +0800634/* amd_imc.c */
635int amd_imc_shutdown(struct pci_dev *dev);
Rong Changaaa1acf2012-06-21 19:21:18 +0800636
hailfinger2b46a862011-02-28 23:58:15 +0000637/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700638int it85xx_spi_init(struct superio s);
639int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000640
hailfinger428f6852010-07-27 22:41:39 +0000641/* it87spi.c */
642void enter_conf_mode_ite(uint16_t port);
643void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000644void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700645int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000646
hailfingere20dc562011-06-09 20:06:34 +0000647/* mcp6x_spi.c */
648int mcp6x_spi_init(int want_spi);
649
David Hendricks46d32e32011-01-19 16:01:52 -0800650/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700651int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800652
hailfinger428f6852010-07-27 22:41:39 +0000653/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000654int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000655
656/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000657int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000658#endif
659
hailfingerfe7cd9e2011-11-04 21:35:26 +0000660/* opaque.c */
661struct opaque_programmer {
662 int max_data_read;
663 int max_data_write;
664 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700665 int (*probe) (struct flashctx *flash);
666 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100667 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700668 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
669 uint8_t (*read_status) (const struct flashctx *flash);
670 int (*write_status) (const struct flashctx *flash, int status);
Duncan Laurie25a4ca22019-04-25 12:08:52 -0700671 int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
David Hendricks5d481e12012-05-24 14:14:14 -0700672 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000673};
David Hendricksac1d25c2016-08-09 17:00:58 -0700674extern struct opaque_programmer *opaque_programmer;
675void register_opaque_programmer(struct opaque_programmer *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000676
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700677/* programmer.c */
678int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100679void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700680void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700681uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700682void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
683void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
684void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
685void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
686uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
687uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
688void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100689struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700690 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
691 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
692 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
693 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
694 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
695 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
696 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
697 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
698};
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100699extern const struct par_master *par_master;
700void register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700701
hailfinger428f6852010-07-27 22:41:39 +0000702/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000703#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700704int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000705void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000706#endif
hailfinger428f6852010-07-27 22:41:39 +0000707
708/* serial.c */
709#if _WIN32
710typedef HANDLE fdtype;
711#else
712typedef int fdtype;
713#endif
714
David Hendricksc801adb2010-12-09 16:58:56 -0800715/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700716int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800717
David Hendricksb907de32014-08-11 16:47:09 -0700718/* cros_ec.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700719int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700720
721/**
722 * Probe the Google Chrome OS EC device
723 *
724 * @return 0 if found correct, non-zero if not found or error
725 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700726int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700727
David Hendricksac1d25c2016-08-09 17:00:58 -0700728int cros_ec_probe_lpc(const char *name);
729int cros_ec_need_2nd_pass(void);
730int cros_ec_finish(void);
731int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800732
hailfinger428f6852010-07-27 22:41:39 +0000733void sp_flush_incoming(void);
734fdtype sp_openserport(char *dev, unsigned int baud);
735void __attribute__((noreturn)) sp_die(char *msg);
736extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000737/* expose serialport_shutdown as it's currently used by buspirate */
738int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000739int serialport_write(unsigned char *buf, unsigned int writecnt);
740int serialport_read(unsigned char *buf, unsigned int readcnt);
741
Edward O'Callaghana88395f2019-02-27 18:44:04 +1100742/* usbdev.c */
743struct libusb_device_handle;
744struct libusb_context;
745struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
746 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno);
747struct libusb_device_handle *usb_dev_get_by_vid_pid_number(
748 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
749
hailfinger428f6852010-07-27 22:41:39 +0000750#endif /* !__PROGRAMMER_H__ */