blob: 172f45d2dbb356e5b732604e16e1d04e2c757835 [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
Souvik Ghoshd75cd672016-06-17 14:21:39 -070023#include "flash.h" /* for chipaddr and flashctx */
hailfingerfe7cd9e2011-11-04 21:35:26 +000024
hailfinger428f6852010-07-27 22:41:39 +000025enum programmer {
26#if CONFIG_INTERNAL == 1
27 PROGRAMMER_INTERNAL,
28#endif
29#if CONFIG_DUMMY == 1
30 PROGRAMMER_DUMMY,
31#endif
32#if CONFIG_NIC3COM == 1
33 PROGRAMMER_NIC3COM,
34#endif
35#if CONFIG_NICREALTEK == 1
36 PROGRAMMER_NICREALTEK,
uwe6764e922010-09-03 18:21:21 +000037#endif
hailfinger428f6852010-07-27 22:41:39 +000038#if CONFIG_NICNATSEMI == 1
39 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000040#endif
hailfinger428f6852010-07-27 22:41:39 +000041#if CONFIG_GFXNVIDIA == 1
42 PROGRAMMER_GFXNVIDIA,
43#endif
44#if CONFIG_DRKAISER == 1
45 PROGRAMMER_DRKAISER,
46#endif
47#if CONFIG_SATASII == 1
48 PROGRAMMER_SATASII,
49#endif
50#if CONFIG_ATAHPT == 1
51 PROGRAMMER_ATAHPT,
52#endif
hailfinger428f6852010-07-27 22:41:39 +000053#if CONFIG_FT2232_SPI == 1
54 PROGRAMMER_FT2232_SPI,
55#endif
56#if CONFIG_SERPROG == 1
57 PROGRAMMER_SERPROG,
58#endif
59#if CONFIG_BUSPIRATE_SPI == 1
60 PROGRAMMER_BUSPIRATE_SPI,
61#endif
Anton Staafb2647882014-09-17 15:13:43 -070062#if CONFIG_RAIDEN_DEBUG_SPI == 1
63 PROGRAMMER_RAIDEN_DEBUG_SPI,
64#endif
hailfinger428f6852010-07-27 22:41:39 +000065#if CONFIG_DEDIPROG == 1
66 PROGRAMMER_DEDIPROG,
67#endif
68#if CONFIG_RAYER_SPI == 1
69 PROGRAMMER_RAYER_SPI,
70#endif
hailfinger7949b652011-05-08 00:24:18 +000071#if CONFIG_NICINTEL == 1
72 PROGRAMMER_NICINTEL,
73#endif
uwe6764e922010-09-03 18:21:21 +000074#if CONFIG_NICINTEL_SPI == 1
75 PROGRAMMER_NICINTEL_SPI,
76#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000077#if CONFIG_OGP_SPI == 1
78 PROGRAMMER_OGP_SPI,
79#endif
hailfinger935365d2011-02-04 21:37:59 +000080#if CONFIG_SATAMV == 1
81 PROGRAMMER_SATAMV,
82#endif
David Hendrickscebee892015-05-23 20:30:30 -070083#if CONFIG_LINUX_MTD == 1
84 PROGRAMMER_LINUX_MTD,
85#endif
uwe7df6dda2011-09-03 18:37:52 +000086#if CONFIG_LINUX_SPI == 1
87 PROGRAMMER_LINUX_SPI,
88#endif
hailfinger428f6852010-07-27 22:41:39 +000089 PROGRAMMER_INVALID /* This must always be the last entry. */
90};
91
David Hendricksba0827a2013-05-03 20:25:40 -070092enum alias_type {
93 ALIAS_NONE = 0, /* no alias (default) */
94 ALIAS_EC, /* embedded controller */
95 ALIAS_HOST, /* chipset / PCH / SoC / etc. */
96};
97
98struct programmer_alias {
99 const char *name;
100 enum alias_type type;
101};
102
103extern struct programmer_alias *alias;
104extern struct programmer_alias aliases[];
105
Vadim Bendebury066143d2018-07-16 18:20:33 -0700106/*
107 * This function returns 'true' if current flashrom invocation is programming
108 * the EC.
109 */
110static inline int programming_ec(void) {
111 return alias && (alias->type == ALIAS_EC);
112}
113
hailfinger428f6852010-07-27 22:41:39 +0000114struct programmer_entry {
115 const char *vendor;
116 const char *name;
117
David Hendricksac1d25c2016-08-09 17:00:58 -0700118 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000119
Patrick Georgi4befc162017-02-03 18:32:01 +0100120 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000121 void (*unmap_flash_region) (void *virt_addr, size_t len);
122
hailfinger428f6852010-07-27 22:41:39 +0000123 void (*delay) (int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800124
125 /*
126 * If set, use extra precautions such as erasing with small block sizes
127 * and verifying more rigorously. This will incur a performance penalty
128 * but is good for programming the ROM in-system on a live machine.
129 */
130 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000131};
132
133extern const struct programmer_entry programmer_table[];
134
David Hendricksac1d25c2016-08-09 17:00:58 -0700135int programmer_init(enum programmer prog, char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700136int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000137
138enum bitbang_spi_master_type {
139 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
140#if CONFIG_RAYER_SPI == 1
141 BITBANG_SPI_MASTER_RAYER,
142#endif
uwe6764e922010-09-03 18:21:21 +0000143#if CONFIG_NICINTEL_SPI == 1
144 BITBANG_SPI_MASTER_NICINTEL,
145#endif
hailfinger52384c92010-07-28 15:08:35 +0000146#if CONFIG_INTERNAL == 1
147#if defined(__i386__) || defined(__x86_64__)
148 BITBANG_SPI_MASTER_MCP,
149#endif
150#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000151#if CONFIG_OGP_SPI == 1
152 BITBANG_SPI_MASTER_OGP,
153#endif
hailfinger428f6852010-07-27 22:41:39 +0000154};
155
156struct bitbang_spi_master {
157 enum bitbang_spi_master_type type;
158
159 /* Note that CS# is active low, so val=0 means the chip is active. */
160 void (*set_cs) (int val);
161 void (*set_sck) (int val);
162 void (*set_mosi) (int val);
163 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000164 void (*request_bus) (void);
165 void (*release_bus) (void);
Patrick Georgie081d5d2017-03-22 21:18:18 +0100166
167 /* Length of half a clock period in usecs. */
168 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000169};
170
171#if CONFIG_INTERNAL == 1
172struct penable {
173 uint16_t vendor_id;
174 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000175 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000176 const char *vendor_name;
177 const char *device_name;
178 int (*doit) (struct pci_dev *dev, const char *name);
179};
180
181extern const struct penable chipset_enables[];
182
hailfingere52e9f82011-05-05 07:12:40 +0000183enum board_match_phase {
184 P1,
185 P2,
186 P3
187};
188
hailfinger4640bdb2011-08-31 16:19:50 +0000189struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000190 /* Any device, but make it sensible, like the ISA bridge. */
191 uint16_t first_vendor;
192 uint16_t first_device;
193 uint16_t first_card_vendor;
194 uint16_t first_card_device;
195
196 /* Any device, but make it sensible, like
197 * the host bridge. May be NULL.
198 */
199 uint16_t second_vendor;
200 uint16_t second_device;
201 uint16_t second_card_vendor;
202 uint16_t second_card_device;
203
stefanct6d836ba2011-05-26 01:35:19 +0000204 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000205 const char *dmi_pattern;
206
stefanct6d836ba2011-05-26 01:35:19 +0000207 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000208 const char *lb_vendor;
209 const char *lb_part;
210
hailfingere52e9f82011-05-05 07:12:40 +0000211 enum board_match_phase phase;
212
hailfinger428f6852010-07-27 22:41:39 +0000213 const char *vendor_name;
214 const char *board_name;
215
216 int max_rom_decode_parallel;
217 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000218 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000219};
220
hailfinger4640bdb2011-08-31 16:19:50 +0000221extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000222
223struct board_info {
224 const char *vendor;
225 const char *name;
226 const int working;
227#ifdef CONFIG_PRINT_WIKI
228 const char *url;
229 const char *note;
230#endif
231};
232
233extern const struct board_info boards_known[];
234extern const struct board_info laptops_known[];
235#endif
236
237/* udelay.c */
238void myusec_delay(int usecs);
239void myusec_calibrate_delay(void);
240void internal_delay(int usecs);
241
242#if NEED_PCI == 1
243/* pcidev.c */
hailfinger428f6852010-07-27 22:41:39 +0000244extern struct pci_access *pacc;
Patrick Georgi8ae16572017-03-09 15:59:25 +0100245struct dev_entry {
hailfinger428f6852010-07-27 22:41:39 +0000246 uint16_t vendor_id;
247 uint16_t device_id;
248 int status;
249 const char *vendor_name;
250 const char *device_name;
251};
Patrick Georgif776a442017-03-28 21:34:33 +0200252uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100253uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct dev_entry *devs);
Patrick Georgi7c30fa92017-03-28 22:47:12 +0200254struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
hailfingerf31cbdc2010-11-10 15:25:18 +0000255/* rpci_write_* are reversible writes. The original PCI config space register
256 * contents will be restored on shutdown.
257 */
mkarcher08a24552010-12-26 23:55:19 +0000258int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
259int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
260int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000261#endif
262
263/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000264#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 +0100265void print_supported_pcidevs(const struct dev_entry *devs);
hailfinger428f6852010-07-27 22:41:39 +0000266#endif
267
hailfingere20dc562011-06-09 20:06:34 +0000268#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000269/* board_enable.c */
270void w836xx_ext_enter(uint16_t port);
271void w836xx_ext_leave(uint16_t port);
272int it8705f_write_enable(uint8_t port);
273uint8_t sio_read(uint16_t port, uint8_t reg);
274void sio_write(uint16_t port, uint8_t reg, uint8_t data);
275void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000276void board_handle_before_superio(void);
277void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000278int board_flash_enable(const char *vendor, const char *part);
279
280/* chipset_enable.c */
281int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800282int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000283
284/* processor_enable.c */
285int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000286#endif
hailfinger428f6852010-07-27 22:41:39 +0000287
288/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100289void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi220f4b52017-03-21 16:55:04 +0100290void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan64a4db22019-05-30 03:13:07 -0400291void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000292void physunmap(void *virt_addr, size_t len);
Edward O'Callaghanb2878982019-05-30 03:44:32 -0400293void physunmap_unaligned(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 */
Edward O'Callaghan481cce82019-05-31 15:03:50 +1000299int cb_parse_table(const char **vendor, const char **model);
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700300void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000301extern int partvendor_from_cbtable;
302
303/* dmi.c */
304extern int has_dmi_support;
305void dmi_init(void);
306int dmi_match(const char *pattern);
307
308/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000309struct superio {
310 uint16_t vendor;
311 uint16_t port;
312 uint16_t model;
313};
hailfinger94e090c2011-04-27 14:34:08 +0000314extern struct superio superios[];
315extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000316#define SUPERIO_VENDOR_NONE 0x0
317#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000318#endif
319#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000320struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000321struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000322struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
323struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
324 uint16_t card_vendor, uint16_t card_device);
325#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100326int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000327#if CONFIG_INTERNAL == 1
328extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000329extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000330extern int force_boardenable;
331extern int force_boardmismatch;
332void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000333int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000334extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700335int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000336#endif
337
338/* hwaccess.c */
339void mmio_writeb(uint8_t val, void *addr);
340void mmio_writew(uint16_t val, void *addr);
341void mmio_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000342uint8_t mmio_readb(const void *addr);
343uint16_t mmio_readw(const void *addr);
344uint32_t mmio_readl(const void *addr);
345void mmio_readn(const void *addr, uint8_t *buf, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000346void 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);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000349uint8_t mmio_le_readb(const void *addr);
350uint16_t mmio_le_readw(const void *addr);
351uint32_t mmio_le_readl(const void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000352#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);
hailfinger428f6852010-07-27 22:41:39 +0000376#endif
377
378/* nic3com.c */
379#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700380int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100381extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000382#endif
383
384/* gfxnvidia.c */
385#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700386int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100387extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000388#endif
389
390/* drkaiser.c */
391#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700392int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100393extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000394#endif
395
396/* nicrealtek.c */
397#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700398int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100399extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000400#endif
401
402/* nicnatsemi.c */
403#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700404int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100405extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000406#endif
407
hailfinger7949b652011-05-08 00:24:18 +0000408/* nicintel.c */
409#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700410int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100411extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000412#endif
413
uwe6764e922010-09-03 18:21:21 +0000414/* nicintel_spi.c */
415#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700416int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100417extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000418#endif
419
hailfingerfb1f31f2010-12-03 14:48:11 +0000420/* ogp_spi.c */
421#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700422int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100423extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000424#endif
425
hailfinger935365d2011-02-04 21:37:59 +0000426/* satamv.c */
427#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700428int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100429extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000430#endif
431
hailfinger428f6852010-07-27 22:41:39 +0000432/* satasii.c */
433#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700434int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100435extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000436#endif
437
438/* atahpt.c */
439#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700440int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100441extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000442#endif
443
444/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000445#if CONFIG_FT2232_SPI == 1
446struct usbdev_status {
uwee15beb92010-08-08 17:01:18 +0000447 uint16_t vendor_id;
448 uint16_t device_id;
449 int status;
450 const char *vendor_name;
451 const char *device_name;
hailfinger888410e2010-07-29 15:54:53 +0000452};
David Hendricksac1d25c2016-08-09 17:00:58 -0700453int ft2232_spi_init(void);
hailfinger888410e2010-07-29 15:54:53 +0000454extern const struct usbdev_status devs_ft2232spi[];
455void print_supported_usbdevs(const struct usbdev_status *devs);
456#endif
hailfinger428f6852010-07-27 22:41:39 +0000457
458/* rayer_spi.c */
459#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700460int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000461#endif
462
463/* bitbang_spi.c */
Edward O'Callaghanbcae3752018-12-19 13:11:57 +1100464int bitbang_spi_init(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700465int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000466
467/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000468#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700469int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000470#endif
hailfinger428f6852010-07-27 22:41:39 +0000471
Anton Staafb2647882014-09-17 15:13:43 -0700472/* raiden_debug_spi.c */
473#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700474int raiden_debug_spi_init(void);
Anton Staafb2647882014-09-17 15:13:43 -0700475#endif
476
David Hendricks7e449602013-05-17 19:21:36 -0700477/* linux_i2c.c */
478#if CONFIG_LINUX_I2C == 1
David Hendricks93784b42016-08-09 17:00:38 -0700479int linux_i2c_shutdown(void *data);
David Hendricksac1d25c2016-08-09 17:00:58 -0700480int linux_i2c_init(void);
David Hendricks7e449602013-05-17 19:21:36 -0700481int linux_i2c_open(int bus, int addr, int force);
482void linux_i2c_close(void);
483int linux_i2c_xfer(int bus, int addr, const void *inbuf,
484 int insize, const void *outbuf, int outsize);
485#endif
486
David Hendrickscebee892015-05-23 20:30:30 -0700487/* linux_mtd.c */
488#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700489int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700490#endif
491
uwe7df6dda2011-09-03 18:37:52 +0000492/* linux_spi.c */
493#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700494int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000495#endif
496
hailfinger428f6852010-07-27 22:41:39 +0000497/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000498#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700499int dediprog_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000500#endif
hailfinger428f6852010-07-27 22:41:39 +0000501
502/* flashrom.c */
503struct decode_sizes {
504 uint32_t parallel;
505 uint32_t lpc;
506 uint32_t fwh;
507 uint32_t spi;
508};
509extern struct decode_sizes max_rom_decode;
510extern int programmer_may_write;
511extern unsigned long flashbase;
hailfinger428f6852010-07-27 22:41:39 +0000512int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000513char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000514
515/* layout.c */
516int show_id(uint8_t *bios, int size, int force);
517
518/* spi.c */
519enum spi_controller {
520 SPI_CONTROLLER_NONE,
521#if CONFIG_INTERNAL == 1
522#if defined(__i386__) || defined(__x86_64__)
523 SPI_CONTROLLER_ICH7,
524 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700525 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000526 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000527 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800528 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000529 SPI_CONTROLLER_SB600,
ivy_jian8e0c4e52017-08-23 09:17:56 +0800530 SPI_CONTROLLER_YANGTZE,
hailfinger428f6852010-07-27 22:41:39 +0000531 SPI_CONTROLLER_VIA,
532 SPI_CONTROLLER_WBSIO,
David Hendricksc801adb2010-12-09 16:58:56 -0800533 SPI_CONTROLLER_WPCE775X,
Rong Changaaa1acf2012-06-21 19:21:18 +0800534 SPI_CONTROLLER_ENE,
David Hendricks82fd8ae2010-08-04 14:34:54 -0700535#endif
Louis Yung-Chieh Lobc351d02011-03-31 13:09:21 +0800536#if defined(__arm__)
537 SPI_CONTROLLER_TEGRA2,
hailfinger428f6852010-07-27 22:41:39 +0000538#endif
539#endif
540#if CONFIG_FT2232_SPI == 1
541 SPI_CONTROLLER_FT2232,
542#endif
543#if CONFIG_DUMMY == 1
544 SPI_CONTROLLER_DUMMY,
545#endif
546#if CONFIG_BUSPIRATE_SPI == 1
547 SPI_CONTROLLER_BUSPIRATE,
548#endif
Anton Staafb2647882014-09-17 15:13:43 -0700549#if CONFIG_RAIDEN_DEBUG_SPI == 1
550 SPI_CONTROLLER_RAIDEN_DEBUG,
551#endif
hailfinger428f6852010-07-27 22:41:39 +0000552#if CONFIG_DEDIPROG == 1
553 SPI_CONTROLLER_DEDIPROG,
554#endif
William A. Kennington III852ebf72017-04-05 12:16:06 -0700555#if CONFIG_BITBANG_SPI == 1
mkarcherd264e9e2011-05-11 17:07:07 +0000556 SPI_CONTROLLER_BITBANG,
hailfinger428f6852010-07-27 22:41:39 +0000557#endif
uwe7df6dda2011-09-03 18:37:52 +0000558#if CONFIG_LINUX_SPI == 1
559 SPI_CONTROLLER_LINUX,
560#endif
stefanct69965b62011-09-15 23:38:14 +0000561#if CONFIG_SERPROG == 1
562 SPI_CONTROLLER_SERPROG,
563#endif
hailfinger428f6852010-07-27 22:41:39 +0000564};
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100565extern const int spi_master_count;
mkarcher8fb57592011-05-11 17:07:02 +0000566
567#define MAX_DATA_UNSPECIFIED 0
568#define MAX_DATA_READ_UNLIMITED 64 * 1024
569#define MAX_DATA_WRITE_UNLIMITED 256
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100570struct spi_master {
mkarcherd264e9e2011-05-11 17:07:07 +0000571 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000572 unsigned int max_data_read;
573 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700574 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000575 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700576 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000577
Patrick Georgie39d6442017-03-22 21:23:35 +0100578 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700579 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100580 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghanbcae3752018-12-19 13:11:57 +1100581 const void *data;
hailfinger428f6852010-07-27 22:41:39 +0000582};
583
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700584int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000585 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700586int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
587int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100588int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghanbcae3752018-12-19 13:11:57 +1100589int register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000590
591/* ichspi.c */
stefanctc035c192011-11-06 23:51:09 +0000592enum ich_chipset {
593 CHIPSET_ICH_UNKNOWN,
594 CHIPSET_ICH7 = 7,
595 CHIPSET_ICH8,
596 CHIPSET_ICH9,
597 CHIPSET_ICH10,
598 CHIPSET_5_SERIES_IBEX_PEAK,
599 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800600 CHIPSET_7_SERIES_PANTHER_POINT,
601 CHIPSET_8_SERIES_LYNX_POINT,
602 CHIPSET_8_SERIES_LYNX_POINT_LP,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700603 CHIPSET_9_SERIES_WILDCAT_POINT,
Ramya Vijaykumara9a64f92015-04-15 15:26:22 +0530604 CHIPSET_100_SERIES_SUNRISE_POINT,
Duncan Lauried59ec692013-11-25 09:40:56 -0800605 CHIPSET_BAYTRAIL,
Furquan Shaikh44088752016-07-11 22:48:08 -0700606 CHIPSET_APL,
stefanctc035c192011-11-06 23:51:09 +0000607};
608
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700609#if CONFIG_INTERNAL == 1
Vadim Bendebury622128c2018-06-21 15:50:28 -0700610
611/*
612 * This global variable is used to communicate the type of ICH found on the
613 * device. When running on non-intel platforms default value of
614 * CHIPSET_ICH_UNKNOWN is used.
615*/
Vadim Bendebury066143d2018-07-16 18:20:33 -0700616extern enum ich_chipset ich_generation;
617
618/*
619 * This global variable is set to indicate that the invoked flash programming
620 * command should not be executed, but just verified for validity.
621 *
622 * This is useful when one needs to determine if a certain flash erase command
623 * supported by the chip is allowed by the Intel controller on the device.
624 */
625extern int ich_dry_run;
hailfinger428f6852010-07-27 22:41:39 +0000626extern uint32_t ichspi_bbar;
627int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000628 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000629int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000630
Rong Changaaa1acf2012-06-21 19:21:18 +0800631/* ene_lpc.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700632int ene_probe_spi_flash(const char *name);
ivy_jian8e0c4e52017-08-23 09:17:56 +0800633/* amd_imc.c */
634int amd_imc_shutdown(struct pci_dev *dev);
Rong Changaaa1acf2012-06-21 19:21:18 +0800635
hailfinger2b46a862011-02-28 23:58:15 +0000636/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700637int it85xx_spi_init(struct superio s);
638int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000639
hailfinger428f6852010-07-27 22:41:39 +0000640/* it87spi.c */
641void enter_conf_mode_ite(uint16_t port);
642void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000643void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700644int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000645
hailfingere20dc562011-06-09 20:06:34 +0000646/* mcp6x_spi.c */
647int mcp6x_spi_init(int want_spi);
648
David Hendricks46d32e32011-01-19 16:01:52 -0800649/* mec1308.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700650int mec1308_probe_spi_flash(const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800651
hailfinger428f6852010-07-27 22:41:39 +0000652/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000653int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000654
655/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000656int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000657#endif
658
hailfingerfe7cd9e2011-11-04 21:35:26 +0000659/* opaque.c */
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000660struct opaque_master {
hailfingerfe7cd9e2011-11-04 21:35:26 +0000661 int max_data_read;
662 int max_data_write;
663 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700664 int (*probe) (struct flashctx *flash);
665 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100666 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700667 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
668 uint8_t (*read_status) (const struct flashctx *flash);
669 int (*write_status) (const struct flashctx *flash, int status);
Duncan Laurie25a4ca22019-04-25 12:08:52 -0700670 int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
David Hendricks5d481e12012-05-24 14:14:14 -0700671 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000672};
Edward O'Callaghanbcae3752018-12-19 13:11:57 +1100673int register_opaque_master(const struct opaque_master *mst);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000674
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700675/* programmer.c */
676int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100677void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700678void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700679uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700680void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
681void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
682void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
683void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
684uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
685uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
686void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100687struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700688 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
689 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
690 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
691 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
692 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
693 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
694 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
695 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000696 const void *data;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700697};
Edward O'Callaghanbcae3752018-12-19 13:11:57 +1100698int register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000699struct registered_master {
700 enum chipbustype buses_supported;
701 union {
702 struct par_master par;
703 struct spi_master spi;
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000704 struct opaque_master opaque;
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000705 };
706};
707extern struct registered_master registered_masters[];
708extern int registered_master_count;
709int register_master(const struct registered_master *mst);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700710
hailfinger428f6852010-07-27 22:41:39 +0000711/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000712#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700713int serprog_init(void);
stefanctd9ac2212011-10-22 21:45:27 +0000714void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000715#endif
hailfinger428f6852010-07-27 22:41:39 +0000716
717/* serial.c */
718#if _WIN32
719typedef HANDLE fdtype;
720#else
721typedef int fdtype;
722#endif
723
David Hendricksc801adb2010-12-09 16:58:56 -0800724/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700725int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800726
David Hendricksb907de32014-08-11 16:47:09 -0700727/* cros_ec.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700728int cros_ec_probe_i2c(const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700729
730/**
731 * Probe the Google Chrome OS EC device
732 *
733 * @return 0 if found correct, non-zero if not found or error
734 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700735int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700736
David Hendricksac1d25c2016-08-09 17:00:58 -0700737int cros_ec_probe_lpc(const char *name);
738int cros_ec_need_2nd_pass(void);
739int cros_ec_finish(void);
740int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800741
hailfinger428f6852010-07-27 22:41:39 +0000742void sp_flush_incoming(void);
743fdtype sp_openserport(char *dev, unsigned int baud);
744void __attribute__((noreturn)) sp_die(char *msg);
745extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000746/* expose serialport_shutdown as it's currently used by buspirate */
747int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000748int serialport_write(unsigned char *buf, unsigned int writecnt);
749int serialport_read(unsigned char *buf, unsigned int readcnt);
750
Edward O'Callaghana88395f2019-02-27 18:44:04 +1100751/* usbdev.c */
752struct libusb_device_handle;
753struct libusb_context;
754struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
755 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno);
756struct libusb_device_handle *usb_dev_get_by_vid_pid_number(
757 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
758
hailfinger428f6852010-07-27 22:41:39 +0000759#endif /* !__PROGRAMMER_H__ */