blob: 02d0db8f6902f73d17dbdbab2498a05486bd0854 [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
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000060#if CONFIG_FT2232_SPI == 1
61 PROGRAMMER_FT2232_SPI,
62#endif
63#if CONFIG_SERPROG == 1
64 PROGRAMMER_SERPROG,
65#endif
66#if CONFIG_BUSPIRATE_SPI == 1
67 PROGRAMMER_BUSPIRATE_SPI,
68#endif
69#if CONFIG_DEDIPROG == 1
70 PROGRAMMER_DEDIPROG,
71#endif
72#if CONFIG_RAYER_SPI == 1
73 PROGRAMMER_RAYER_SPI,
74#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +000075#if CONFIG_PONY_SPI == 1
76 PROGRAMMER_PONY_SPI,
77#endif
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000078#if CONFIG_NICINTEL == 1
79 PROGRAMMER_NICINTEL,
80#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +000081#if CONFIG_NICINTEL_SPI == 1
82 PROGRAMMER_NICINTEL_SPI,
83#endif
Mark Marshall90021f22010-12-03 14:48:11 +000084#if CONFIG_OGP_SPI == 1
85 PROGRAMMER_OGP_SPI,
86#endif
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +000087#if CONFIG_SATAMV == 1
88 PROGRAMMER_SATAMV,
89#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +000090#if CONFIG_LINUX_SPI == 1
91 PROGRAMMER_LINUX_SPI,
92#endif
James Lairdc60de0e2013-03-27 13:00:23 +000093#if CONFIG_USBBLASTER_SPI == 1
94 PROGRAMMER_USBBLASTER_SPI,
95#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000096 PROGRAMMER_INVALID /* This must always be the last entry. */
97};
98
Stefan Tauneraf358d62012-12-27 18:40:26 +000099enum programmer_type {
100 PCI = 1, /* to detect uninitialized values */
101 USB,
102 OTHER,
103};
104
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000105struct dev_entry {
106 uint16_t vendor_id;
107 uint16_t device_id;
108 const enum test_state status;
109 const char *vendor_name;
110 const char *device_name;
111};
112
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000113struct programmer_entry {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000114 const char *name;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000115 const enum programmer_type type;
116 union {
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000117 const struct dev_entry *const dev;
Stefan Tauneraf358d62012-12-27 18:40:26 +0000118 const char *const note;
119 } devs;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000120
121 int (*init) (void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000122
Stefan Tauner305e0b92013-07-17 23:46:44 +0000123 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000124 void (*unmap_flash_region) (void *virt_addr, size_t len);
125
Stefan Taunerf80419c2014-05-02 15:41:42 +0000126 void (*delay) (unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000127};
128
129extern const struct programmer_entry programmer_table[];
130
Nico Huberbcb2e5a2012-12-30 01:23:17 +0000131int programmer_init(enum programmer prog, const char *param);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000132int programmer_shutdown(void);
133
134enum bitbang_spi_master_type {
135 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
136#if CONFIG_RAYER_SPI == 1
137 BITBANG_SPI_MASTER_RAYER,
138#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000139#if CONFIG_PONY_SPI == 1
140 BITBANG_SPI_MASTER_PONY,
141#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +0000142#if CONFIG_NICINTEL_SPI == 1
143 BITBANG_SPI_MASTER_NICINTEL,
144#endif
Carl-Daniel Hailfinger2f436162010-07-28 15:08:35 +0000145#if CONFIG_INTERNAL == 1
146#if defined(__i386__) || defined(__x86_64__)
147 BITBANG_SPI_MASTER_MCP,
148#endif
149#endif
Mark Marshall90021f22010-12-03 14:48:11 +0000150#if CONFIG_OGP_SPI == 1
151 BITBANG_SPI_MASTER_OGP,
152#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000153};
154
155struct bitbang_spi_master {
156 enum bitbang_spi_master_type type;
157
158 /* Note that CS# is active low, so val=0 means the chip is active. */
159 void (*set_cs) (int val);
160 void (*set_sck) (int val);
161 void (*set_mosi) (int val);
162 int (*get_miso) (void);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000163 void (*request_bus) (void);
164 void (*release_bus) (void);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000165 /* Length of half a clock period in usecs. */
166 unsigned int half_period;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000167};
168
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000169#if NEED_PCI == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000170struct pci_dev;
Carl-Daniel Hailfingera2faddf2013-01-05 23:52:45 +0000171
172/* pcidev.c */
173// FIXME: These need to be local, not global
174extern uint32_t io_base_addr;
175extern struct pci_access *pacc;
176int pci_init_common(void);
177uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
178struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
179/* rpci_write_* are reversible writes. The original PCI config space register
180 * contents will be restored on shutdown.
181 */
182int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
183int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
184int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
185#endif
186
187#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000188struct penable {
189 uint16_t vendor_id;
190 uint16_t device_id;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000191 const enum test_state status;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000192 const char *vendor_name;
193 const char *device_name;
194 int (*doit) (struct pci_dev *dev, const char *name);
195};
196
197extern const struct penable chipset_enables[];
198
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000199enum board_match_phase {
200 P1,
201 P2,
202 P3
203};
204
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000205struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000206 /* Any device, but make it sensible, like the ISA bridge. */
207 uint16_t first_vendor;
208 uint16_t first_device;
209 uint16_t first_card_vendor;
210 uint16_t first_card_device;
211
212 /* Any device, but make it sensible, like
213 * the host bridge. May be NULL.
214 */
215 uint16_t second_vendor;
216 uint16_t second_device;
217 uint16_t second_card_vendor;
218 uint16_t second_card_device;
219
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000220 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000221 const char *dmi_pattern;
222
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000223 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000224 const char *lb_vendor;
225 const char *lb_part;
226
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000227 enum board_match_phase phase;
228
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000229 const char *vendor_name;
230 const char *board_name;
231
232 int max_rom_decode_parallel;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000233 const enum test_state status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000234 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000235};
236
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000237extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000238
239struct board_info {
240 const char *vendor;
241 const char *name;
Stefan Tauner2c20b282012-07-28 19:35:26 +0000242 const enum test_state working;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000243#ifdef CONFIG_PRINT_WIKI
244 const char *url;
245 const char *note;
246#endif
247};
248
249extern const struct board_info boards_known[];
250extern const struct board_info laptops_known[];
251#endif
252
253/* udelay.c */
Stefan Taunerf80419c2014-05-02 15:41:42 +0000254void myusec_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000255void myusec_calibrate_delay(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000256void internal_sleep(unsigned int usecs);
257void internal_delay(unsigned int usecs);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000258
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000259#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000260/* board_enable.c */
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000261int board_parse_parameter(const char *boardstring, const char **vendor, const char **model);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000262void w836xx_ext_enter(uint16_t port);
263void w836xx_ext_leave(uint16_t port);
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000264void probe_superio_winbond(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000265int it8705f_write_enable(uint8_t port);
266uint8_t sio_read(uint16_t port, uint8_t reg);
267void sio_write(uint16_t port, uint8_t reg, uint8_t data);
268void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000269void board_handle_before_superio(void);
270void board_handle_before_laptop(void);
Stefan Taunerfa9fa712012-09-24 21:29:29 +0000271int 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 +0000272
273/* chipset_enable.c */
274int chipset_flash_enable(void);
275
276/* processor_enable.c */
277int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000278#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000279
280/* physmap.c */
Stefan Tauner305e0b92013-07-17 23:46:44 +0000281void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Stefan Tauner7fb5aa02013-08-14 15:48:44 +0000282void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Niklas Söderlund5d307202013-09-14 09:02:27 +0000283void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000284void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000285void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger43eac032014-03-05 00:16:16 +0000286void physunmap_unaligned(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000287#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000288int setup_cpu_msr(int cpu);
289void cleanup_cpu_msr(void);
290
291/* cbtable.c */
Stefan Taunerb4e06bd2012-08-20 00:24:22 +0000292int cb_parse_table(const char **vendor, const char **model);
293int cb_check_image(uint8_t *bios, int size);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000294
295/* dmi.c */
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000296#if defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000297extern int has_dmi_support;
298void dmi_init(void);
299int dmi_match(const char *pattern);
Sean Nelson4c6d3a42013-09-11 23:35:03 +0000300#endif // defined(__i386__) || defined(__x86_64__)
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000301
302/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000303struct superio {
304 uint16_t vendor;
305 uint16_t port;
306 uint16_t model;
307};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000308extern struct superio superios[];
309extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000310#define SUPERIO_VENDOR_NONE 0x0
311#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerf5e62cb2012-05-06 22:48:01 +0000312#define SUPERIO_VENDOR_WINBOND 0x2
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000313#endif
314#if NEED_PCI == 1
Patrick Georgi32508eb2012-07-20 20:35:14 +0000315struct pci_filter;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000316struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
Uwe Hermann24c35e42011-07-13 11:22:03 +0000317struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000318struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
319struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
320 uint16_t card_vendor, uint16_t card_device);
321#endif
Carl-Daniel Hailfingerd6bb8282012-07-21 17:27:08 +0000322int rget_io_perms(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000323#if CONFIG_INTERNAL == 1
324extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000325extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000326extern int force_boardenable;
327extern int force_boardmismatch;
328void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000329int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000330extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000331int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000332#endif
333
334/* hwaccess.c */
335void mmio_writeb(uint8_t val, void *addr);
336void mmio_writew(uint16_t val, void *addr);
337void mmio_writel(uint32_t val, void *addr);
338uint8_t mmio_readb(void *addr);
339uint16_t mmio_readw(void *addr);
340uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerccd71c22012-03-01 22:38:27 +0000341void mmio_readn(void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000342void mmio_le_writeb(uint8_t val, void *addr);
343void mmio_le_writew(uint16_t val, void *addr);
344void mmio_le_writel(uint32_t val, void *addr);
345uint8_t mmio_le_readb(void *addr);
346uint16_t mmio_le_readw(void *addr);
347uint32_t mmio_le_readl(void *addr);
348#define pci_mmio_writeb mmio_le_writeb
349#define pci_mmio_writew mmio_le_writew
350#define pci_mmio_writel mmio_le_writel
351#define pci_mmio_readb mmio_le_readb
352#define pci_mmio_readw mmio_le_readw
353#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000354void rmmio_writeb(uint8_t val, void *addr);
355void rmmio_writew(uint16_t val, void *addr);
356void rmmio_writel(uint32_t val, void *addr);
357void rmmio_le_writeb(uint8_t val, void *addr);
358void rmmio_le_writew(uint16_t val, void *addr);
359void rmmio_le_writel(uint32_t val, void *addr);
360#define pci_rmmio_writeb rmmio_le_writeb
361#define pci_rmmio_writew rmmio_le_writew
362#define pci_rmmio_writel rmmio_le_writel
363void rmmio_valb(void *addr);
364void rmmio_valw(void *addr);
365void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000366
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000367/* dummyflasher.c */
368#if CONFIG_DUMMY == 1
369int dummy_init(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000370void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000371void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000372#endif
373
374/* nic3com.c */
375#if CONFIG_NIC3COM == 1
376int nic3com_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000377extern const struct dev_entry nics_3com[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000378#endif
379
380/* gfxnvidia.c */
381#if CONFIG_GFXNVIDIA == 1
382int gfxnvidia_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000383extern const struct dev_entry gfx_nvidia[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000384#endif
385
386/* drkaiser.c */
387#if CONFIG_DRKAISER == 1
388int drkaiser_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000389extern const struct dev_entry drkaiser_pcidev[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000390#endif
391
392/* nicrealtek.c */
393#if CONFIG_NICREALTEK == 1
394int nicrealtek_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000395extern const struct dev_entry nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000396#endif
397
398/* nicnatsemi.c */
399#if CONFIG_NICNATSEMI == 1
400int nicnatsemi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000401extern const struct dev_entry nics_natsemi[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000402#endif
403
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000404/* nicintel.c */
405#if CONFIG_NICINTEL == 1
406int nicintel_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000407extern const struct dev_entry nics_intel[];
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000408#endif
409
Idwer Vollering004f4b72010-09-03 18:21:21 +0000410/* nicintel_spi.c */
411#if CONFIG_NICINTEL_SPI == 1
412int nicintel_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000413extern const struct dev_entry nics_intel_spi[];
Idwer Vollering004f4b72010-09-03 18:21:21 +0000414#endif
415
Mark Marshall90021f22010-12-03 14:48:11 +0000416/* ogp_spi.c */
417#if CONFIG_OGP_SPI == 1
418int ogp_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000419extern const struct dev_entry ogp_spi[];
Mark Marshall90021f22010-12-03 14:48:11 +0000420#endif
421
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000422/* satamv.c */
423#if CONFIG_SATAMV == 1
424int satamv_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000425extern const struct dev_entry satas_mv[];
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000426#endif
427
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000428/* satasii.c */
429#if CONFIG_SATASII == 1
430int satasii_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000431extern const struct dev_entry satas_sii[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000432#endif
433
434/* atahpt.c */
435#if CONFIG_ATAHPT == 1
436int atahpt_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000437extern const struct dev_entry ata_hpt[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000438#endif
439
Jonathan Kollasch7f0f3fa2014-06-01 10:26:23 +0000440/* atavia.c */
441#if CONFIG_ATAVIA == 1
442int atavia_init(void);
443void *atavia_map(const char *descr, uintptr_t phys_addr, size_t len);
444extern const struct dev_entry ata_via[];
445#endif
446
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000447/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000448#if CONFIG_FT2232_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000449int ft2232_spi_init(void);
Stefan Tauner4b24a2d2012-12-27 18:40:36 +0000450extern const struct dev_entry devs_ft2232spi[];
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000451#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000452
James Lairdc60de0e2013-03-27 13:00:23 +0000453/* usbblaster_spi.c */
454#if CONFIG_USBBLASTER_SPI == 1
455int usbblaster_spi_init(void);
456extern const struct dev_entry devs_usbblasterspi[];
457#endif
458
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000459/* rayer_spi.c */
460#if CONFIG_RAYER_SPI == 1
461int rayer_spi_init(void);
462#endif
463
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000464/* pony_spi.c */
465#if CONFIG_PONY_SPI == 1
466int pony_spi_init(void);
467#endif
468
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000469/* bitbang_spi.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000470int bitbang_spi_init(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000471
472/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000473#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000474int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000475#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000476
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000477/* linux_spi.c */
478#if CONFIG_LINUX_SPI == 1
479int linux_spi_init(void);
480#endif
481
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000482/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000483#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000484int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000485#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000486
487/* flashrom.c */
488struct decode_sizes {
489 uint32_t parallel;
490 uint32_t lpc;
491 uint32_t fwh;
492 uint32_t spi;
493};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000494// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000495extern struct decode_sizes max_rom_decode;
496extern int programmer_may_write;
497extern unsigned long flashbase;
Carl-Daniel Hailfinger5a7cb842012-08-25 01:17:58 +0000498void check_chip_supported(const struct flashchip *chip);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000499int check_max_decode(enum chipbustype buses, uint32_t size);
Stefan Tauner66652442011-06-26 17:38:17 +0000500char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000501
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000502/* spi.c */
503enum spi_controller {
504 SPI_CONTROLLER_NONE,
505#if CONFIG_INTERNAL == 1
506#if defined(__i386__) || defined(__x86_64__)
507 SPI_CONTROLLER_ICH7,
508 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000509 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000510 SPI_CONTROLLER_IT87XX,
511 SPI_CONTROLLER_SB600,
Wei Hu31402ee2014-05-16 21:39:33 +0000512 SPI_CONTROLLER_YANGTZE,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000513 SPI_CONTROLLER_VIA,
514 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000515#endif
516#endif
517#if CONFIG_FT2232_SPI == 1
518 SPI_CONTROLLER_FT2232,
519#endif
520#if CONFIG_DUMMY == 1
521 SPI_CONTROLLER_DUMMY,
522#endif
523#if CONFIG_BUSPIRATE_SPI == 1
524 SPI_CONTROLLER_BUSPIRATE,
525#endif
526#if CONFIG_DEDIPROG == 1
527 SPI_CONTROLLER_DEDIPROG,
528#endif
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000529#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 +0000530 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000531#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000532#if CONFIG_LINUX_SPI == 1
533 SPI_CONTROLLER_LINUX,
534#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000535#if CONFIG_SERPROG == 1
536 SPI_CONTROLLER_SERPROG,
537#endif
James Lairdc60de0e2013-03-27 13:00:23 +0000538#if CONFIG_USBBLASTER_SPI == 1
539 SPI_CONTROLLER_USBBLASTER,
540#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000541};
Michael Karcher62797512011-05-11 17:07:02 +0000542
543#define MAX_DATA_UNSPECIFIED 0
544#define MAX_DATA_READ_UNLIMITED 64 * 1024
545#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000546struct spi_programmer {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000547 enum spi_controller type;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000548 unsigned int max_data_read;
549 unsigned int max_data_write;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000550 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000551 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000552 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000553
554 /* Optimized functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000555 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000556 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
557 int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000558 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000559};
560
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000561int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000562 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000563int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000564int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000565int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
566int 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 +0000567int register_spi_programmer(const struct spi_programmer *programmer);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000568
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000569/* 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 +0000570enum ich_chipset {
571 CHIPSET_ICH_UNKNOWN,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000572 CHIPSET_ICH,
573 CHIPSET_ICH2345,
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000574 CHIPSET_ICH6,
Stefan Tauner92d6a862013-10-25 00:33:37 +0000575 CHIPSET_POULSBO, /* SCH U* */
576 CHIPSET_TUNNEL_CREEK, /* Atom E6xx */
577 CHIPSET_CENTERTON, /* Atom S1220 S1240 S1260 */
Kyösti Mälkki78cd0872013-09-14 23:36:57 +0000578 CHIPSET_ICH7,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000579 CHIPSET_ICH8,
580 CHIPSET_ICH9,
581 CHIPSET_ICH10,
582 CHIPSET_5_SERIES_IBEX_PEAK,
583 CHIPSET_6_SERIES_COUGAR_POINT,
Stefan Tauner2abab942012-04-27 20:41:23 +0000584 CHIPSET_7_SERIES_PANTHER_POINT,
Duncan Laurie90eb2262013-03-15 03:12:29 +0000585 CHIPSET_8_SERIES_LYNX_POINT,
586 CHIPSET_8_SERIES_LYNX_POINT_LP,
587 CHIPSET_8_SERIES_WELLSBURG,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000588};
589
Stefan Tauner2abab942012-04-27 20:41:23 +0000590/* ichspi.c */
591#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000592extern uint32_t ichspi_bbar;
Stefan Tauner92d6a862013-10-25 00:33:37 +0000593int ich_init_spi(struct pci_dev *dev, void *spibar, enum ich_chipset ich_generation);
Helge Wagnerdd73d832012-08-24 23:03:46 +0000594int via_init_spi(struct pci_dev *dev, uint32_t mmio_base);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000595
Stefan Taunerdbac46c2013-08-13 22:10:41 +0000596/* amd_imc.c */
Rudolf Marek70e14592013-07-25 22:58:56 +0000597int amd_imc_shutdown(struct pci_dev *dev);
598
David Hendricks4e748392011-02-28 23:58:15 +0000599/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000600int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000601
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000602/* it87spi.c */
603void enter_conf_mode_ite(uint16_t port);
604void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000605void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000606int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000607
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000608/* mcp6x_spi.c */
609int mcp6x_spi_init(int want_spi);
610
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000611/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000612int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000613
614/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000615int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000616#endif
617
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000618/* opaque.c */
619struct opaque_programmer {
620 int max_data_read;
621 int max_data_write;
622 /* Specific functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000623 int (*probe) (struct flashctx *flash);
624 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000625 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000626 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000627 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000628};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000629int register_opaque_programmer(const struct opaque_programmer *pgm);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000630
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000631/* programmer.c */
632int noop_shutdown(void);
Stefan Tauner305e0b92013-07-17 23:46:44 +0000633void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000634void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000635void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
636void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
637void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000638void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000639uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
640uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
641void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
642struct par_programmer {
643 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
644 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
645 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000646 void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000647 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
648 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
649 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
650 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000651 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000652};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000653int register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
654struct registered_programmer {
655 enum chipbustype buses_supported;
656 union {
657 struct par_programmer par;
658 struct spi_programmer spi;
659 struct opaque_programmer opaque;
660 };
661};
662extern struct registered_programmer registered_programmers[];
663extern int registered_programmer_count;
664int register_programmer(struct registered_programmer *pgm);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000665
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000666/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000667#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000668int serprog_init(void);
Stefan Taunerf80419c2014-05-02 15:41:42 +0000669void serprog_delay(unsigned int usecs);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000670#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000671
672/* serial.c */
Carl-Daniel Hailfinger60d9bd22012-08-09 23:34:41 +0000673#ifdef _WIN32
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000674typedef HANDLE fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000675#define SER_INV_FD INVALID_HANDLE_VALUE
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000676#else
677typedef int fdtype;
Stefan Taunerbb4fed72012-09-01 21:47:19 +0000678#define SER_INV_FD -1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000679#endif
680
681void sp_flush_incoming(void);
682fdtype sp_openserport(char *dev, unsigned int baud);
Stefan Tauner184c52c2013-08-23 21:51:32 +0000683int serialport_config(fdtype fd, unsigned int baud);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000684extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000685/* expose serialport_shutdown as it's currently used by buspirate */
686int serialport_shutdown(void *data);
Mark Marshallf20b7be2014-05-09 21:16:21 +0000687int serialport_write(const unsigned char *buf, unsigned int writecnt);
688int 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 +0000689int serialport_read(unsigned char *buf, unsigned int readcnt);
Stefan Tauner00e16082013-04-01 00:45:38 +0000690int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000691
Virgil-Adrian Teacada7c5452012-04-30 23:11:06 +0000692/* Serial port/pin mapping:
693
694 1 CD <-
695 2 RXD <-
696 3 TXD ->
697 4 DTR ->
698 5 GND --
699 6 DSR <-
700 7 RTS ->
701 8 CTS <-
702 9 RI <-
703*/
704enum SP_PIN {
705 PIN_CD = 1,
706 PIN_RXD,
707 PIN_TXD,
708 PIN_DTR,
709 PIN_GND,
710 PIN_DSR,
711 PIN_RTS,
712 PIN_CTS,
713 PIN_RI,
714};
715
716void sp_set_pin(enum SP_PIN pin, int val);
717int sp_get_pin(enum SP_PIN pin);
718
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000719#endif /* !__PROGRAMMER_H__ */