blob: b0df2ba7fdb5552fa3c111ee92053566d7f4a3a6 [file] [log] [blame]
Carl-Daniel Hailfinger5b997c32010-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
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000027#include "flash.h" /* for chipaddr and flashctx */
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000028
Carl-Daniel Hailfinger5b997c32010-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,
Idwer Vollering004f4b72010-09-03 18:21:21 +000041#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000042#if CONFIG_NICNATSEMI == 1
43 PROGRAMMER_NICNATSEMI,
Idwer Vollering004f4b72010-09-03 18:21:21 +000044#endif
Carl-Daniel Hailfinger5b997c32010-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
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +000057#if CONFIG_ATAVIA == 1
58 PROGRAMMER_ATAVIA,
59#endif
Kyösti Mälkki72d42f82014-06-01 23:48:31 +000060#if CONFIG_IT8212 == 1
61 PROGRAMMER_IT8212,
62#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000063#if CONFIG_FT2232_SPI == 1
64 PROGRAMMER_FT2232_SPI,
65#endif
66#if CONFIG_SERPROG == 1
67 PROGRAMMER_SERPROG,
68#endif
69#if CONFIG_BUSPIRATE_SPI == 1
70 PROGRAMMER_BUSPIRATE_SPI,
71#endif
72#if CONFIG_DEDIPROG == 1
73 PROGRAMMER_DEDIPROG,
74#endif
75#if CONFIG_RAYER_SPI == 1
76 PROGRAMMER_RAYER_SPI,
77#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +000078#if CONFIG_PONY_SPI == 1
79 PROGRAMMER_PONY_SPI,
80#endif
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000081#if CONFIG_NICINTEL == 1
82 PROGRAMMER_NICINTEL,
83#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +000084#if CONFIG_NICINTEL_SPI == 1
85 PROGRAMMER_NICINTEL_SPI,
86#endif
Mark Marshall90021f22010-12-03 14:48:11 +000087#if CONFIG_OGP_SPI == 1
88 PROGRAMMER_OGP_SPI,
89#endif
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +000090#if CONFIG_SATAMV == 1
91 PROGRAMMER_SATAMV,
92#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +000093#if CONFIG_LINUX_SPI == 1
94 PROGRAMMER_LINUX_SPI,
95#endif
James Lairdc60de0e2013-03-27 13:00:23 +000096#if CONFIG_USBBLASTER_SPI == 1
97 PROGRAMMER_USBBLASTER_SPI,
98#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000099 PROGRAMMER_INVALID /* This must always be the last entry. */
100};
101
Stefan Tauneraf358d62012-12-27 18:40:26 +0000102enum programmer_type {
103 PCI = 1, /* to detect uninitialized values */
104 USB,
105 OTHER,
106};
107
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000108struct dev_entry {
109 uint16_t vendor_id;
110 uint16_t device_id;
111 const enum test_state status;
112 const char *vendor_name;
113 const char *device_name;
114};
115
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000116struct programmer_entry {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000117 const char *name;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000118 const enum programmer_type type;
119 union {
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000120 const struct dev_entry *const dev;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000121 const char *const note;
122 } devs;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000123
124 int (*init) (void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000125
Stefan Tauner305e0b92013-07-17 23:46:44 +0000126 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000127 void (*unmap_flash_region) (void *virt_addr, size_t len);
128
Stefan Taunerf80419c2014-05-02 15:41:42 +0000129 void (*delay) (unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000130};
131
132extern const struct programmer_entry programmer_table[];
133
Nico Huberbcb2e5a2012-12-30 01:23:17 +0000134int programmer_init(enum programmer prog, const char *param);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000135int programmer_shutdown(void);
136
137enum bitbang_spi_master_type {
138 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
139#if CONFIG_RAYER_SPI == 1
140 BITBANG_SPI_MASTER_RAYER,
141#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000142#if CONFIG_PONY_SPI == 1
143 BITBANG_SPI_MASTER_PONY,
144#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +0000145#if CONFIG_NICINTEL_SPI == 1
146 BITBANG_SPI_MASTER_NICINTEL,
147#endif
Carl-Daniel Hailfinger2f436162010-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
Mark Marshall90021f22010-12-03 14:48:11 +0000153#if CONFIG_OGP_SPI == 1
154 BITBANG_SPI_MASTER_OGP,
155#endif
Carl-Daniel Hailfinger5b997c32010-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);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000166 void (*request_bus) (void);
167 void (*release_bus) (void);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000168 /* Length of half a clock period in usecs. */
169 unsigned int half_period;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000170};
171
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000172#if NEED_PCI == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000173struct pci_dev;
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000174
175/* pcidev.c */
Stefan Tauner0ccec8f2014-06-01 23:49:03 +0000176// FIXME: This needs to be local, not global(?)
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000177extern struct pci_access *pacc;
178int pci_init_common(void);
179uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
180struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
181/* rpci_write_* are reversible writes. The original PCI config space register
182 * contents will be restored on shutdown.
183 */
184int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
185int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
186int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
187#endif
188
189#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000190struct penable {
191 uint16_t vendor_id;
192 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000193 const enum test_state status;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000194 const char *vendor_name;
195 const char *device_name;
196 int (*doit) (struct pci_dev *dev, const char *name);
197};
198
199extern const struct penable chipset_enables[];
200
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000201enum board_match_phase {
202 P1,
203 P2,
204 P3
205};
206
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000207struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000208 /* Any device, but make it sensible, like the ISA bridge. */
209 uint16_t first_vendor;
210 uint16_t first_device;
211 uint16_t first_card_vendor;
212 uint16_t first_card_device;
213
214 /* Any device, but make it sensible, like
215 * the host bridge. May be NULL.
216 */
217 uint16_t second_vendor;
218 uint16_t second_device;
219 uint16_t second_card_vendor;
220 uint16_t second_card_device;
221
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000222 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000223 const char *dmi_pattern;
224
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000225 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000226 const char *lb_vendor;
227 const char *lb_part;
228
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000229 enum board_match_phase phase;
230
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000231 const char *vendor_name;
232 const char *board_name;
233
234 int max_rom_decode_parallel;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000235 const enum test_state status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000236 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000237};
238
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000239extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000240
241struct board_info {
242 const char *vendor;
243 const char *name;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000244 const enum test_state working;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000245#ifdef CONFIG_PRINT_WIKI
246 const char *url;
247 const char *note;
248#endif
249};
250
251extern const struct board_info boards_known[];
252extern const struct board_info laptops_known[];
253#endif
254
255/* udelay.c */
Stefan Taunerf80419c2014-05-02 15:41:42 +0000256void myusec_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000257void myusec_calibrate_delay(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000258void internal_sleep(unsigned int usecs);
259void internal_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000260
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000261#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000262/* board_enable.c */
Stefan Tauner600576b2014-06-12 22:57:36 +0000263int selfcheck_board_enables(void);
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000264int board_parse_parameter(const char *boardstring, const char **vendor, const char **model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000265void w836xx_ext_enter(uint16_t port);
266void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000267void probe_superio_winbond(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000268int it8705f_write_enable(uint8_t port);
269uint8_t sio_read(uint16_t port, uint8_t reg);
270void sio_write(uint16_t port, uint8_t reg, uint8_t data);
271void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000272void board_handle_before_superio(void);
273void board_handle_before_laptop(void);
Stefan Taunerfa9fa712012-09-24 21:29:29 +0000274int board_flash_enable(const char *vendor, const char *model, const char *cb_vendor, const char *cb_model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000275
276/* chipset_enable.c */
277int chipset_flash_enable(void);
278
279/* processor_enable.c */
280int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000281#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000282
283/* physmap.c */
Stefan Tauner305e0b92013-07-17 23:46:44 +0000284void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Stefan Tauner7fb5aa02013-08-14 15:48:44 +0000285void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Niklas Söderlund5d307202013-09-14 09:02:27 +0000286void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000287void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000288void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000289void physunmap_unaligned(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000290#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000291int setup_cpu_msr(int cpu);
292void cleanup_cpu_msr(void);
293
294/* cbtable.c */
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000295int cb_parse_table(const char **vendor, const char **model);
296int cb_check_image(uint8_t *bios, int size);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000297
298/* dmi.c */
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000299#if defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000300extern int has_dmi_support;
301void dmi_init(void);
302int dmi_match(const char *pattern);
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000303#endif // defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000304
305/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000306struct superio {
307 uint16_t vendor;
308 uint16_t port;
309 uint16_t model;
310};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000311extern struct superio superios[];
312extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000313#define SUPERIO_VENDOR_NONE 0x0
314#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000315#define SUPERIO_VENDOR_WINBOND 0x2
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000316#endif
317#if NEED_PCI == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000318struct pci_filter;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000319struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
Uwe Hermann24c35e42011-07-13 11:22:03 +0000320struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-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
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +0000325int rget_io_perms(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000326#if CONFIG_INTERNAL == 1
327extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000328extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000329extern int force_boardenable;
330extern int force_boardmismatch;
331void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000332int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000333extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000334int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000335#endif
336
337/* hwaccess.c */
338void mmio_writeb(uint8_t val, void *addr);
339void mmio_writew(uint16_t val, void *addr);
340void mmio_writel(uint32_t val, void *addr);
341uint8_t mmio_readb(void *addr);
342uint16_t mmio_readw(void *addr);
343uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerccd71c22012-03-01 22:38:27 +0000344void mmio_readn(void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000345void 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
Carl-Daniel Hailfinger54ce73a2011-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);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000369
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000370/* dummyflasher.c */
371#if CONFIG_DUMMY == 1
372int dummy_init(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000373void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000374void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000375#endif
376
377/* nic3com.c */
378#if CONFIG_NIC3COM == 1
379int nic3com_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000380extern const struct dev_entry nics_3com[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000381#endif
382
383/* gfxnvidia.c */
384#if CONFIG_GFXNVIDIA == 1
385int gfxnvidia_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000386extern const struct dev_entry gfx_nvidia[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000387#endif
388
389/* drkaiser.c */
390#if CONFIG_DRKAISER == 1
391int drkaiser_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000392extern const struct dev_entry drkaiser_pcidev[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000393#endif
394
395/* nicrealtek.c */
396#if CONFIG_NICREALTEK == 1
397int nicrealtek_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000398extern const struct dev_entry nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000399#endif
400
401/* nicnatsemi.c */
402#if CONFIG_NICNATSEMI == 1
403int nicnatsemi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000404extern const struct dev_entry nics_natsemi[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000405#endif
406
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000407/* nicintel.c */
408#if CONFIG_NICINTEL == 1
409int nicintel_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000410extern const struct dev_entry nics_intel[];
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000411#endif
412
Idwer Vollering004f4b72010-09-03 18:21:21 +0000413/* nicintel_spi.c */
414#if CONFIG_NICINTEL_SPI == 1
415int nicintel_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000416extern const struct dev_entry nics_intel_spi[];
Idwer Vollering004f4b72010-09-03 18:21:21 +0000417#endif
418
Mark Marshall90021f22010-12-03 14:48:11 +0000419/* ogp_spi.c */
420#if CONFIG_OGP_SPI == 1
421int ogp_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000422extern const struct dev_entry ogp_spi[];
Mark Marshall90021f22010-12-03 14:48:11 +0000423#endif
424
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000425/* satamv.c */
426#if CONFIG_SATAMV == 1
427int satamv_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000428extern const struct dev_entry satas_mv[];
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000429#endif
430
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000431/* satasii.c */
432#if CONFIG_SATASII == 1
433int satasii_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000434extern const struct dev_entry satas_sii[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000435#endif
436
437/* atahpt.c */
438#if CONFIG_ATAHPT == 1
439int atahpt_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000440extern const struct dev_entry ata_hpt[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000441#endif
442
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +0000443/* atavia.c */
444#if CONFIG_ATAVIA == 1
445int atavia_init(void);
446void *atavia_map(const char *descr, uintptr_t phys_addr, size_t len);
447extern const struct dev_entry ata_via[];
448#endif
449
Kyösti Mälkki72d42f82014-06-01 23:48:31 +0000450/* it8212.c */
451#if CONFIG_IT8212 == 1
452int it8212_init(void);
453extern const struct dev_entry devs_it8212[];
454#endif
455
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000456/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000457#if CONFIG_FT2232_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000458int ft2232_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000459extern const struct dev_entry devs_ft2232spi[];
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000460#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000461
James Lairdc60de0e2013-03-27 13:00:23 +0000462/* usbblaster_spi.c */
463#if CONFIG_USBBLASTER_SPI == 1
464int usbblaster_spi_init(void);
465extern const struct dev_entry devs_usbblasterspi[];
466#endif
467
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000468/* rayer_spi.c */
469#if CONFIG_RAYER_SPI == 1
470int rayer_spi_init(void);
471#endif
472
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000473/* pony_spi.c */
474#if CONFIG_PONY_SPI == 1
475int pony_spi_init(void);
476#endif
477
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000478/* bitbang_spi.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000479int bitbang_spi_init(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000480
481/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000482#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000483int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000484#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000485
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000486/* linux_spi.c */
487#if CONFIG_LINUX_SPI == 1
488int linux_spi_init(void);
489#endif
490
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000491/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000492#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000493int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000494#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000495
496/* flashrom.c */
497struct decode_sizes {
498 uint32_t parallel;
499 uint32_t lpc;
500 uint32_t fwh;
501 uint32_t spi;
502};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000503// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000504extern struct decode_sizes max_rom_decode;
505extern int programmer_may_write;
506extern unsigned long flashbase;
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +0000507void check_chip_supported(const struct flashchip *chip);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000508int check_max_decode(enum chipbustype buses, uint32_t size);
Stefan Tauner66652442011-06-26 17:38:17 +0000509char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000510
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000511/* spi.c */
512enum spi_controller {
513 SPI_CONTROLLER_NONE,
514#if CONFIG_INTERNAL == 1
515#if defined(__i386__) || defined(__x86_64__)
516 SPI_CONTROLLER_ICH7,
517 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000518 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000519 SPI_CONTROLLER_IT87XX,
520 SPI_CONTROLLER_SB600,
Wei Hu31402ee2014-05-16 21:39:33 +0000521 SPI_CONTROLLER_YANGTZE,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000522 SPI_CONTROLLER_VIA,
523 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000524#endif
525#endif
526#if CONFIG_FT2232_SPI == 1
527 SPI_CONTROLLER_FT2232,
528#endif
529#if CONFIG_DUMMY == 1
530 SPI_CONTROLLER_DUMMY,
531#endif
532#if CONFIG_BUSPIRATE_SPI == 1
533 SPI_CONTROLLER_BUSPIRATE,
534#endif
535#if CONFIG_DEDIPROG == 1
536 SPI_CONTROLLER_DEDIPROG,
537#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000538#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || CONFIG_PONY_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__)))
Michael Karcherb9dbe482011-05-11 17:07:07 +0000539 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000540#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000541#if CONFIG_LINUX_SPI == 1
542 SPI_CONTROLLER_LINUX,
543#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000544#if CONFIG_SERPROG == 1
545 SPI_CONTROLLER_SERPROG,
546#endif
James Lairdc60de0e2013-03-27 13:00:23 +0000547#if CONFIG_USBBLASTER_SPI == 1
548 SPI_CONTROLLER_USBBLASTER,
549#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000550};
Michael Karcher62797512011-05-11 17:07:02 +0000551
552#define MAX_DATA_UNSPECIFIED 0
553#define MAX_DATA_READ_UNLIMITED 64 * 1024
554#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000555struct spi_programmer {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000556 enum spi_controller type;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000557 unsigned int max_data_read;
558 unsigned int max_data_write;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000559 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000560 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000561 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000562
563 /* Optimized functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000564 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000565 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
566 int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000567 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000568};
569
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000570int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000571 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000572int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000573int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000574int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
575int default_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000576int register_spi_programmer(const struct spi_programmer *programmer);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000577
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000578/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
Stefan Taunera8d838d2011-11-06 23:51:09 +0000579enum ich_chipset {
580 CHIPSET_ICH_UNKNOWN,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000581 CHIPSET_ICH,
582 CHIPSET_ICH2345,
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000583 CHIPSET_ICH6,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000584 CHIPSET_POULSBO, /* SCH U* */
585 CHIPSET_TUNNEL_CREEK, /* Atom E6xx */
586 CHIPSET_CENTERTON, /* Atom S1220 S1240 S1260 */
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000587 CHIPSET_ICH7,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000588 CHIPSET_ICH8,
589 CHIPSET_ICH9,
590 CHIPSET_ICH10,
591 CHIPSET_5_SERIES_IBEX_PEAK,
592 CHIPSET_6_SERIES_COUGAR_POINT,
Stefan Tauner2abab942012-04-27 20:41:23 +0000593 CHIPSET_7_SERIES_PANTHER_POINT,
Duncan Laurie90eb2262013-03-15 03:12:29 +0000594 CHIPSET_8_SERIES_LYNX_POINT,
595 CHIPSET_8_SERIES_LYNX_POINT_LP,
596 CHIPSET_8_SERIES_WELLSBURG,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000597};
598
Stefan Tauner2abab942012-04-27 20:41:23 +0000599/* ichspi.c */
600#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000601extern uint32_t ichspi_bbar;
Stefan Tauner92d6a862013-10-25 00:33:37 +0000602int ich_init_spi(struct pci_dev *dev, void *spibar, enum ich_chipset ich_generation);
Helge Wagnerdd73d832012-08-24 23:03:46 +0000603int via_init_spi(struct pci_dev *dev, uint32_t mmio_base);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000604
Stefan Taunerdbac46c2013-08-13 22:10:41 +0000605/* amd_imc.c */
Rudolf Marek70e14592013-07-25 22:58:56 +0000606int amd_imc_shutdown(struct pci_dev *dev);
607
David Hendricks4e748392011-02-28 23:58:15 +0000608/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000609int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000610
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000611/* it87spi.c */
612void enter_conf_mode_ite(uint16_t port);
613void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000614void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000615int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000616
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000617/* mcp6x_spi.c */
618int mcp6x_spi_init(int want_spi);
619
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000620/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000621int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000622
623/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000624int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000625#endif
626
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000627/* opaque.c */
628struct opaque_programmer {
629 int max_data_read;
630 int max_data_write;
631 /* Specific functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000632 int (*probe) (struct flashctx *flash);
633 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000634 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000635 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000636 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000637};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000638int register_opaque_programmer(const struct opaque_programmer *pgm);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000639
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000640/* programmer.c */
641int noop_shutdown(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000642void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000643void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000644void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
645void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
646void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000647void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000648uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
649uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
650void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
651struct par_programmer {
652 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
653 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
654 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000655 void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000656 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
657 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
658 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
659 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000660 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000661};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000662int register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
663struct registered_programmer {
664 enum chipbustype buses_supported;
665 union {
666 struct par_programmer par;
667 struct spi_programmer spi;
668 struct opaque_programmer opaque;
669 };
670};
671extern struct registered_programmer registered_programmers[];
672extern int registered_programmer_count;
673int register_programmer(struct registered_programmer *pgm);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000674
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000675/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000676#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000677int serprog_init(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000678void serprog_delay(unsigned int usecs);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000679#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000680
681/* serial.c */
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000682#ifdef _WIN32
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000683typedef HANDLE fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000684#define SER_INV_FD INVALID_HANDLE_VALUE
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000685#else
686typedef int fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000687#define SER_INV_FD -1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000688#endif
689
690void sp_flush_incoming(void);
691fdtype sp_openserport(char *dev, unsigned int baud);
Stefan Tauner184c52c2013-08-23 21:51:32 +0000692int serialport_config(fdtype fd, unsigned int baud);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000693extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000694/* expose serialport_shutdown as it's currently used by buspirate */
695int serialport_shutdown(void *data);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000696int serialport_write(const unsigned char *buf, unsigned int writecnt);
697int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000698int serialport_read(unsigned char *buf, unsigned int readcnt);
Stefan Tauner00e16082013-04-01 00:45:38 +0000699int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000700
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000701/* Serial port/pin mapping:
702
703 1 CD <-
704 2 RXD <-
705 3 TXD ->
706 4 DTR ->
707 5 GND --
708 6 DSR <-
709 7 RTS ->
710 8 CTS <-
711 9 RI <-
712*/
713enum SP_PIN {
714 PIN_CD = 1,
715 PIN_RXD,
716 PIN_TXD,
717 PIN_DTR,
718 PIN_GND,
719 PIN_DSR,
720 PIN_RTS,
721 PIN_CTS,
722 PIN_RI,
723};
724
725void sp_set_pin(enum SP_PIN pin, int val);
726int sp_get_pin(enum SP_PIN pin);
727
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000728#endif /* !__PROGRAMMER_H__ */