blob: c5653a9f5c0d9e6fd1059c4ce9f30cc5d19538f1 [file] [log] [blame]
hailfinger428f6852010-07-27 22:41:39 +00001/*
2 * This file is part of the flashrom project.
3 *
4 * Copyright (C) 2000 Silicon Integrated System Corporation
5 * Copyright (C) 2000 Ronald G. Minnich <rminnich@gmail.com>
6 * Copyright (C) 2005-2009 coresystems GmbH
7 * Copyright (C) 2006-2009 Carl-Daniel Hailfinger
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef __PROGRAMMER_H__
25#define __PROGRAMMER_H__ 1
26
Souvik Ghoshd75cd672016-06-17 14:21:39 -070027#include "flash.h" /* for chipaddr and flashctx */
hailfingerfe7cd9e2011-11-04 21:35:26 +000028
hailfinger428f6852010-07-27 22:41:39 +000029enum programmer {
30#if CONFIG_INTERNAL == 1
31 PROGRAMMER_INTERNAL,
32#endif
33#if CONFIG_DUMMY == 1
34 PROGRAMMER_DUMMY,
35#endif
36#if CONFIG_NIC3COM == 1
37 PROGRAMMER_NIC3COM,
38#endif
39#if CONFIG_NICREALTEK == 1
40 PROGRAMMER_NICREALTEK,
uwe6764e922010-09-03 18:21:21 +000041#endif
hailfinger428f6852010-07-27 22:41:39 +000042#if CONFIG_NICNATSEMI == 1
43 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000044#endif
hailfinger428f6852010-07-27 22:41:39 +000045#if CONFIG_GFXNVIDIA == 1
46 PROGRAMMER_GFXNVIDIA,
47#endif
48#if CONFIG_DRKAISER == 1
49 PROGRAMMER_DRKAISER,
50#endif
51#if CONFIG_SATASII == 1
52 PROGRAMMER_SATASII,
53#endif
54#if CONFIG_ATAHPT == 1
55 PROGRAMMER_ATAHPT,
56#endif
hailfinger428f6852010-07-27 22:41:39 +000057#if CONFIG_FT2232_SPI == 1
58 PROGRAMMER_FT2232_SPI,
59#endif
60#if CONFIG_SERPROG == 1
61 PROGRAMMER_SERPROG,
62#endif
63#if CONFIG_BUSPIRATE_SPI == 1
64 PROGRAMMER_BUSPIRATE_SPI,
65#endif
Anton Staafb2647882014-09-17 15:13:43 -070066#if CONFIG_RAIDEN_DEBUG_SPI == 1
67 PROGRAMMER_RAIDEN_DEBUG_SPI,
68#endif
hailfinger428f6852010-07-27 22:41:39 +000069#if CONFIG_DEDIPROG == 1
70 PROGRAMMER_DEDIPROG,
71#endif
72#if CONFIG_RAYER_SPI == 1
73 PROGRAMMER_RAYER_SPI,
74#endif
hailfinger7949b652011-05-08 00:24:18 +000075#if CONFIG_NICINTEL == 1
76 PROGRAMMER_NICINTEL,
77#endif
uwe6764e922010-09-03 18:21:21 +000078#if CONFIG_NICINTEL_SPI == 1
79 PROGRAMMER_NICINTEL_SPI,
80#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000081#if CONFIG_OGP_SPI == 1
82 PROGRAMMER_OGP_SPI,
83#endif
hailfinger935365d2011-02-04 21:37:59 +000084#if CONFIG_SATAMV == 1
85 PROGRAMMER_SATAMV,
86#endif
David Hendrickscebee892015-05-23 20:30:30 -070087#if CONFIG_LINUX_MTD == 1
88 PROGRAMMER_LINUX_MTD,
89#endif
uwe7df6dda2011-09-03 18:37:52 +000090#if CONFIG_LINUX_SPI == 1
91 PROGRAMMER_LINUX_SPI,
92#endif
hailfinger428f6852010-07-27 22:41:39 +000093 PROGRAMMER_INVALID /* This must always be the last entry. */
94};
95
David Hendricksba0827a2013-05-03 20:25:40 -070096enum alias_type {
97 ALIAS_NONE = 0, /* no alias (default) */
98 ALIAS_EC, /* embedded controller */
99 ALIAS_HOST, /* chipset / PCH / SoC / etc. */
100};
101
102struct programmer_alias {
103 const char *name;
104 enum alias_type type;
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700105 enum programmer prog;
David Hendricksba0827a2013-05-03 20:25:40 -0700106};
107
108extern struct programmer_alias *alias;
109extern struct programmer_alias aliases[];
110
hailfinger428f6852010-07-27 22:41:39 +0000111struct programmer_entry {
112 const char *vendor;
113 const char *name;
114
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700115 int (*init) (struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000116
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700117 void *(*map_flash_region) (const char *descr, unsigned long phys_addr,
118 size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000119 void (*unmap_flash_region) (void *virt_addr, size_t len);
120
hailfinger428f6852010-07-27 22:41:39 +0000121 void (*delay) (int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800122
123 /*
124 * If set, use extra precautions such as erasing with small block sizes
125 * and verifying more rigorously. This will incur a performance penalty
126 * but is good for programming the ROM in-system on a live machine.
127 */
128 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000129};
130
131extern const struct programmer_entry programmer_table[];
132
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700133int programmer_init(struct flashctx *flash, enum programmer prog, char *param);
Souvik Ghosh052210a2016-07-11 12:29:05 -0700134int programmer_shutdown(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000135
136enum bitbang_spi_master_type {
137 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
138#if CONFIG_RAYER_SPI == 1
139 BITBANG_SPI_MASTER_RAYER,
140#endif
uwe6764e922010-09-03 18:21:21 +0000141#if CONFIG_NICINTEL_SPI == 1
142 BITBANG_SPI_MASTER_NICINTEL,
143#endif
hailfinger52384c92010-07-28 15:08:35 +0000144#if CONFIG_INTERNAL == 1
145#if defined(__i386__) || defined(__x86_64__)
146 BITBANG_SPI_MASTER_MCP,
147#endif
148#endif
hailfingerfb1f31f2010-12-03 14:48:11 +0000149#if CONFIG_OGP_SPI == 1
150 BITBANG_SPI_MASTER_OGP,
151#endif
hailfinger428f6852010-07-27 22:41:39 +0000152};
153
154struct bitbang_spi_master {
155 enum bitbang_spi_master_type type;
156
157 /* Note that CS# is active low, so val=0 means the chip is active. */
158 void (*set_cs) (int val);
159 void (*set_sck) (int val);
160 void (*set_mosi) (int val);
161 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000162 void (*request_bus) (void);
163 void (*release_bus) (void);
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700164 /* Length of half a clock period in usecs. */
165 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000166};
167
168#if CONFIG_INTERNAL == 1
169struct penable {
170 uint16_t vendor_id;
171 uint16_t device_id;
stefanct6d836ba2011-05-26 01:35:19 +0000172 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000173 const char *vendor_name;
174 const char *device_name;
175 int (*doit) (struct pci_dev *dev, const char *name);
176};
177
178extern const struct penable chipset_enables[];
179
hailfingere52e9f82011-05-05 07:12:40 +0000180enum board_match_phase {
181 P1,
182 P2,
183 P3
184};
185
hailfinger4640bdb2011-08-31 16:19:50 +0000186struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000187 /* Any device, but make it sensible, like the ISA bridge. */
188 uint16_t first_vendor;
189 uint16_t first_device;
190 uint16_t first_card_vendor;
191 uint16_t first_card_device;
192
193 /* Any device, but make it sensible, like
194 * the host bridge. May be NULL.
195 */
196 uint16_t second_vendor;
197 uint16_t second_device;
198 uint16_t second_card_vendor;
199 uint16_t second_card_device;
200
stefanct6d836ba2011-05-26 01:35:19 +0000201 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000202 const char *dmi_pattern;
203
stefanct6d836ba2011-05-26 01:35:19 +0000204 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000205 const char *lb_vendor;
206 const char *lb_part;
207
hailfingere52e9f82011-05-05 07:12:40 +0000208 enum board_match_phase phase;
209
hailfinger428f6852010-07-27 22:41:39 +0000210 const char *vendor_name;
211 const char *board_name;
212
213 int max_rom_decode_parallel;
214 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000215 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000216};
217
hailfinger4640bdb2011-08-31 16:19:50 +0000218extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000219
220struct board_info {
221 const char *vendor;
222 const char *name;
223 const int working;
224#ifdef CONFIG_PRINT_WIKI
225 const char *url;
226 const char *note;
227#endif
228};
229
230extern const struct board_info boards_known[];
231extern const struct board_info laptops_known[];
232#endif
233
234/* udelay.c */
235void myusec_delay(int usecs);
236void myusec_calibrate_delay(void);
237void internal_delay(int usecs);
238
239#if NEED_PCI == 1
240/* pcidev.c */
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700241// FIXME: These need to be local, not global
hailfinger428f6852010-07-27 22:41:39 +0000242extern uint32_t io_base_addr;
243extern struct pci_access *pacc;
244extern struct pci_dev *pcidev_dev;
245struct pcidev_status {
246 uint16_t vendor_id;
247 uint16_t device_id;
248 int status;
249 const char *vendor_name;
250 const char *device_name;
251};
hailfingerbf923c32011-02-15 22:44:27 +0000252uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct pcidev_status *devs);
hailfinger0d703d42011-03-07 01:08:09 +0000253uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
hailfingerf31cbdc2010-11-10 15:25:18 +0000254/* rpci_write_* are reversible writes. The original PCI config space register
255 * contents will be restored on shutdown.
256 */
mkarcher08a24552010-12-26 23:55:19 +0000257int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
258int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
259int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
hailfinger428f6852010-07-27 22:41:39 +0000260#endif
261
262/* print.c */
hailfinger7949b652011-05-08 00:24:18 +0000263#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
hailfinger428f6852010-07-27 22:41:39 +0000264void print_supported_pcidevs(const struct pcidev_status *devs);
265#endif
266
hailfingere20dc562011-06-09 20:06:34 +0000267#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000268/* board_enable.c */
269void w836xx_ext_enter(uint16_t port);
270void w836xx_ext_leave(uint16_t port);
271int it8705f_write_enable(uint8_t port);
272uint8_t sio_read(uint16_t port, uint8_t reg);
273void sio_write(uint16_t port, uint8_t reg, uint8_t data);
274void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000275void board_handle_before_superio(void);
276void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000277int board_flash_enable(const char *vendor, const char *part);
278
279/* chipset_enable.c */
280int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800281int get_target_bus_from_chipset(enum chipbustype *target_bus);
Ramya Vijaykumare6a7ca82015-05-12 14:27:29 +0530282enum ich_chipset ich_generation;
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 */
289void *physmap(const char *descr, unsigned long phys_addr, size_t len);
290void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
291void physunmap(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000292#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000293int setup_cpu_msr(int cpu);
294void cleanup_cpu_msr(void);
295
296/* cbtable.c */
297void lb_vendor_dev_from_string(char *boardstring);
298int coreboot_init(void);
299extern char *lb_part, *lb_vendor;
300extern int partvendor_from_cbtable;
301
302/* dmi.c */
303extern int has_dmi_support;
304void dmi_init(void);
305int dmi_match(const char *pattern);
306
307/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000308struct superio {
309 uint16_t vendor;
310 uint16_t port;
311 uint16_t model;
312};
hailfinger94e090c2011-04-27 14:34:08 +0000313extern struct superio superios[];
314extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000315#define SUPERIO_VENDOR_NONE 0x0
316#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000317#endif
318#if NEED_PCI == 1
hailfinger428f6852010-07-27 22:41:39 +0000319struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
uwe922946a2011-07-13 11:22:03 +0000320struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000321struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
322struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
323 uint16_t card_vendor, uint16_t card_device);
324#endif
325void get_io_perms(void);
326void release_io_perms(void);
327#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;
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700335int internal_init(struct flashctx *flash);
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);
342uint8_t mmio_readb(void *addr);
343uint16_t mmio_readw(void *addr);
344uint32_t mmio_readl(void *addr);
345void mmio_le_writeb(uint8_t val, void *addr);
346void mmio_le_writew(uint16_t val, void *addr);
347void mmio_le_writel(uint32_t val, void *addr);
348uint8_t mmio_le_readb(void *addr);
349uint16_t mmio_le_readw(void *addr);
350uint32_t mmio_le_readl(void *addr);
351#define pci_mmio_writeb mmio_le_writeb
352#define pci_mmio_writew mmio_le_writew
353#define pci_mmio_writel mmio_le_writel
354#define pci_mmio_readb mmio_le_readb
355#define pci_mmio_readw mmio_le_readw
356#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000357void rmmio_writeb(uint8_t val, void *addr);
358void rmmio_writew(uint16_t val, void *addr);
359void rmmio_writel(uint32_t val, void *addr);
360void rmmio_le_writeb(uint8_t val, void *addr);
361void rmmio_le_writew(uint16_t val, void *addr);
362void rmmio_le_writel(uint32_t val, void *addr);
363#define pci_rmmio_writeb rmmio_le_writeb
364#define pci_rmmio_writew rmmio_le_writew
365#define pci_rmmio_writel rmmio_le_writel
366void rmmio_valb(void *addr);
367void rmmio_valw(void *addr);
368void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000369
hailfinger428f6852010-07-27 22:41:39 +0000370/* dummyflasher.c */
371#if CONFIG_DUMMY == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700372int dummy_init(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000373void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
374void dummy_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700375
hailfinger428f6852010-07-27 22:41:39 +0000376#endif
377
378/* nic3com.c */
379#if CONFIG_NIC3COM == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700380int nic3com_init(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000381extern const struct pcidev_status nics_3com[];
382#endif
383
384/* gfxnvidia.c */
385#if CONFIG_GFXNVIDIA == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700386int gfxnvidia_init(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000387extern const struct pcidev_status gfx_nvidia[];
388#endif
389
390/* drkaiser.c */
391#if CONFIG_DRKAISER == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700392int drkaiser_init(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000393extern const struct pcidev_status drkaiser_pcidev[];
394#endif
395
396/* nicrealtek.c */
397#if CONFIG_NICREALTEK == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700398int nicrealtek_init(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000399extern const struct pcidev_status nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000400#endif
401
402/* nicnatsemi.c */
403#if CONFIG_NICNATSEMI == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700404int nicnatsemi_init(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000405extern const struct pcidev_status nics_natsemi[];
406#endif
407
hailfinger7949b652011-05-08 00:24:18 +0000408/* nicintel.c */
409#if CONFIG_NICINTEL == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700410int nicintel_init(struct flashctx *flash);
hailfinger7949b652011-05-08 00:24:18 +0000411extern const struct pcidev_status nics_intel[];
412#endif
413
uwe6764e922010-09-03 18:21:21 +0000414/* nicintel_spi.c */
415#if CONFIG_NICINTEL_SPI == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700416int nicintel_spi_init(struct flashctx *flash);
uwe6764e922010-09-03 18:21:21 +0000417extern const struct pcidev_status nics_intel_spi[];
418#endif
419
hailfingerfb1f31f2010-12-03 14:48:11 +0000420/* ogp_spi.c */
421#if CONFIG_OGP_SPI == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700422int ogp_spi_init(struct flashctx *flash);
hailfingerfb1f31f2010-12-03 14:48:11 +0000423extern const struct pcidev_status ogp_spi[];
424#endif
425
hailfinger935365d2011-02-04 21:37:59 +0000426/* satamv.c */
427#if CONFIG_SATAMV == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700428int satamv_init(struct flashctx *flash);
hailfinger935365d2011-02-04 21:37:59 +0000429extern const struct pcidev_status satas_mv[];
430#endif
431
hailfinger428f6852010-07-27 22:41:39 +0000432/* satasii.c */
433#if CONFIG_SATASII == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700434int satasii_init(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000435extern const struct pcidev_status satas_sii[];
436#endif
437
438/* atahpt.c */
439#if CONFIG_ATAHPT == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700440int atahpt_init(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000441extern const struct pcidev_status ata_hpt[];
442#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};
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700453int ft2232_spi_init(struct flashctx *flash);
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
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700460int rayer_spi_init(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000461#endif
462
463/* bitbang_spi.c */
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700464int bitbang_spi_init(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000465
466/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000467#if CONFIG_BUSPIRATE_SPI == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700468int buspirate_spi_init(struct flashctx *flash);
hailfingere20dc562011-06-09 20:06:34 +0000469#endif
hailfinger428f6852010-07-27 22:41:39 +0000470
Anton Staafb2647882014-09-17 15:13:43 -0700471/* raiden_debug_spi.c */
472#if CONFIG_RAIDEN_DEBUG_SPI == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700473int raiden_debug_spi_init(struct flashctx *flash);
Anton Staafb2647882014-09-17 15:13:43 -0700474#endif
475
David Hendricks7e449602013-05-17 19:21:36 -0700476/* linux_i2c.c */
477#if CONFIG_LINUX_I2C == 1
Souvik Ghosh052210a2016-07-11 12:29:05 -0700478int linux_i2c_shutdown(struct flashctx *flash, void *data);
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700479int linux_i2c_init(struct flashctx *flash);
David Hendricks7e449602013-05-17 19:21:36 -0700480int linux_i2c_open(int bus, int addr, int force);
481void linux_i2c_close(void);
482int linux_i2c_xfer(int bus, int addr, const void *inbuf,
483 int insize, const void *outbuf, int outsize);
484#endif
485
David Hendrickscebee892015-05-23 20:30:30 -0700486/* linux_mtd.c */
487#if CONFIG_LINUX_MTD == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700488int linux_mtd_init(struct flashctx *flash);
David Hendrickscebee892015-05-23 20:30:30 -0700489#endif
490
uwe7df6dda2011-09-03 18:37:52 +0000491/* linux_spi.c */
492#if CONFIG_LINUX_SPI == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700493int linux_spi_init(struct flashctx *flash);
uwe7df6dda2011-09-03 18:37:52 +0000494#endif
495
hailfinger428f6852010-07-27 22:41:39 +0000496/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000497#if CONFIG_DEDIPROG == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700498int dediprog_init(struct flashctx *flash);
hailfingere20dc562011-06-09 20:06:34 +0000499#endif
hailfinger428f6852010-07-27 22:41:39 +0000500
501/* flashrom.c */
502struct decode_sizes {
503 uint32_t parallel;
504 uint32_t lpc;
505 uint32_t fwh;
506 uint32_t spi;
507};
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700508// FIXME: These need to be local, not global
hailfinger428f6852010-07-27 22:41:39 +0000509extern struct decode_sizes max_rom_decode;
510extern int programmer_may_write;
511extern unsigned long flashbase;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700512void check_chip_supported(const struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000513int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000514char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000515
516/* layout.c */
517int show_id(uint8_t *bios, int size, int force);
518
519/* spi.c */
520enum spi_controller {
521 SPI_CONTROLLER_NONE,
522#if CONFIG_INTERNAL == 1
523#if defined(__i386__) || defined(__x86_64__)
524 SPI_CONTROLLER_ICH7,
525 SPI_CONTROLLER_ICH9,
David Hendricks07af3a42011-07-11 22:13:02 -0700526 SPI_CONTROLLER_ICH_HWSEQ,
hailfinger2b46a862011-02-28 23:58:15 +0000527 SPI_CONTROLLER_IT85XX,
hailfinger428f6852010-07-27 22:41:39 +0000528 SPI_CONTROLLER_IT87XX,
David Hendricks46d32e32011-01-19 16:01:52 -0800529 SPI_CONTROLLER_MEC1308,
hailfinger428f6852010-07-27 22:41:39 +0000530 SPI_CONTROLLER_SB600,
531 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
David Hendricks91040832011-07-08 20:01:09 -0700555#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__) || defined(__arm__)))
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};
mkarcher8fb57592011-05-11 17:07:02 +0000565
566#define MAX_DATA_UNSPECIFIED 0
567#define MAX_DATA_READ_UNLIMITED 64 * 1024
568#define MAX_DATA_WRITE_UNLIMITED 256
hailfinger428f6852010-07-27 22:41:39 +0000569struct spi_programmer {
mkarcherd264e9e2011-05-11 17:07:07 +0000570 enum spi_controller type;
stefanctc5eb8a92011-11-23 09:13:48 +0000571 unsigned int max_data_read;
572 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700573 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000574 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700575 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000576
577 /* Optimized functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700578 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
579 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700580 const void *data;
hailfinger428f6852010-07-27 22:41:39 +0000581};
582
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700583int default_spi_send_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 -0700585int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
586int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
587int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700588int register_spi_programmer(const struct spi_programmer *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000589
590/* ichspi.c */
591#if CONFIG_INTERNAL == 1
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
hailfinger428f6852010-07-27 22:41:39 +0000609extern uint32_t ichspi_bbar;
610int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
stefanctc035c192011-11-06 23:51:09 +0000611 enum ich_chipset ich_generation);
hailfinger428f6852010-07-27 22:41:39 +0000612int via_init_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000613
Rong Changaaa1acf2012-06-21 19:21:18 +0800614/* ene_lpc.c */
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700615int ene_probe_spi_flash(struct flashctx *flash, const char *name);
Rong Changaaa1acf2012-06-21 19:21:18 +0800616
hailfinger2b46a862011-02-28 23:58:15 +0000617/* it85spi.c */
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700618int it85xx_spi_init(struct flashctx *flash, struct superio s);
619int it8518_spi_init(struct flashctx *flash, struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000620
hailfinger428f6852010-07-27 22:41:39 +0000621/* it87spi.c */
622void enter_conf_mode_ite(uint16_t port);
623void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000624void probe_superio_ite(void);
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700625int init_superio_ite(struct flashctx *flash);
hailfinger428f6852010-07-27 22:41:39 +0000626
hailfingere20dc562011-06-09 20:06:34 +0000627/* mcp6x_spi.c */
628int mcp6x_spi_init(int want_spi);
629
David Hendricks46d32e32011-01-19 16:01:52 -0800630/* mec1308.c */
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700631int mec1308_probe_spi_flash(struct flashctx *flash, const char *name);
David Hendricks46d32e32011-01-19 16:01:52 -0800632
hailfinger428f6852010-07-27 22:41:39 +0000633/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000634int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000635
636/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000637int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000638#endif
639
hailfingerfe7cd9e2011-11-04 21:35:26 +0000640/* opaque.c */
641struct opaque_programmer {
642 int max_data_read;
643 int max_data_write;
644 /* Specific functions for this programmer */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700645 int (*probe) (struct flashctx *flash);
646 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
647 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
648 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
649 uint8_t (*read_status) (const struct flashctx *flash);
650 int (*write_status) (const struct flashctx *flash, int status);
David Hendricks5d481e12012-05-24 14:14:14 -0700651 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000652};
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700653int register_opaque_programmer(const struct opaque_programmer *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000654
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700655/* programmer.c */
656int noop_shutdown(void);
657void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
658void fallback_unmap(void *virt_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700659void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
660void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
661void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
662void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
663uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
664uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
665void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
666struct par_programmer {
667 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
668 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
669 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
670 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
671 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
672 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
673 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
674 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700675 const void *data;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700676};
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700677int register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
678struct registered_programmer {
679 enum chipbustype buses_supported;
680 union {
681 struct par_programmer par;
682 struct spi_programmer spi;
683 struct opaque_programmer opaque;
684 };
685};
686extern struct registered_programmer registered_programmers[];
687extern int registered_programmer_count;
688int register_programmer(struct registered_programmer *pgm);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700689
hailfinger428f6852010-07-27 22:41:39 +0000690/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000691#if CONFIG_SERPROG == 1
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700692int serprog_init(struct flashctx *flash);
stefanctd9ac2212011-10-22 21:45:27 +0000693void serprog_delay(int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000694#endif
hailfinger428f6852010-07-27 22:41:39 +0000695
696/* serial.c */
697#if _WIN32
698typedef HANDLE fdtype;
699#else
700typedef int fdtype;
701#endif
702
David Hendricksc801adb2010-12-09 16:58:56 -0800703/* wpce775x.c */
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700704int wpce775x_probe_spi_flash(struct flashctx *flash, const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800705
David Hendricksb907de32014-08-11 16:47:09 -0700706/* cros_ec.c */
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700707int cros_ec_probe_i2c(struct flashctx *flash, const char *name);
Simon Glasscd597032013-05-23 17:18:44 -0700708
709/**
710 * Probe the Google Chrome OS EC device
711 *
712 * @return 0 if found correct, non-zero if not found or error
713 */
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700714int cros_ec_probe_dev(struct flashctx *flash);
Simon Glasscd597032013-05-23 17:18:44 -0700715
Souvik Ghosh63b92f92016-06-29 18:45:52 -0700716int cros_ec_probe_lpc(struct flashctx *flash, const char *name);
717int cros_ec_need_2nd_pass(struct flashctx *flash);
718int cros_ec_finish(struct flashctx *flash);
719int cros_ec_prepare(struct flashctx *flash, uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800720
hailfinger428f6852010-07-27 22:41:39 +0000721void sp_flush_incoming(void);
722fdtype sp_openserport(char *dev, unsigned int baud);
723void __attribute__((noreturn)) sp_die(char *msg);
724extern fdtype sp_fd;
dhendrix0ffc2eb2011-06-14 01:35:36 +0000725/* expose serialport_shutdown as it's currently used by buspirate */
726int serialport_shutdown(void *data);
hailfinger428f6852010-07-27 22:41:39 +0000727int serialport_write(unsigned char *buf, unsigned int writecnt);
728int serialport_read(unsigned char *buf, unsigned int readcnt);
729
730#endif /* !__PROGRAMMER_H__ */