blob: 5f595d13a681eba5d2131f30b782b682073d8269 [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);
Edward O'Callaghanb2878982019-05-30 03:44:32 -0400294void physunmap_unaligned(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000295#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000296int setup_cpu_msr(int cpu);
297void cleanup_cpu_msr(void);
298
299/* cbtable.c */
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700300void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000301int coreboot_init(void);
302extern char *lb_part, *lb_vendor;
303extern int partvendor_from_cbtable;
304
305/* dmi.c */
306extern int has_dmi_support;
307void dmi_init(void);
308int dmi_match(const char *pattern);
309
310/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000311struct superio {
312 uint16_t vendor;
313 uint16_t port;
314 uint16_t model;
315};
hailfinger94e090c2011-04-27 14:34:08 +0000316extern struct superio superios[];
317extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000318#define SUPERIO_VENDOR_NONE 0x0
319#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000320#endif
321#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000322struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000323struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000324struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
325struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
326 uint16_t card_vendor, uint16_t card_device);
327#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100328int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000329#if CONFIG_INTERNAL == 1
330extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000331extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000332extern int force_boardenable;
333extern int force_boardmismatch;
334void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000335int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000336extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700337int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000338#endif
339
340/* hwaccess.c */
341void mmio_writeb(uint8_t val, void *addr);
342void mmio_writew(uint16_t val, void *addr);
343void mmio_writel(uint32_t val, void *addr);
344uint8_t mmio_readb(void *addr);
345uint16_t mmio_readw(void *addr);
346uint32_t mmio_readl(void *addr);
347void mmio_le_writeb(uint8_t val, void *addr);
348void mmio_le_writew(uint16_t val, void *addr);
349void mmio_le_writel(uint32_t val, void *addr);
350uint8_t mmio_le_readb(void *addr);
351uint16_t mmio_le_readw(void *addr);
352uint32_t mmio_le_readl(void *addr);
353#define pci_mmio_writeb mmio_le_writeb
354#define pci_mmio_writew mmio_le_writew
355#define pci_mmio_writel mmio_le_writel
356#define pci_mmio_readb mmio_le_readb
357#define pci_mmio_readw mmio_le_readw
358#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000359void rmmio_writeb(uint8_t val, void *addr);
360void rmmio_writew(uint16_t val, void *addr);
361void rmmio_writel(uint32_t val, void *addr);
362void rmmio_le_writeb(uint8_t val, void *addr);
363void rmmio_le_writew(uint16_t val, void *addr);
364void rmmio_le_writel(uint32_t val, void *addr);
365#define pci_rmmio_writeb rmmio_le_writeb
366#define pci_rmmio_writew rmmio_le_writew
367#define pci_rmmio_writel rmmio_le_writel
368void rmmio_valb(void *addr);
369void rmmio_valw(void *addr);
370void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000371
hailfinger428f6852010-07-27 22:41:39 +0000372/* dummyflasher.c */
373#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700374int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100375void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000376void dummy_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700377
hailfinger428f6852010-07-27 22:41:39 +0000378#endif
379
380/* nic3com.c */
381#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700382int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100383extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000384#endif
385
386/* gfxnvidia.c */
387#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700388int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100389extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000390#endif
391
392/* drkaiser.c */
393#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700394int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100395extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000396#endif
397
398/* nicrealtek.c */
399#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700400int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100401extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000402#endif
403
404/* nicnatsemi.c */
405#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700406int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100407extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000408#endif
409
hailfinger7949b652011-05-08 00:24:18 +0000410/* nicintel.c */
411#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700412int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100413extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000414#endif
415
uwe6764e922010-09-03 18:21:21 +0000416/* nicintel_spi.c */
417#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700418int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100419extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000420#endif
421
hailfingerfb1f31f2010-12-03 14:48:11 +0000422/* ogp_spi.c */
423#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700424int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100425extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000426#endif
427
hailfinger935365d2011-02-04 21:37:59 +0000428/* satamv.c */
429#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700430int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100431extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000432#endif
433
hailfinger428f6852010-07-27 22:41:39 +0000434/* satasii.c */
435#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700436int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100437extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000438#endif
439
440/* atahpt.c */
441#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700442int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100443extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000444#endif
445
446/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000447#if CONFIG_FT2232_SPI == 1
448struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000449 uint16_t vendor_id;
450 uint16_t device_id;
451 int status;
452 const char *vendor_name;
453 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000454};
David Hendricksac1d25c2016-08-09 17:00:58 -0700455int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000456extern const struct usbdev_status devs_ft2232spi[];
457void print_supported_usbdevs(const struct usbdev_status *devs);
458#endif
hailfinger428f6852010-07-27 22:41:39 +0000459
460/* rayer_spi.c */
461#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700462int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000463#endif
464
465/* bitbang_spi.c */
Patrick Georgie081d5d2017-03-22 21:18:18 +0100466int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700467int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000468
469/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000470#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700471int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000472#endif
hailfinger428f6852010-07-27 22:41:39 +0000473
Anton Staafb2647882014-09-17 15:13:43 -0700474/* raiden_debug_spi.c */
475#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700476int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700477#endif
478
David Hendricks7e449602013-05-17 19:21:36 -0700479/* linux_i2c.c */
480#if CONFIG_LINUX_I2C == 1
David Hendricks93784b42016-08-09 17:00:38 -0700481int linux_i2c_shutdown(void *data);
David Hendricksac1d25c2016-08-09 17:00:58 -0700482int linux_i2c_init(void);
David Hendricks7e449602013-05-17 19:21:36 -0700483int linux_i2c_open(int bus, int addr, int force);
484void linux_i2c_close(void);
485int linux_i2c_xfer(int bus, int addr, const void *inbuf,
486 int insize, const void *outbuf, int outsize);
487#endif
488
David Hendrickscebee892015-05-23 20:30:30 -0700489/* linux_mtd.c */
490#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700491int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700492#endif
493
uwe7df6dda2011-09-03 18:37:52 +0000494/* linux_spi.c */
495#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700496int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000497#endif
498
hailfinger428f6852010-07-27 22:41:39 +0000499/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000500#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700501int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000502#endif
hailfinger428f6852010-07-27 22:41:39 +0000503
504/* flashrom.c */
505struct decode_sizes {
506 uint32_t parallel;
507 uint32_t lpc;
508 uint32_t fwh;
509 uint32_t spi;
510};
511extern struct decode_sizes max_rom_decode;
512extern int programmer_may_write;
513extern unsigned long flashbase;
hailfinger428f6852010-07-27 22:41:39 +0000514int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000515char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000516
517/* layout.c */
518int show_id(uint8_t *bios, int size, int force);
519
520/* spi.c */
521enum spi_controller {
522 SPI_CONTROLLER_NONE,
523#if CONFIG_INTERNAL == 1
524#if defined(__i386__) || defined(__x86_64__)
525 SPI_CONTROLLER_ICH7,
526 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700527 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000528 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000529 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800530 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000531 SPI_CONTROLLER_SB600,
ivy_jian8e0c4e52017-08-23 09:17:56 +0800532 SPI_CONTROLLER_YANGTZE,
hailfinger428f6852010-07-27 22:41:39 +0000533 SPI_CONTROLLER_VIA,
534 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800535 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800536 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700537#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800538#if defined(__arm__)
539 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000540#endif
541#endif
542#if CONFIG_FT2232_SPI == 1
543 SPI_CONTROLLER_FT2232,
544#endif
545#if CONFIG_DUMMY == 1
546 SPI_CONTROLLER_DUMMY,
547#endif
548#if CONFIG_BUSPIRATE_SPI == 1
549 SPI_CONTROLLER_BUSPIRATE,
550#endif
Anton Staafb2647882014-09-17 15:13:43 -0700551#if CONFIG_RAIDEN_DEBUG_SPI == 1
552 SPI_CONTROLLER_RAIDEN_DEBUG,
553#endif
hailfinger428f6852010-07-27 22:41:39 +0000554#if CONFIG_DEDIPROG == 1
555 SPI_CONTROLLER_DEDIPROG,
556#endif
William A. Kennington III852ebf72017-04-05 12:16:06 -0700557#if CONFIG_BITBANG_SPI == 1
mkarcherd264e9e2011-05-11 17:07:07 +0000558 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000559#endif
uwe7df6dda2011-09-03 18:37:52 +0000560#if CONFIG_LINUX_SPI == 1
561 SPI_CONTROLLER_LINUX,
562#endif
stefanct69965b62011-09-15 23:38:14 +0000563#if CONFIG_SERPROG == 1
564 SPI_CONTROLLER_SERPROG,
565#endif
hailfinger428f6852010-07-27 22:41:39 +0000566};
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100567extern const int spi_master_count;
mkarcher8fb57592011-05-11 17:07:02 +0000568
569#define MAX_DATA_UNSPECIFIED 0
570#define MAX_DATA_READ_UNLIMITED 64 * 1024
571#define MAX_DATA_WRITE_UNLIMITED 256
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100572struct spi_master {
mkarcherd264e9e2011-05-11 17:07:07 +0000573 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000574 unsigned int max_data_read;
575 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700576 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000577 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700578 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000579
Patrick Georgie39d6442017-03-22 21:23:35 +0100580 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700581 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100582 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000583};
584
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100585extern const struct spi_master *spi_master;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700586int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000587 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700588int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
589int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100590int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100591void register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000592
593/* ichspi.c */
stefanctc035c192011-11-06 23:51:09 +0000594enum ich_chipset {
595 CHIPSET_ICH_UNKNOWN,
596 CHIPSET_ICH7 = 7,
597 CHIPSET_ICH8,
598 CHIPSET_ICH9,
599 CHIPSET_ICH10,
600 CHIPSET_5_SERIES_IBEX_PEAK,
601 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800602 CHIPSET_7_SERIES_PANTHER_POINT,
603 CHIPSET_8_SERIES_LYNX_POINT,
604 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700605 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530606 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800607 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700608 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000609};
610
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700611#if CONFIG_INTERNAL == 1
Vadim Bendebury622128c2018-06-21 15:50:28 -0700612
613/*
614 * This global variable is used to communicate the type of ICH found on the
615 * device. When running on non-intel platforms default value of
616 * CHIPSET_ICH_UNKNOWN is used.
617*/
Vadim Bendebury066143d2018-07-16 18:20:33 -0700618extern enum ich_chipset ich_generation;
619
620/*
621 * This global variable is set to indicate that the invoked flash programming
622 * command should not be executed, but just verified for validity.
623 *
624 * This is useful when one needs to determine if a certain flash erase command
625 * supported by the chip is allowed by the Intel controller on the device.
626 */
627extern int ich_dry_run;
hailfinger428f6852010-07-27 22:41:39 +0000628extern uint32_t ichspi_bbar;
629int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000630 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000631int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000632
Rong Changaaa1acf2012-06-21 19:21:18 +0800633/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700634int ene_probe_spi_flash(const char *name);
ivy_jian8e0c4e52017-08-23 09:17:56 +0800635/* amd_imc.c */
636int amd_imc_shutdown(struct pci_dev *dev);
Rong Changaaa1acf2012-06-21 19:21:18 +0800637
hailfinger2b46a862011-02-28 23:58:15 +0000638/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700639int it85xx_spi_init(struct superio s);
640int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000641
hailfinger428f6852010-07-27 22:41:39 +0000642/* it87spi.c */
643void enter_conf_mode_ite(uint16_t port);
644void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000645void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700646int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000647
hailfingere20dc562011-06-09 20:06:34 +0000648/* mcp6x_spi.c */
649int mcp6x_spi_init(int want_spi);
650
David Hendricks46d32e32011-01-19 16:01:52 -0800651/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700652int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800653
hailfinger428f6852010-07-27 22:41:39 +0000654/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000655int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000656
657/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000658int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000659#endif
660
hailfingerfe7cd9e2011-11-04 21:35:26 +0000661/* opaque.c */
662struct opaque_programmer {
663 int max_data_read;
664 int max_data_write;
665 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700666 int (*probe) (struct flashctx *flash);
667 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100668 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700669 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
670 uint8_t (*read_status) (const struct flashctx *flash);
671 int (*write_status) (const struct flashctx *flash, int status);
Duncan Laurie25a4ca22019-04-25 12:08:52 -0700672 int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
David Hendricks5d481e12012-05-24 14:14:14 -0700673 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000674};
David Hendricksac1d25c2016-08-09 17:00:58 -0700675extern struct opaque_programmer *opaque_programmer;
676void register_opaque_programmer(struct opaque_programmer *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000677
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700678/* programmer.c */
679int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100680void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700681void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700682uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700683void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
684void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
685void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
686void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
687uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
688uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
689void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100690struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700691 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
692 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
693 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
694 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
695 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
696 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
697 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
698 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
699};
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100700extern const struct par_master *par_master;
701void register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700702
hailfinger428f6852010-07-27 22:41:39 +0000703/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000704#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700705int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000706void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000707#endif
hailfinger428f6852010-07-27 22:41:39 +0000708
709/* serial.c */
710#if _WIN32
711typedef HANDLE fdtype;
712#else
713typedef int fdtype;
714#endif
715
David Hendricksc801adb2010-12-09 16:58:56 -0800716/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700717int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800718
David Hendricksb907de32014-08-11 16:47:09 -0700719/* cros_ec.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700720int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700721
722/**
723 * Probe the Google Chrome OS EC device
724 *
725 * @return 0 if found correct, non-zero if not found or error
726 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700727int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700728
David Hendricksac1d25c2016-08-09 17:00:58 -0700729int cros_ec_probe_lpc(const char *name);
730int cros_ec_need_2nd_pass(void);
731int cros_ec_finish(void);
732int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800733
hailfinger428f6852010-07-27 22:41:39 +0000734void sp_flush_incoming(void);
735fdtype sp_openserport(char *dev, unsigned int baud);
736void __attribute__((noreturn)) sp_die(char *msg);
737extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000738/* expose serialport_shutdown as it's currently used by buspirate */
739int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000740int serialport_write(unsigned char *buf, unsigned int writecnt);
741int serialport_read(unsigned char *buf, unsigned int readcnt);
742
Edward O'Callaghana88395f2019-02-27 18:44:04 +1100743/* usbdev.c */
744struct libusb_device_handle;
745struct libusb_context;
746struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
747 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno);
748struct libusb_device_handle *usb_dev_get_by_vid_pid_number(
749 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
750
hailfinger428f6852010-07-27 22:41:39 +0000751#endif /* !__PROGRAMMER_H__ */