blob: c99e37fdda261db4e4a237c8ba9ba970ab88ee67 [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
Carl-Daniel Hailfinger5b997c32010-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
66#if CONFIG_DEDIPROG == 1
67 PROGRAMMER_DEDIPROG,
68#endif
69#if CONFIG_RAYER_SPI == 1
70 PROGRAMMER_RAYER_SPI,
71#endif
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +000072#if CONFIG_NICINTEL == 1
73 PROGRAMMER_NICINTEL,
74#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +000075#if CONFIG_NICINTEL_SPI == 1
76 PROGRAMMER_NICINTEL_SPI,
77#endif
Mark Marshall90021f22010-12-03 14:48:11 +000078#if CONFIG_OGP_SPI == 1
79 PROGRAMMER_OGP_SPI,
80#endif
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +000081#if CONFIG_SATAMV == 1
82 PROGRAMMER_SATAMV,
83#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +000084#if CONFIG_LINUX_SPI == 1
85 PROGRAMMER_LINUX_SPI,
86#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000087 PROGRAMMER_INVALID /* This must always be the last entry. */
88};
89
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000090struct programmer_entry {
91 const char *vendor;
92 const char *name;
93
94 int (*init) (void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000095
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +000096 void *(*map_flash_region) (const char *descr, unsigned long phys_addr,
97 size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +000098 void (*unmap_flash_region) (void *virt_addr, size_t len);
99
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000100 void (*delay) (int usecs);
101};
102
103extern const struct programmer_entry programmer_table[];
104
Carl-Daniel Hailfinger2e681602011-09-08 00:00:29 +0000105int programmer_init(enum programmer prog, char *param);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000106int programmer_shutdown(void);
107
108enum bitbang_spi_master_type {
109 BITBANG_SPI_INVALID = 0, /* This must always be the first entry. */
110#if CONFIG_RAYER_SPI == 1
111 BITBANG_SPI_MASTER_RAYER,
112#endif
Idwer Vollering004f4b72010-09-03 18:21:21 +0000113#if CONFIG_NICINTEL_SPI == 1
114 BITBANG_SPI_MASTER_NICINTEL,
115#endif
Carl-Daniel Hailfinger2f436162010-07-28 15:08:35 +0000116#if CONFIG_INTERNAL == 1
117#if defined(__i386__) || defined(__x86_64__)
118 BITBANG_SPI_MASTER_MCP,
119#endif
120#endif
Mark Marshall90021f22010-12-03 14:48:11 +0000121#if CONFIG_OGP_SPI == 1
122 BITBANG_SPI_MASTER_OGP,
123#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000124};
125
126struct bitbang_spi_master {
127 enum bitbang_spi_master_type type;
128
129 /* Note that CS# is active low, so val=0 means the chip is active. */
130 void (*set_cs) (int val);
131 void (*set_sck) (int val);
132 void (*set_mosi) (int val);
133 int (*get_miso) (void);
Carl-Daniel Hailfinger28228882010-09-15 00:17:37 +0000134 void (*request_bus) (void);
135 void (*release_bus) (void);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000136 /* Length of half a clock period in usecs. */
137 unsigned int half_period;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000138};
139
140#if CONFIG_INTERNAL == 1
141struct penable {
142 uint16_t vendor_id;
143 uint16_t device_id;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000144 int status; /* OK=0 and NT=1 are defines only. Beware! */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000145 const char *vendor_name;
146 const char *device_name;
147 int (*doit) (struct pci_dev *dev, const char *name);
148};
149
150extern const struct penable chipset_enables[];
151
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000152enum board_match_phase {
153 P1,
154 P2,
155 P3
156};
157
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000158struct board_match {
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000159 /* Any device, but make it sensible, like the ISA bridge. */
160 uint16_t first_vendor;
161 uint16_t first_device;
162 uint16_t first_card_vendor;
163 uint16_t first_card_device;
164
165 /* Any device, but make it sensible, like
166 * the host bridge. May be NULL.
167 */
168 uint16_t second_vendor;
169 uint16_t second_device;
170 uint16_t second_card_vendor;
171 uint16_t second_card_device;
172
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000173 /* Pattern to match DMI entries. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000174 const char *dmi_pattern;
175
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000176 /* The vendor / part name from the coreboot table. May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000177 const char *lb_vendor;
178 const char *lb_part;
179
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000180 enum board_match_phase phase;
181
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000182 const char *vendor_name;
183 const char *board_name;
184
185 int max_rom_decode_parallel;
186 int status;
Stefan Tauner7bcacb12011-05-26 01:35:19 +0000187 int (*enable) (void); /* May be NULL. */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000188};
189
Carl-Daniel Hailfinger97d5b122011-08-31 16:19:50 +0000190extern const struct board_match board_matches[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000191
192struct board_info {
193 const char *vendor;
194 const char *name;
195 const int working;
196#ifdef CONFIG_PRINT_WIKI
197 const char *url;
198 const char *note;
199#endif
200};
201
202extern const struct board_info boards_known[];
203extern const struct board_info laptops_known[];
204#endif
205
206/* udelay.c */
207void myusec_delay(int usecs);
208void myusec_calibrate_delay(void);
209void internal_delay(int usecs);
210
211#if NEED_PCI == 1
212/* pcidev.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000213// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000214extern uint32_t io_base_addr;
215extern struct pci_access *pacc;
216extern struct pci_dev *pcidev_dev;
217struct pcidev_status {
218 uint16_t vendor_id;
219 uint16_t device_id;
220 int status;
221 const char *vendor_name;
222 const char *device_name;
223};
Carl-Daniel Hailfinger8a19ef12011-02-15 22:44:27 +0000224uintptr_t pcidev_validate(struct pci_dev *dev, int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger40446ee2011-03-07 01:08:09 +0000225uintptr_t pcidev_init(int bar, const struct pcidev_status *devs);
Carl-Daniel Hailfinger2bee8cf2010-11-10 15:25:18 +0000226/* rpci_write_* are reversible writes. The original PCI config space register
227 * contents will be restored on shutdown.
228 */
Idwer Vollering1a6162e2010-12-26 23:55:19 +0000229int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
230int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
231int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000232#endif
233
234/* print.c */
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000235#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
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000236void print_supported_pcidevs(const struct pcidev_status *devs);
237#endif
238
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000239#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000240/* board_enable.c */
241void w836xx_ext_enter(uint16_t port);
242void w836xx_ext_leave(uint16_t port);
243int it8705f_write_enable(uint8_t port);
244uint8_t sio_read(uint16_t port, uint8_t reg);
245void sio_write(uint16_t port, uint8_t reg, uint8_t data);
246void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000247void board_handle_before_superio(void);
248void board_handle_before_laptop(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000249int board_flash_enable(const char *vendor, const char *part);
250
251/* chipset_enable.c */
252int chipset_flash_enable(void);
253
254/* processor_enable.c */
255int processor_flash_enable(void);
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000256#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000257
258/* physmap.c */
259void *physmap(const char *descr, unsigned long phys_addr, size_t len);
260void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
261void physunmap(void *virt_addr, size_t len);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000262#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000263int setup_cpu_msr(int cpu);
264void cleanup_cpu_msr(void);
265
266/* cbtable.c */
Carl-Daniel Hailfinger2d927fb2012-01-04 00:48:27 +0000267void lb_vendor_dev_from_string(const char *boardstring);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000268int coreboot_init(void);
269extern char *lb_part, *lb_vendor;
270extern int partvendor_from_cbtable;
271
272/* dmi.c */
273extern int has_dmi_support;
274void dmi_init(void);
275int dmi_match(const char *pattern);
276
277/* internal.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000278struct superio {
279 uint16_t vendor;
280 uint16_t port;
281 uint16_t model;
282};
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000283extern struct superio superios[];
284extern int superio_count;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000285#define SUPERIO_VENDOR_NONE 0x0
286#define SUPERIO_VENDOR_ITE 0x1
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000287#endif
288#if NEED_PCI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000289struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
Uwe Hermann24c35e42011-07-13 11:22:03 +0000290struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000291struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
292struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
293 uint16_t card_vendor, uint16_t card_device);
294#endif
295void get_io_perms(void);
296void release_io_perms(void);
297#if CONFIG_INTERNAL == 1
298extern int is_laptop;
Carl-Daniel Hailfinger580d29a2011-05-05 07:12:40 +0000299extern int laptop_ok;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000300extern int force_boardenable;
301extern int force_boardmismatch;
302void probe_superio(void);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000303int register_superio(struct superio s);
Carl-Daniel Hailfingereaacd2d2011-11-09 23:40:00 +0000304extern enum chipbustype internal_buses_supported;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000305int internal_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000306#endif
307
308/* hwaccess.c */
309void mmio_writeb(uint8_t val, void *addr);
310void mmio_writew(uint16_t val, void *addr);
311void mmio_writel(uint32_t val, void *addr);
312uint8_t mmio_readb(void *addr);
313uint16_t mmio_readw(void *addr);
314uint32_t mmio_readl(void *addr);
Carl-Daniel Hailfingerccd71c22012-03-01 22:38:27 +0000315void mmio_readn(void *addr, uint8_t *buf, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000316void mmio_le_writeb(uint8_t val, void *addr);
317void mmio_le_writew(uint16_t val, void *addr);
318void mmio_le_writel(uint32_t val, void *addr);
319uint8_t mmio_le_readb(void *addr);
320uint16_t mmio_le_readw(void *addr);
321uint32_t mmio_le_readl(void *addr);
322#define pci_mmio_writeb mmio_le_writeb
323#define pci_mmio_writew mmio_le_writew
324#define pci_mmio_writel mmio_le_writel
325#define pci_mmio_readb mmio_le_readb
326#define pci_mmio_readw mmio_le_readw
327#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000328void rmmio_writeb(uint8_t val, void *addr);
329void rmmio_writew(uint16_t val, void *addr);
330void rmmio_writel(uint32_t val, void *addr);
331void rmmio_le_writeb(uint8_t val, void *addr);
332void rmmio_le_writew(uint16_t val, void *addr);
333void rmmio_le_writel(uint32_t val, void *addr);
334#define pci_rmmio_writeb rmmio_le_writeb
335#define pci_rmmio_writew rmmio_le_writew
336#define pci_rmmio_writel rmmio_le_writel
337void rmmio_valb(void *addr);
338void rmmio_valw(void *addr);
339void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000340
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000341/* dummyflasher.c */
342#if CONFIG_DUMMY == 1
343int dummy_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000344void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
345void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000346#endif
347
348/* nic3com.c */
349#if CONFIG_NIC3COM == 1
350int nic3com_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000351extern const struct pcidev_status nics_3com[];
352#endif
353
354/* gfxnvidia.c */
355#if CONFIG_GFXNVIDIA == 1
356int gfxnvidia_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000357extern const struct pcidev_status gfx_nvidia[];
358#endif
359
360/* drkaiser.c */
361#if CONFIG_DRKAISER == 1
362int drkaiser_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000363extern const struct pcidev_status drkaiser_pcidev[];
364#endif
365
366/* nicrealtek.c */
367#if CONFIG_NICREALTEK == 1
368int nicrealtek_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000369extern const struct pcidev_status nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000370#endif
371
372/* nicnatsemi.c */
373#if CONFIG_NICNATSEMI == 1
374int nicnatsemi_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000375extern const struct pcidev_status nics_natsemi[];
376#endif
377
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000378/* nicintel.c */
379#if CONFIG_NICINTEL == 1
380int nicintel_init(void);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000381extern const struct pcidev_status nics_intel[];
382#endif
383
Idwer Vollering004f4b72010-09-03 18:21:21 +0000384/* nicintel_spi.c */
385#if CONFIG_NICINTEL_SPI == 1
386int nicintel_spi_init(void);
Idwer Vollering004f4b72010-09-03 18:21:21 +0000387extern const struct pcidev_status nics_intel_spi[];
388#endif
389
Mark Marshall90021f22010-12-03 14:48:11 +0000390/* ogp_spi.c */
391#if CONFIG_OGP_SPI == 1
392int ogp_spi_init(void);
Mark Marshall90021f22010-12-03 14:48:11 +0000393extern const struct pcidev_status ogp_spi[];
394#endif
395
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000396/* satamv.c */
397#if CONFIG_SATAMV == 1
398int satamv_init(void);
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000399extern const struct pcidev_status satas_mv[];
400#endif
401
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000402/* satasii.c */
403#if CONFIG_SATASII == 1
404int satasii_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000405extern const struct pcidev_status satas_sii[];
406#endif
407
408/* atahpt.c */
409#if CONFIG_ATAHPT == 1
410int atahpt_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000411extern const struct pcidev_status ata_hpt[];
412#endif
413
414/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000415#if CONFIG_FT2232_SPI == 1
416struct usbdev_status {
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000417 uint16_t vendor_id;
418 uint16_t device_id;
419 int status;
420 const char *vendor_name;
421 const char *device_name;
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000422};
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000423int ft2232_spi_init(void);
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000424extern const struct usbdev_status devs_ft2232spi[];
425void print_supported_usbdevs(const struct usbdev_status *devs);
426#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000427
428/* rayer_spi.c */
429#if CONFIG_RAYER_SPI == 1
430int rayer_spi_init(void);
431#endif
432
433/* bitbang_spi.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000434int bitbang_spi_init(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000435
436/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000437#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000438int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000439#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000440
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000441/* linux_spi.c */
442#if CONFIG_LINUX_SPI == 1
443int linux_spi_init(void);
444#endif
445
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000446/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000447#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000448int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000449#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000450
451/* flashrom.c */
452struct decode_sizes {
453 uint32_t parallel;
454 uint32_t lpc;
455 uint32_t fwh;
456 uint32_t spi;
457};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000458// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000459extern struct decode_sizes max_rom_decode;
460extern int programmer_may_write;
461extern unsigned long flashbase;
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000462void check_chip_supported(const struct flashctx *flash);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000463int check_max_decode(enum chipbustype buses, uint32_t size);
Stefan Tauner66652442011-06-26 17:38:17 +0000464char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000465
466/* layout.c */
467int show_id(uint8_t *bios, int size, int force);
468
469/* spi.c */
470enum spi_controller {
471 SPI_CONTROLLER_NONE,
472#if CONFIG_INTERNAL == 1
473#if defined(__i386__) || defined(__x86_64__)
474 SPI_CONTROLLER_ICH7,
475 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000476 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000477 SPI_CONTROLLER_IT87XX,
478 SPI_CONTROLLER_SB600,
479 SPI_CONTROLLER_VIA,
480 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000481#endif
482#endif
483#if CONFIG_FT2232_SPI == 1
484 SPI_CONTROLLER_FT2232,
485#endif
486#if CONFIG_DUMMY == 1
487 SPI_CONTROLLER_DUMMY,
488#endif
489#if CONFIG_BUSPIRATE_SPI == 1
490 SPI_CONTROLLER_BUSPIRATE,
491#endif
492#if CONFIG_DEDIPROG == 1
493 SPI_CONTROLLER_DEDIPROG,
494#endif
Michael Karcherb9dbe482011-05-11 17:07:07 +0000495#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__)))
496 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000497#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000498#if CONFIG_LINUX_SPI == 1
499 SPI_CONTROLLER_LINUX,
500#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000501#if CONFIG_SERPROG == 1
502 SPI_CONTROLLER_SERPROG,
503#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000504};
Michael Karcher62797512011-05-11 17:07:02 +0000505
506#define MAX_DATA_UNSPECIFIED 0
507#define MAX_DATA_READ_UNLIMITED 64 * 1024
508#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000509struct spi_programmer {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000510 enum spi_controller type;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000511 unsigned int max_data_read;
512 unsigned int max_data_write;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000513 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000514 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000515 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000516
517 /* Optimized functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000518 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
519 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000520 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000521};
522
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000523int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000524 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000525int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000526int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
527int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000528int register_spi_programmer(const struct spi_programmer *programmer);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000529
530/* ichspi.c */
David Hendricksb286da72012-02-13 00:35:35 +0000531#if CONFIG_INTERNAL == 1
Stefan Taunera8d838d2011-11-06 23:51:09 +0000532enum ich_chipset {
533 CHIPSET_ICH_UNKNOWN,
534 CHIPSET_ICH7 = 7,
535 CHIPSET_ICH8,
536 CHIPSET_ICH9,
537 CHIPSET_ICH10,
538 CHIPSET_5_SERIES_IBEX_PEAK,
539 CHIPSET_6_SERIES_COUGAR_POINT,
540 CHIPSET_7_SERIES_PANTHER_POINT
541};
542
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000543extern uint32_t ichspi_bbar;
544int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000545 enum ich_chipset ich_generation);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000546int via_init_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000547
David Hendricks4e748392011-02-28 23:58:15 +0000548/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000549int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000550
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000551/* it87spi.c */
552void enter_conf_mode_ite(uint16_t port);
553void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000554void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000555int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000556
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000557/* mcp6x_spi.c */
558int mcp6x_spi_init(int want_spi);
559
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000560/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000561int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000562
563/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000564int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000565#endif
566
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000567/* opaque.c */
568struct opaque_programmer {
569 int max_data_read;
570 int max_data_write;
571 /* Specific functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000572 int (*probe) (struct flashctx *flash);
573 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
574 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
575 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000576 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000577};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000578int register_opaque_programmer(const struct opaque_programmer *pgm);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000579
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000580/* programmer.c */
581int noop_shutdown(void);
582void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
583void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000584void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
585void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
586void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
587void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
588uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
589uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
590void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
591struct par_programmer {
592 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
593 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
594 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
595 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
596 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
597 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
598 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
599 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000600 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000601};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000602int register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
603struct registered_programmer {
604 enum chipbustype buses_supported;
605 union {
606 struct par_programmer par;
607 struct spi_programmer spi;
608 struct opaque_programmer opaque;
609 };
610};
611extern struct registered_programmer registered_programmers[];
612extern int registered_programmer_count;
613int register_programmer(struct registered_programmer *pgm);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000614
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000615/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000616#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000617int serprog_init(void);
Stefan Tauner31019d42011-10-22 21:45:27 +0000618void serprog_delay(int usecs);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000619#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000620
621/* serial.c */
622#if _WIN32
623typedef HANDLE fdtype;
624#else
625typedef int fdtype;
626#endif
627
628void sp_flush_incoming(void);
629fdtype sp_openserport(char *dev, unsigned int baud);
630void __attribute__((noreturn)) sp_die(char *msg);
631extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000632/* expose serialport_shutdown as it's currently used by buspirate */
633int serialport_shutdown(void *data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000634int serialport_write(unsigned char *buf, unsigned int writecnt);
635int serialport_read(unsigned char *buf, unsigned int readcnt);
636
637#endif /* !__PROGRAMMER_H__ */