blob: 1aed65cbcaa78b6f952ca4d33053c6cde95f8c77 [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.
hailfinger428f6852010-07-27 22:41:39 +000018 */
19
20#ifndef __PROGRAMMER_H__
21#define __PROGRAMMER_H__ 1
22
Edward O'Callaghana6673bd2019-06-24 15:22:28 +100023#include <stdint.h>
24
Souvik Ghoshd75cd672016-06-17 14:21:39 -070025#include "flash.h" /* for chipaddr and flashctx */
hailfingerfe7cd9e2011-11-04 21:35:26 +000026
hailfinger428f6852010-07-27 22:41:39 +000027enum programmer {
28#if CONFIG_INTERNAL == 1
29 PROGRAMMER_INTERNAL,
30#endif
31#if CONFIG_DUMMY == 1
32 PROGRAMMER_DUMMY,
33#endif
34#if CONFIG_NIC3COM == 1
35 PROGRAMMER_NIC3COM,
36#endif
37#if CONFIG_NICREALTEK == 1
38 PROGRAMMER_NICREALTEK,
uwe6764e922010-09-03 18:21:21 +000039#endif
hailfinger428f6852010-07-27 22:41:39 +000040#if CONFIG_NICNATSEMI == 1
41 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000042#endif
hailfinger428f6852010-07-27 22:41:39 +000043#if CONFIG_GFXNVIDIA == 1
44 PROGRAMMER_GFXNVIDIA,
45#endif
46#if CONFIG_DRKAISER == 1
47 PROGRAMMER_DRKAISER,
48#endif
49#if CONFIG_SATASII == 1
50 PROGRAMMER_SATASII,
51#endif
52#if CONFIG_ATAHPT == 1
53 PROGRAMMER_ATAHPT,
54#endif
hailfinger428f6852010-07-27 22:41:39 +000055#if CONFIG_FT2232_SPI == 1
56 PROGRAMMER_FT2232_SPI,
57#endif
58#if CONFIG_SERPROG == 1
59 PROGRAMMER_SERPROG,
60#endif
61#if CONFIG_BUSPIRATE_SPI == 1
62 PROGRAMMER_BUSPIRATE_SPI,
63#endif
Anton Staafb2647882014-09-17 15:13:43 -070064#if CONFIG_RAIDEN_DEBUG_SPI == 1
65 PROGRAMMER_RAIDEN_DEBUG_SPI,
66#endif
hailfinger428f6852010-07-27 22:41:39 +000067#if CONFIG_DEDIPROG == 1
68 PROGRAMMER_DEDIPROG,
69#endif
70#if CONFIG_RAYER_SPI == 1
71 PROGRAMMER_RAYER_SPI,
72#endif
hailfinger7949b652011-05-08 00:24:18 +000073#if CONFIG_NICINTEL == 1
74 PROGRAMMER_NICINTEL,
75#endif
uwe6764e922010-09-03 18:21:21 +000076#if CONFIG_NICINTEL_SPI == 1
77 PROGRAMMER_NICINTEL_SPI,
78#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000079#if CONFIG_OGP_SPI == 1
80 PROGRAMMER_OGP_SPI,
81#endif
hailfinger935365d2011-02-04 21:37:59 +000082#if CONFIG_SATAMV == 1
83 PROGRAMMER_SATAMV,
84#endif
David Hendrickscebee892015-05-23 20:30:30 -070085#if CONFIG_LINUX_MTD == 1
86 PROGRAMMER_LINUX_MTD,
87#endif
uwe7df6dda2011-09-03 18:37:52 +000088#if CONFIG_LINUX_SPI == 1
89 PROGRAMMER_LINUX_SPI,
90#endif
hailfinger428f6852010-07-27 22:41:39 +000091 PROGRAMMER_INVALID /* This must always be the last entry. */
92};
93
David Hendricksba0827a2013-05-03 20:25:40 -070094enum alias_type {
95 ALIAS_NONE = 0, /* no alias (default) */
96 ALIAS_EC, /* embedded controller */
97 ALIAS_HOST, /* chipset / PCH / SoC / etc. */
98};
99
100struct programmer_alias {
101 const char *name;
102 enum alias_type type;
103};
104
105extern struct programmer_alias *alias;
106extern struct programmer_alias aliases[];
107
Vadim Bendebury066143d2018-07-16 18:20:33 -0700108/*
109 * This function returns 'true' if current flashrom invocation is programming
110 * the EC.
111 */
112static inline int programming_ec(void) {
113 return alias && (alias->type == ALIAS_EC);
114}
115
hailfinger428f6852010-07-27 22:41:39 +0000116struct programmer_entry {
117 const char *vendor;
118 const char *name;
119
David Hendricksac1d25c2016-08-09 17:00:58 -0700120 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000121
Patrick Georgi4befc162017-02-03 18:32:01 +0100122 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000123 void (*unmap_flash_region) (void *virt_addr, size_t len);
124
hailfinger428f6852010-07-27 22:41:39 +0000125 void (*delay) (int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800126
127 /*
128 * If set, use extra precautions such as erasing with small block sizes
129 * and verifying more rigorously. This will incur a performance penalty
130 * but is good for programming the ROM in-system on a live machine.
131 */
132 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000133};
134
135extern const struct programmer_entry programmer_table[];
136
David Hendricksac1d25c2016-08-09 17:00:58 -0700137int programmer_init(enum programmer prog, char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700138int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000139
140enum bitbang_spi_master_type {
141 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
142#if CONFIG_RAYER_SPI == 1
143 BITBANG_SPI_MASTER_RAYER,
144#endif
uwe6764e922010-09-03 18:21:21 +0000145#if CONFIG_NICINTEL_SPI == 1
146 BITBANG_SPI_MASTER_NICINTEL,
147#endif
hailfinger52384c92010-07-28 15:08:35 +0000148#if CONFIG_INTERNAL == 1
149#if defined(__i386__) || defined(__x86_64__)
150 BITBANG_SPI_MASTER_MCP,
151#endif
152#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000153#if CONFIG_OGP_SPI == 1
154 BITBANG_SPI_MASTER_OGP,
155#endif
hailfinger428f6852010-07-27 22:41:39 +0000156};
157
158struct bitbang_spi_master {
159 enum bitbang_spi_master_type type;
160
161 /* Note that CS# is active low, so val=0 means the chip is active. */
162 void (*set_cs) (int val);
163 void (*set_sck) (int val);
164 void (*set_mosi) (int val);
165 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000166 void (*request_bus) (void);
167 void (*release_bus) (void);
Patrick Georgie081d5d2017-03-22 21:18:18 +0100168
169 /* Length of half a clock period in usecs. */
170 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000171};
172
173#if CONFIG_INTERNAL == 1
Mayur Panchalf4796862019-08-05 15:46:12 +1000174struct pci_dev;
hailfinger428f6852010-07-27 22:41:39 +0000175struct penable {
176 uint16_t vendor_id;
177 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000178 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000179 const char *vendor_name;
180 const char *device_name;
181 int (*doit) (struct pci_dev *dev, const char *name);
182};
183
184extern const struct penable chipset_enables[];
185
hailfingere52e9f82011-05-05 07:12:40 +0000186enum board_match_phase {
187 P1,
188 P2,
189 P3
190};
191
hailfinger4640bdb2011-08-31 16:19:50 +0000192struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000193 /* Any device, but make it sensible, like the ISA bridge. */
194 uint16_t first_vendor;
195 uint16_t first_device;
196 uint16_t first_card_vendor;
197 uint16_t first_card_device;
198
199 /* Any device, but make it sensible, like
200 * the host bridge. May be NULL.
201 */
202 uint16_t second_vendor;
203 uint16_t second_device;
204 uint16_t second_card_vendor;
205 uint16_t second_card_device;
206
stefanct6d836ba2011-05-26 01:35:19 +0000207 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000208 const char *dmi_pattern;
209
stefanct6d836ba2011-05-26 01:35:19 +0000210 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000211 const char *lb_vendor;
212 const char *lb_part;
213
hailfingere52e9f82011-05-05 07:12:40 +0000214 enum board_match_phase phase;
215
hailfinger428f6852010-07-27 22:41:39 +0000216 const char *vendor_name;
217 const char *board_name;
218
219 int max_rom_decode_parallel;
220 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000221 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000222};
223
hailfinger4640bdb2011-08-31 16:19:50 +0000224extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000225
226struct board_info {
227 const char *vendor;
228 const char *name;
229 const int working;
230#ifdef CONFIG_PRINT_WIKI
231 const char *url;
232 const char *note;
233#endif
234};
235
236extern const struct board_info boards_known[];
237extern const struct board_info laptops_known[];
238#endif
239
240/* udelay.c */
241void myusec_delay(int usecs);
242void myusec_calibrate_delay(void);
243void internal_delay(int usecs);
244
245#if NEED_PCI == 1
246/* pcidev.c */
hailfinger428f6852010-07-27 22:41:39 +0000247extern struct pci_access *pacc;
Patrick Georgi8ae16572017-03-09 15:59:25 +0100248struct dev_entry {
hailfinger428f6852010-07-27 22:41:39 +0000249 uint16_t vendor_id;
250 uint16_t device_id;
251 int status;
252 const char *vendor_name;
253 const char *device_name;
254};
Edward O'Callaghan80aedd02019-08-02 22:36:56 +1000255int pci_init_common(void);
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);
Edward O'Callaghan64a4db22019-05-30 03:13:07 -0400295void *physmap_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);
Edward O'Callaghanb2878982019-05-30 03:44:32 -0400297void physunmap_unaligned(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000298#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000299int setup_cpu_msr(int cpu);
300void cleanup_cpu_msr(void);
301
302/* cbtable.c */
Edward O'Callaghan481cce82019-05-31 15:03:50 +1000303int cb_parse_table(const char **vendor, const char **model);
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700304void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000305extern 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
Mayur Panchalf4796862019-08-05 15:46:12 +1000324struct pci_filter;
hailfinger428f6852010-07-27 22:41:39 +0000325struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000326struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000327struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
328struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
329 uint16_t card_vendor, uint16_t card_device);
330#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100331int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000332#if CONFIG_INTERNAL == 1
333extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000334extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000335extern int force_boardenable;
336extern int force_boardmismatch;
337void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000338int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000339extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700340int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000341#endif
342
343/* hwaccess.c */
344void mmio_writeb(uint8_t val, void *addr);
345void mmio_writew(uint16_t val, void *addr);
346void mmio_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000347uint8_t mmio_readb(const void *addr);
348uint16_t mmio_readw(const void *addr);
349uint32_t mmio_readl(const void *addr);
350void mmio_readn(const void *addr, uint8_t *buf, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000351void mmio_le_writeb(uint8_t val, void *addr);
352void mmio_le_writew(uint16_t val, void *addr);
353void mmio_le_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000354uint8_t mmio_le_readb(const void *addr);
355uint16_t mmio_le_readw(const void *addr);
356uint32_t mmio_le_readl(const void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000357#define pci_mmio_writeb mmio_le_writeb
358#define pci_mmio_writew mmio_le_writew
359#define pci_mmio_writel mmio_le_writel
360#define pci_mmio_readb mmio_le_readb
361#define pci_mmio_readw mmio_le_readw
362#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000363void rmmio_writeb(uint8_t val, void *addr);
364void rmmio_writew(uint16_t val, void *addr);
365void rmmio_writel(uint32_t val, void *addr);
366void rmmio_le_writeb(uint8_t val, void *addr);
367void rmmio_le_writew(uint16_t val, void *addr);
368void rmmio_le_writel(uint32_t val, void *addr);
369#define pci_rmmio_writeb rmmio_le_writeb
370#define pci_rmmio_writew rmmio_le_writew
371#define pci_rmmio_writel rmmio_le_writel
372void rmmio_valb(void *addr);
373void rmmio_valw(void *addr);
374void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000375
hailfinger428f6852010-07-27 22:41:39 +0000376/* dummyflasher.c */
377#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700378int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100379void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000380void dummy_unmap(void *virt_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000381#endif
382
383/* nic3com.c */
384#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700385int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100386extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000387#endif
388
389/* gfxnvidia.c */
390#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700391int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100392extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000393#endif
394
395/* drkaiser.c */
396#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700397int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100398extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000399#endif
400
401/* nicrealtek.c */
402#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700403int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100404extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000405#endif
406
407/* nicnatsemi.c */
408#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700409int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100410extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000411#endif
412
hailfinger7949b652011-05-08 00:24:18 +0000413/* nicintel.c */
414#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700415int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100416extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000417#endif
418
uwe6764e922010-09-03 18:21:21 +0000419/* nicintel_spi.c */
420#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700421int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100422extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000423#endif
424
hailfingerfb1f31f2010-12-03 14:48:11 +0000425/* ogp_spi.c */
426#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700427int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100428extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000429#endif
430
hailfinger935365d2011-02-04 21:37:59 +0000431/* satamv.c */
432#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700433int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100434extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000435#endif
436
hailfinger428f6852010-07-27 22:41:39 +0000437/* satasii.c */
438#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700439int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100440extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000441#endif
442
443/* atahpt.c */
444#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700445int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100446extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000447#endif
448
449/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000450#if CONFIG_FT2232_SPI == 1
451struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000452 uint16_t vendor_id;
453 uint16_t device_id;
454 int status;
455 const char *vendor_name;
456 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000457};
David Hendricksac1d25c2016-08-09 17:00:58 -0700458int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000459extern const struct usbdev_status devs_ft2232spi[];
460void print_supported_usbdevs(const struct usbdev_status *devs);
461#endif
hailfinger428f6852010-07-27 22:41:39 +0000462
463/* rayer_spi.c */
464#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700465int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000466#endif
467
468/* bitbang_spi.c */
Craig Hesling65eb8812019-08-01 09:33:56 -0700469int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700470int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000471
472/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000473#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700474int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000475#endif
hailfinger428f6852010-07-27 22:41:39 +0000476
Anton Staafb2647882014-09-17 15:13:43 -0700477/* raiden_debug_spi.c */
478#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700479int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700480#endif
481
David Hendricks7e449602013-05-17 19:21:36 -0700482/* linux_i2c.c */
483#if CONFIG_LINUX_I2C == 1
David Hendricks93784b42016-08-09 17:00:38 -0700484int linux_i2c_shutdown(void *data);
David Hendricksac1d25c2016-08-09 17:00:58 -0700485int linux_i2c_init(void);
David Hendricks7e449602013-05-17 19:21:36 -0700486int linux_i2c_open(int bus, int addr, int force);
487void linux_i2c_close(void);
488int linux_i2c_xfer(int bus, int addr, const void *inbuf,
489 int insize, const void *outbuf, int outsize);
490#endif
491
David Hendrickscebee892015-05-23 20:30:30 -0700492/* linux_mtd.c */
493#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700494int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700495#endif
496
uwe7df6dda2011-09-03 18:37:52 +0000497/* linux_spi.c */
498#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700499int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000500#endif
501
hailfinger428f6852010-07-27 22:41:39 +0000502/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000503#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700504int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000505#endif
hailfinger428f6852010-07-27 22:41:39 +0000506
507/* flashrom.c */
508struct decode_sizes {
509 uint32_t parallel;
510 uint32_t lpc;
511 uint32_t fwh;
512 uint32_t spi;
513};
514extern struct decode_sizes max_rom_decode;
515extern int programmer_may_write;
516extern unsigned long flashbase;
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
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000575
576#define SPI_MASTER_4BA (1U << 0) /**< Can handle 4-byte addresses */
577
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100578struct spi_master {
mkarcherd264e9e2011-05-11 17:07:07 +0000579 enum spi_controller type;
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000580 uint32_t features;
stefanctc5eb8a92011-11-23 09:13:48 +0000581 unsigned int max_data_read;
582 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700583 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000584 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700585 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000586
Patrick Georgie39d6442017-03-22 21:23:35 +0100587 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700588 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100589 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
hailfinger428f6852010-07-27 22:41:39 +0000590};
591
Craig Hesling65eb8812019-08-01 09:33:56 -0700592extern const struct spi_master *spi_master;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700593int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000594 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700595int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
596int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100597int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghan20ba6152019-08-26 23:21:09 +1000598int register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000599
Edward O'Callaghanea053772019-08-13 10:32:30 +1000600/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
601 enum ich_chipset {
stefanctc035c192011-11-06 23:51:09 +0000602 CHIPSET_ICH_UNKNOWN,
Edward O'Callaghanea053772019-08-13 10:32:30 +1000603 CHIPSET_ICH2 = 2,
604 CHIPSET_ICH3,
605 CHIPSET_ICH4,
606 CHIPSET_ICH5,
607 CHIPSET_ICH6,
608 CHIPSET_ICH7,
stefanctc035c192011-11-06 23:51:09 +0000609 CHIPSET_ICH8,
610 CHIPSET_ICH9,
611 CHIPSET_ICH10,
612 CHIPSET_5_SERIES_IBEX_PEAK,
613 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800614 CHIPSET_7_SERIES_PANTHER_POINT,
615 CHIPSET_8_SERIES_LYNX_POINT,
616 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700617 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530618 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800619 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700620 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000621};
622
Edward O'Callaghanea053772019-08-13 10:32:30 +1000623/* ichspi.c */
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700624#if CONFIG_INTERNAL == 1
Vadim Bendebury622128c2018-06-21 15:50:28 -0700625
626/*
627 * This global variable is used to communicate the type of ICH found on the
628 * device. When running on non-intel platforms default value of
629 * CHIPSET_ICH_UNKNOWN is used.
630*/
Edward O'Callaghane3e30562019-09-03 13:10:58 +1000631extern enum ich_chipset g_ich_generation;
Vadim Bendebury066143d2018-07-16 18:20:33 -0700632
633/*
634 * This global variable is set to indicate that the invoked flash programming
635 * command should not be executed, but just verified for validity.
636 *
637 * This is useful when one needs to determine if a certain flash erase command
638 * supported by the chip is allowed by the Intel controller on the device.
639 */
640extern int ich_dry_run;
hailfinger428f6852010-07-27 22:41:39 +0000641extern uint32_t ichspi_bbar;
642int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000643 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000644int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000645
Rong Changaaa1acf2012-06-21 19:21:18 +0800646/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700647int ene_probe_spi_flash(const char *name);
ivy_jian8e0c4e52017-08-23 09:17:56 +0800648/* amd_imc.c */
649int amd_imc_shutdown(struct pci_dev *dev);
Rong Changaaa1acf2012-06-21 19:21:18 +0800650
hailfinger2b46a862011-02-28 23:58:15 +0000651/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700652int it85xx_spi_init(struct superio s);
653int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000654
hailfinger428f6852010-07-27 22:41:39 +0000655/* it87spi.c */
656void enter_conf_mode_ite(uint16_t port);
657void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000658void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700659int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000660
hailfingere20dc562011-06-09 20:06:34 +0000661/* mcp6x_spi.c */
662int mcp6x_spi_init(int want_spi);
663
David Hendricks46d32e32011-01-19 16:01:52 -0800664/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700665int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800666
hailfinger428f6852010-07-27 22:41:39 +0000667/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000668int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000669
670/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000671int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000672#endif
673
hailfingerfe7cd9e2011-11-04 21:35:26 +0000674/* opaque.c */
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000675struct opaque_master {
hailfingerfe7cd9e2011-11-04 21:35:26 +0000676 int max_data_read;
677 int max_data_write;
678 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700679 int (*probe) (struct flashctx *flash);
680 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100681 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700682 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
683 uint8_t (*read_status) (const struct flashctx *flash);
684 int (*write_status) (const struct flashctx *flash, int status);
Duncan Laurie25a4ca22019-04-25 12:08:52 -0700685 int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
David Hendricks5d481e12012-05-24 14:14:14 -0700686 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000687};
Craig Hesling65eb8812019-08-01 09:33:56 -0700688extern struct opaque_master *opaque_master;
689void register_opaque_master(struct opaque_master *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000690
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700691/* programmer.c */
692int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100693void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700694void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700695uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700696void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
697void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
698void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
699void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
700uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
701uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
702void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100703struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700704 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
705 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
706 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
707 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
708 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
709 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
710 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
711 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000712 const void *data;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700713};
Craig Hesling65eb8812019-08-01 09:33:56 -0700714extern const struct par_master *par_master;
715void register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000716struct registered_master {
717 enum chipbustype buses_supported;
718 union {
719 struct par_master par;
720 struct spi_master spi;
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000721 struct opaque_master opaque;
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000722 };
723};
724extern struct registered_master registered_masters[];
725extern int registered_master_count;
726int register_master(const struct registered_master *mst);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700727
hailfinger428f6852010-07-27 22:41:39 +0000728/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000729#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700730int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000731void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000732#endif
hailfinger428f6852010-07-27 22:41:39 +0000733
734/* serial.c */
735#if _WIN32
736typedef HANDLE fdtype;
737#else
738typedef int fdtype;
739#endif
740
David Hendricksc801adb2010-12-09 16:58:56 -0800741/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700742int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800743
David Hendricksb907de32014-08-11 16:47:09 -0700744/* cros_ec.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700745int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700746
747/**
748 * Probe the Google Chrome OS EC device
749 *
750 * @return 0 if found correct, non-zero if not found or error
751 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700752int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700753
David Hendricksac1d25c2016-08-09 17:00:58 -0700754int cros_ec_probe_lpc(const char *name);
755int cros_ec_need_2nd_pass(void);
756int cros_ec_finish(void);
757int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800758
hailfinger428f6852010-07-27 22:41:39 +0000759void sp_flush_incoming(void);
760fdtype sp_openserport(char *dev, unsigned int baud);
761void __attribute__((noreturn)) sp_die(char *msg);
762extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000763/* expose serialport_shutdown as it's currently used by buspirate */
764int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000765int serialport_write(unsigned char *buf, unsigned int writecnt);
766int serialport_read(unsigned char *buf, unsigned int readcnt);
767
Edward O'Callaghana88395f2019-02-27 18:44:04 +1100768/* usbdev.c */
769struct libusb_device_handle;
770struct libusb_context;
771struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
772 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno);
773struct libusb_device_handle *usb_dev_get_by_vid_pid_number(
774 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
775
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000776/* spi_master feature checks */
777static inline bool spi_master_4ba(const struct flashctx *const flash)
778{
779 return flash->mst->buses_supported & BUS_SPI &&
780 flash->mst->spi.features & SPI_MASTER_4BA;
781}
782
hailfinger428f6852010-07-27 22:41:39 +0000783#endif /* !__PROGRAMMER_H__ */