blob: d6b9cd668fef1dff9edf7251ce2dcc9f5e048e15 [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 */
267void lb_vendor_dev_from_string(char *boardstring);
268int 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);
315void mmio_le_writeb(uint8_t val, void *addr);
316void mmio_le_writew(uint16_t val, void *addr);
317void mmio_le_writel(uint32_t val, void *addr);
318uint8_t mmio_le_readb(void *addr);
319uint16_t mmio_le_readw(void *addr);
320uint32_t mmio_le_readl(void *addr);
321#define pci_mmio_writeb mmio_le_writeb
322#define pci_mmio_writew mmio_le_writew
323#define pci_mmio_writel mmio_le_writel
324#define pci_mmio_readb mmio_le_readb
325#define pci_mmio_readw mmio_le_readw
326#define pci_mmio_readl mmio_le_readl
Carl-Daniel Hailfinger54ce73a2011-05-03 21:49:41 +0000327void rmmio_writeb(uint8_t val, void *addr);
328void rmmio_writew(uint16_t val, void *addr);
329void rmmio_writel(uint32_t val, void *addr);
330void rmmio_le_writeb(uint8_t val, void *addr);
331void rmmio_le_writew(uint16_t val, void *addr);
332void rmmio_le_writel(uint32_t val, void *addr);
333#define pci_rmmio_writeb rmmio_le_writeb
334#define pci_rmmio_writew rmmio_le_writew
335#define pci_rmmio_writel rmmio_le_writel
336void rmmio_valb(void *addr);
337void rmmio_valw(void *addr);
338void rmmio_vall(void *addr);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000339
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000340/* dummyflasher.c */
341#if CONFIG_DUMMY == 1
342int dummy_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000343void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
344void dummy_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000345#endif
346
347/* nic3com.c */
348#if CONFIG_NIC3COM == 1
349int nic3com_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000350extern const struct pcidev_status nics_3com[];
351#endif
352
353/* gfxnvidia.c */
354#if CONFIG_GFXNVIDIA == 1
355int gfxnvidia_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000356extern const struct pcidev_status gfx_nvidia[];
357#endif
358
359/* drkaiser.c */
360#if CONFIG_DRKAISER == 1
361int drkaiser_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000362extern const struct pcidev_status drkaiser_pcidev[];
363#endif
364
365/* nicrealtek.c */
366#if CONFIG_NICREALTEK == 1
367int nicrealtek_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000368extern const struct pcidev_status nics_realtek[];
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000369#endif
370
371/* nicnatsemi.c */
372#if CONFIG_NICNATSEMI == 1
373int nicnatsemi_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000374extern const struct pcidev_status nics_natsemi[];
375#endif
376
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000377/* nicintel.c */
378#if CONFIG_NICINTEL == 1
379int nicintel_init(void);
Carl-Daniel Hailfingerb713d2e2011-05-08 00:24:18 +0000380extern const struct pcidev_status nics_intel[];
381#endif
382
Idwer Vollering004f4b72010-09-03 18:21:21 +0000383/* nicintel_spi.c */
384#if CONFIG_NICINTEL_SPI == 1
385int nicintel_spi_init(void);
Idwer Vollering004f4b72010-09-03 18:21:21 +0000386extern const struct pcidev_status nics_intel_spi[];
387#endif
388
Mark Marshall90021f22010-12-03 14:48:11 +0000389/* ogp_spi.c */
390#if CONFIG_OGP_SPI == 1
391int ogp_spi_init(void);
Mark Marshall90021f22010-12-03 14:48:11 +0000392extern const struct pcidev_status ogp_spi[];
393#endif
394
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000395/* satamv.c */
396#if CONFIG_SATAMV == 1
397int satamv_init(void);
Carl-Daniel Hailfinger9a1105c2011-02-04 21:37:59 +0000398extern const struct pcidev_status satas_mv[];
399#endif
400
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000401/* satasii.c */
402#if CONFIG_SATASII == 1
403int satasii_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000404extern const struct pcidev_status satas_sii[];
405#endif
406
407/* atahpt.c */
408#if CONFIG_ATAHPT == 1
409int atahpt_init(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000410extern const struct pcidev_status ata_hpt[];
411#endif
412
413/* ft2232_spi.c */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000414#if CONFIG_FT2232_SPI == 1
415struct usbdev_status {
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000416 uint16_t vendor_id;
417 uint16_t device_id;
418 int status;
419 const char *vendor_name;
420 const char *device_name;
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000421};
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000422int ft2232_spi_init(void);
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000423extern const struct usbdev_status devs_ft2232spi[];
424void print_supported_usbdevs(const struct usbdev_status *devs);
425#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000426
427/* rayer_spi.c */
428#if CONFIG_RAYER_SPI == 1
429int rayer_spi_init(void);
430#endif
431
432/* bitbang_spi.c */
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000433int bitbang_spi_init(const struct bitbang_spi_master *master);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000434
435/* buspirate_spi.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000436#if CONFIG_BUSPIRATE_SPI == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000437int buspirate_spi_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000438#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000439
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000440/* linux_spi.c */
441#if CONFIG_LINUX_SPI == 1
442int linux_spi_init(void);
443#endif
444
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000445/* dediprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000446#if CONFIG_DEDIPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000447int dediprog_init(void);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000448#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000449
450/* flashrom.c */
451struct decode_sizes {
452 uint32_t parallel;
453 uint32_t lpc;
454 uint32_t fwh;
455 uint32_t spi;
456};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000457// FIXME: These need to be local, not global
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000458extern struct decode_sizes max_rom_decode;
459extern int programmer_may_write;
460extern unsigned long flashbase;
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000461void check_chip_supported(const struct flashctx *flash);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000462int check_max_decode(enum chipbustype buses, uint32_t size);
Stefan Tauner66652442011-06-26 17:38:17 +0000463char *extract_programmer_param(const char *param_name);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000464
465/* layout.c */
466int show_id(uint8_t *bios, int size, int force);
467
468/* spi.c */
469enum spi_controller {
470 SPI_CONTROLLER_NONE,
471#if CONFIG_INTERNAL == 1
472#if defined(__i386__) || defined(__x86_64__)
473 SPI_CONTROLLER_ICH7,
474 SPI_CONTROLLER_ICH9,
David Hendricks4e748392011-02-28 23:58:15 +0000475 SPI_CONTROLLER_IT85XX,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000476 SPI_CONTROLLER_IT87XX,
477 SPI_CONTROLLER_SB600,
478 SPI_CONTROLLER_VIA,
479 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000480#endif
481#endif
482#if CONFIG_FT2232_SPI == 1
483 SPI_CONTROLLER_FT2232,
484#endif
485#if CONFIG_DUMMY == 1
486 SPI_CONTROLLER_DUMMY,
487#endif
488#if CONFIG_BUSPIRATE_SPI == 1
489 SPI_CONTROLLER_BUSPIRATE,
490#endif
491#if CONFIG_DEDIPROG == 1
492 SPI_CONTROLLER_DEDIPROG,
493#endif
Michael Karcherb9dbe482011-05-11 17:07:07 +0000494#if CONFIG_OGP_SPI == 1 || CONFIG_NICINTEL_SPI == 1 || CONFIG_RAYER_SPI == 1 || (CONFIG_INTERNAL == 1 && (defined(__i386__) || defined(__x86_64__)))
495 SPI_CONTROLLER_BITBANG,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000496#endif
Sven Schnelle5ce5f702011-09-03 18:37:52 +0000497#if CONFIG_LINUX_SPI == 1
498 SPI_CONTROLLER_LINUX,
499#endif
Urja Rannikkoc93f5f12011-09-15 23:38:14 +0000500#if CONFIG_SERPROG == 1
501 SPI_CONTROLLER_SERPROG,
502#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000503};
Michael Karcher62797512011-05-11 17:07:02 +0000504
505#define MAX_DATA_UNSPECIFIED 0
506#define MAX_DATA_READ_UNLIMITED 64 * 1024
507#define MAX_DATA_WRITE_UNLIMITED 256
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000508struct spi_programmer {
Michael Karcherb9dbe482011-05-11 17:07:07 +0000509 enum spi_controller type;
Stefan Taunerc69c9c82011-11-23 09:13:48 +0000510 unsigned int max_data_read;
511 unsigned int max_data_write;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000512 int (*command)(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000513 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000514 int (*multicommand)(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000515
516 /* Optimized functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000517 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
518 int (*write_256)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000519 const void *data;
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000520};
521
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000522int default_spi_send_command(struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000523 const unsigned char *writearr, unsigned char *readarr);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000524int default_spi_send_multicommand(struct flashctx *flash, struct spi_command *cmds);
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000525int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
526int default_spi_write_256(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000527int register_spi_programmer(const struct spi_programmer *programmer);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000528
529/* ichspi.c */
Stefan Taunera8d838d2011-11-06 23:51:09 +0000530enum ich_chipset {
531 CHIPSET_ICH_UNKNOWN,
532 CHIPSET_ICH7 = 7,
533 CHIPSET_ICH8,
534 CHIPSET_ICH9,
535 CHIPSET_ICH10,
536 CHIPSET_5_SERIES_IBEX_PEAK,
537 CHIPSET_6_SERIES_COUGAR_POINT,
538 CHIPSET_7_SERIES_PANTHER_POINT
539};
540
Stefan Taunerb3850962011-12-24 00:00:32 +0000541#if CONFIG_INTERNAL == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000542extern uint32_t ichspi_bbar;
543int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
Stefan Taunera8d838d2011-11-06 23:51:09 +0000544 enum ich_chipset ich_generation);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000545int via_init_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000546
David Hendricks4e748392011-02-28 23:58:15 +0000547/* it85spi.c */
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000548int it85xx_spi_init(struct superio s);
David Hendricks4e748392011-02-28 23:58:15 +0000549
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000550/* it87spi.c */
551void enter_conf_mode_ite(uint16_t port);
552void exit_conf_mode_ite(uint16_t port);
Carl-Daniel Hailfingerbfecef62011-04-27 14:34:08 +0000553void probe_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000554int init_superio_ite(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000555
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000556/* mcp6x_spi.c */
557int mcp6x_spi_init(int want_spi);
558
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000559/* sb600spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000560int sb600_probe_spi(struct pci_dev *dev);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000561
562/* wbsio_spi.c */
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000563int wbsio_check_for_spi(void);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000564#endif
565
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000566/* opaque.c */
567struct opaque_programmer {
568 int max_data_read;
569 int max_data_write;
570 /* Specific functions for this programmer */
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +0000571 int (*probe) (struct flashctx *flash);
572 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
573 int (*write) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
574 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000575 const void *data;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000576};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000577int register_opaque_programmer(const struct opaque_programmer *pgm);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +0000578
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000579/* programmer.c */
580int noop_shutdown(void);
581void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
582void fallback_unmap(void *virt_addr, size_t len);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000583void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
584void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
585void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
586void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
587uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
588uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
589void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
590struct par_programmer {
591 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
592 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
593 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
594 void (*chip_writen) (const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len);
595 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
596 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
597 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
598 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000599 const void *data;
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000600};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +0000601int register_par_programmer(const struct par_programmer *pgm, const enum chipbustype buses);
602struct registered_programmer {
603 enum chipbustype buses_supported;
604 union {
605 struct par_programmer par;
606 struct spi_programmer spi;
607 struct opaque_programmer opaque;
608 };
609};
610extern struct registered_programmer registered_programmers[];
611extern int registered_programmer_count;
612int register_programmer(struct registered_programmer *pgm);
Carl-Daniel Hailfinger8a3c60c2011-12-18 15:01:24 +0000613
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000614/* serprog.c */
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000615#if CONFIG_SERPROG == 1
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000616int serprog_init(void);
Stefan Tauner31019d42011-10-22 21:45:27 +0000617void serprog_delay(int usecs);
Carl-Daniel Hailfingerc4224842011-06-09 20:06:34 +0000618#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000619
620/* serial.c */
621#if _WIN32
622typedef HANDLE fdtype;
623#else
624typedef int fdtype;
625#endif
626
627void sp_flush_incoming(void);
628fdtype sp_openserport(char *dev, unsigned int baud);
629void __attribute__((noreturn)) sp_die(char *msg);
630extern fdtype sp_fd;
David Hendricks8bb20212011-06-14 01:35:36 +0000631/* expose serialport_shutdown as it's currently used by buspirate */
632int serialport_shutdown(void *data);
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000633int serialport_write(unsigned char *buf, unsigned int writecnt);
634int serialport_read(unsigned char *buf, unsigned int readcnt);
635
636#endif /* !__PROGRAMMER_H__ */