blob: 68ad500b6dc1ebe916aa473ab6aaa24a6517a6fa [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
27enum programmer {
28#if CONFIG_INTERNAL == 1
29 PROGRAMMER_INTERNAL,
30#endif
31#if CONFIG_DUMMY == 1
32 PROGRAMMER_DUMMY,
33#endif
34#if CONFIG_NIC3COM == 1
35 PROGRAMMER_NIC3COM,
36#endif
37#if CONFIG_NICREALTEK == 1
38 PROGRAMMER_NICREALTEK,
39 PROGRAMMER_NICREALTEK2,
40#endif
41#if CONFIG_NICNATSEMI == 1
42 PROGRAMMER_NICNATSEMI,
43#endif
44#if CONFIG_GFXNVIDIA == 1
45 PROGRAMMER_GFXNVIDIA,
46#endif
47#if CONFIG_DRKAISER == 1
48 PROGRAMMER_DRKAISER,
49#endif
50#if CONFIG_SATASII == 1
51 PROGRAMMER_SATASII,
52#endif
53#if CONFIG_ATAHPT == 1
54 PROGRAMMER_ATAHPT,
55#endif
56#if CONFIG_INTERNAL == 1
57#if defined(__i386__) || defined(__x86_64__)
58 PROGRAMMER_IT87SPI,
59#endif
60#endif
61#if CONFIG_FT2232_SPI == 1
62 PROGRAMMER_FT2232_SPI,
63#endif
64#if CONFIG_SERPROG == 1
65 PROGRAMMER_SERPROG,
66#endif
67#if CONFIG_BUSPIRATE_SPI == 1
68 PROGRAMMER_BUSPIRATE_SPI,
69#endif
70#if CONFIG_DEDIPROG == 1
71 PROGRAMMER_DEDIPROG,
72#endif
73#if CONFIG_RAYER_SPI == 1
74 PROGRAMMER_RAYER_SPI,
75#endif
76 PROGRAMMER_INVALID /* This must always be the last entry. */
77};
78
79extern enum programmer programmer;
80
81struct programmer_entry {
82 const char *vendor;
83 const char *name;
84
85 int (*init) (void);
86 int (*shutdown) (void);
87
88 void * (*map_flash_region) (const char *descr, unsigned long phys_addr,
89 size_t len);
90 void (*unmap_flash_region) (void *virt_addr, size_t len);
91
92 void (*chip_writeb) (uint8_t val, chipaddr addr);
93 void (*chip_writew) (uint16_t val, chipaddr addr);
94 void (*chip_writel) (uint32_t val, chipaddr addr);
95 void (*chip_writen) (uint8_t *buf, chipaddr addr, size_t len);
96 uint8_t (*chip_readb) (const chipaddr addr);
97 uint16_t (*chip_readw) (const chipaddr addr);
98 uint32_t (*chip_readl) (const chipaddr addr);
99 void (*chip_readn) (uint8_t *buf, const chipaddr addr, size_t len);
100 void (*delay) (int usecs);
101};
102
103extern const struct programmer_entry programmer_table[];
104
105int programmer_init(char *param);
106int 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
113};
114
115struct bitbang_spi_master {
116 enum bitbang_spi_master_type type;
117
118 /* Note that CS# is active low, so val=0 means the chip is active. */
119 void (*set_cs) (int val);
120 void (*set_sck) (int val);
121 void (*set_mosi) (int val);
122 int (*get_miso) (void);
123};
124
125#if CONFIG_INTERNAL == 1
126struct penable {
127 uint16_t vendor_id;
128 uint16_t device_id;
129 int status;
130 const char *vendor_name;
131 const char *device_name;
132 int (*doit) (struct pci_dev *dev, const char *name);
133};
134
135extern const struct penable chipset_enables[];
136
137struct board_pciid_enable {
138 /* Any device, but make it sensible, like the ISA bridge. */
139 uint16_t first_vendor;
140 uint16_t first_device;
141 uint16_t first_card_vendor;
142 uint16_t first_card_device;
143
144 /* Any device, but make it sensible, like
145 * the host bridge. May be NULL.
146 */
147 uint16_t second_vendor;
148 uint16_t second_device;
149 uint16_t second_card_vendor;
150 uint16_t second_card_device;
151
152 /* Pattern to match DMI entries */
153 const char *dmi_pattern;
154
155 /* The vendor / part name from the coreboot table. */
156 const char *lb_vendor;
157 const char *lb_part;
158
159 const char *vendor_name;
160 const char *board_name;
161
162 int max_rom_decode_parallel;
163 int status;
164 int (*enable) (void);
165};
166
167extern const struct board_pciid_enable board_pciid_enables[];
168
169struct board_info {
170 const char *vendor;
171 const char *name;
172 const int working;
173#ifdef CONFIG_PRINT_WIKI
174 const char *url;
175 const char *note;
176#endif
177};
178
179extern const struct board_info boards_known[];
180extern const struct board_info laptops_known[];
181#endif
182
183/* udelay.c */
184void myusec_delay(int usecs);
185void myusec_calibrate_delay(void);
186void internal_delay(int usecs);
187
188#if NEED_PCI == 1
189/* pcidev.c */
190extern uint32_t io_base_addr;
191extern struct pci_access *pacc;
192extern struct pci_dev *pcidev_dev;
193struct pcidev_status {
194 uint16_t vendor_id;
195 uint16_t device_id;
196 int status;
197 const char *vendor_name;
198 const char *device_name;
199};
200uint32_t pcidev_validate(struct pci_dev *dev, uint32_t bar, const struct pcidev_status *devs);
201uint32_t pcidev_init(uint16_t vendor_id, uint32_t bar, const struct pcidev_status *devs);
202#endif
203
204/* print.c */
205#if CONFIG_NIC3COM+CONFIG_NICREALTEK+CONFIG_NICNATSEMI+CONFIG_GFXNVIDIA+CONFIG_DRKAISER+CONFIG_SATASII+CONFIG_ATAHPT >= 1
206void print_supported_pcidevs(const struct pcidev_status *devs);
207#endif
208
209/* board_enable.c */
210void w836xx_ext_enter(uint16_t port);
211void w836xx_ext_leave(uint16_t port);
212int it8705f_write_enable(uint8_t port);
213uint8_t sio_read(uint16_t port, uint8_t reg);
214void sio_write(uint16_t port, uint8_t reg, uint8_t data);
215void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
216int board_flash_enable(const char *vendor, const char *part);
217
218/* chipset_enable.c */
219int chipset_flash_enable(void);
220
221/* processor_enable.c */
222int processor_flash_enable(void);
223
224/* physmap.c */
225void *physmap(const char *descr, unsigned long phys_addr, size_t len);
226void *physmap_try_ro(const char *descr, unsigned long phys_addr, size_t len);
227void physunmap(void *virt_addr, size_t len);
228int setup_cpu_msr(int cpu);
229void cleanup_cpu_msr(void);
230
231/* cbtable.c */
232void lb_vendor_dev_from_string(char *boardstring);
233int coreboot_init(void);
234extern char *lb_part, *lb_vendor;
235extern int partvendor_from_cbtable;
236
237/* dmi.c */
238extern int has_dmi_support;
239void dmi_init(void);
240int dmi_match(const char *pattern);
241
242/* internal.c */
243#if NEED_PCI == 1
244struct superio {
245 uint16_t vendor;
246 uint16_t port;
247 uint16_t model;
248};
249extern struct superio superio;
250#define SUPERIO_VENDOR_NONE 0x0
251#define SUPERIO_VENDOR_ITE 0x1
252struct pci_dev *pci_dev_find_filter(struct pci_filter filter);
253struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t class);
254struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
255struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
256 uint16_t card_vendor, uint16_t card_device);
257#endif
258void get_io_perms(void);
259void release_io_perms(void);
260#if CONFIG_INTERNAL == 1
261extern int is_laptop;
262extern int force_boardenable;
263extern int force_boardmismatch;
264void probe_superio(void);
265int internal_init(void);
266int internal_shutdown(void);
267void internal_chip_writeb(uint8_t val, chipaddr addr);
268void internal_chip_writew(uint16_t val, chipaddr addr);
269void internal_chip_writel(uint32_t val, chipaddr addr);
270uint8_t internal_chip_readb(const chipaddr addr);
271uint16_t internal_chip_readw(const chipaddr addr);
272uint32_t internal_chip_readl(const chipaddr addr);
273void internal_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
274#endif
275
276/* hwaccess.c */
277void mmio_writeb(uint8_t val, void *addr);
278void mmio_writew(uint16_t val, void *addr);
279void mmio_writel(uint32_t val, void *addr);
280uint8_t mmio_readb(void *addr);
281uint16_t mmio_readw(void *addr);
282uint32_t mmio_readl(void *addr);
283void mmio_le_writeb(uint8_t val, void *addr);
284void mmio_le_writew(uint16_t val, void *addr);
285void mmio_le_writel(uint32_t val, void *addr);
286uint8_t mmio_le_readb(void *addr);
287uint16_t mmio_le_readw(void *addr);
288uint32_t mmio_le_readl(void *addr);
289#define pci_mmio_writeb mmio_le_writeb
290#define pci_mmio_writew mmio_le_writew
291#define pci_mmio_writel mmio_le_writel
292#define pci_mmio_readb mmio_le_readb
293#define pci_mmio_readw mmio_le_readw
294#define pci_mmio_readl mmio_le_readl
295
296/* programmer.c */
297int noop_shutdown(void);
298void *fallback_map(const char *descr, unsigned long phys_addr, size_t len);
299void fallback_unmap(void *virt_addr, size_t len);
300uint8_t noop_chip_readb(const chipaddr addr);
301void noop_chip_writeb(uint8_t val, chipaddr addr);
302void fallback_chip_writew(uint16_t val, chipaddr addr);
303void fallback_chip_writel(uint32_t val, chipaddr addr);
304void fallback_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
305uint16_t fallback_chip_readw(const chipaddr addr);
306uint32_t fallback_chip_readl(const chipaddr addr);
307void fallback_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
308
309/* dummyflasher.c */
310#if CONFIG_DUMMY == 1
311int dummy_init(void);
312int dummy_shutdown(void);
313void *dummy_map(const char *descr, unsigned long phys_addr, size_t len);
314void dummy_unmap(void *virt_addr, size_t len);
315void dummy_chip_writeb(uint8_t val, chipaddr addr);
316void dummy_chip_writew(uint16_t val, chipaddr addr);
317void dummy_chip_writel(uint32_t val, chipaddr addr);
318void dummy_chip_writen(uint8_t *buf, chipaddr addr, size_t len);
319uint8_t dummy_chip_readb(const chipaddr addr);
320uint16_t dummy_chip_readw(const chipaddr addr);
321uint32_t dummy_chip_readl(const chipaddr addr);
322void dummy_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
323int dummy_spi_send_command(unsigned int writecnt, unsigned int readcnt,
324 const unsigned char *writearr, unsigned char *readarr);
325int dummy_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
326int dummy_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
327#endif
328
329/* nic3com.c */
330#if CONFIG_NIC3COM == 1
331int nic3com_init(void);
332int nic3com_shutdown(void);
333void nic3com_chip_writeb(uint8_t val, chipaddr addr);
334uint8_t nic3com_chip_readb(const chipaddr addr);
335extern const struct pcidev_status nics_3com[];
336#endif
337
338/* gfxnvidia.c */
339#if CONFIG_GFXNVIDIA == 1
340int gfxnvidia_init(void);
341int gfxnvidia_shutdown(void);
342void gfxnvidia_chip_writeb(uint8_t val, chipaddr addr);
343uint8_t gfxnvidia_chip_readb(const chipaddr addr);
344extern const struct pcidev_status gfx_nvidia[];
345#endif
346
347/* drkaiser.c */
348#if CONFIG_DRKAISER == 1
349int drkaiser_init(void);
350int drkaiser_shutdown(void);
351void drkaiser_chip_writeb(uint8_t val, chipaddr addr);
352uint8_t drkaiser_chip_readb(const chipaddr addr);
353extern const struct pcidev_status drkaiser_pcidev[];
354#endif
355
356/* nicrealtek.c */
357#if CONFIG_NICREALTEK == 1
358int nicrealtek_init(void);
359int nicsmc1211_init(void);
360int nicrealtek_shutdown(void);
361void nicrealtek_chip_writeb(uint8_t val, chipaddr addr);
362uint8_t nicrealtek_chip_readb(const chipaddr addr);
363extern const struct pcidev_status nics_realtek[];
364extern const struct pcidev_status nics_realteksmc1211[];
365#endif
366
367/* nicnatsemi.c */
368#if CONFIG_NICNATSEMI == 1
369int nicnatsemi_init(void);
370int nicnatsemi_shutdown(void);
371void nicnatsemi_chip_writeb(uint8_t val, chipaddr addr);
372uint8_t nicnatsemi_chip_readb(const chipaddr addr);
373extern const struct pcidev_status nics_natsemi[];
374#endif
375
376/* satasii.c */
377#if CONFIG_SATASII == 1
378int satasii_init(void);
379int satasii_shutdown(void);
380void satasii_chip_writeb(uint8_t val, chipaddr addr);
381uint8_t satasii_chip_readb(const chipaddr addr);
382extern const struct pcidev_status satas_sii[];
383#endif
384
385/* atahpt.c */
386#if CONFIG_ATAHPT == 1
387int atahpt_init(void);
388int atahpt_shutdown(void);
389void atahpt_chip_writeb(uint8_t val, chipaddr addr);
390uint8_t atahpt_chip_readb(const chipaddr addr);
391extern const struct pcidev_status ata_hpt[];
392#endif
393
394/* ft2232_spi.c */
395#define FTDI_FT2232H 0x6010
396#define FTDI_FT4232H 0x6011
397int ft2232_spi_init(void);
398int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
399int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
400int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
401
402/* rayer_spi.c */
403#if CONFIG_RAYER_SPI == 1
404int rayer_spi_init(void);
405#endif
406
407/* bitbang_spi.c */
408int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
409int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
410int bitbang_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
411int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
412
413/* buspirate_spi.c */
414struct buspirate_spispeeds {
415 const char *name;
416 const int speed;
417};
418int buspirate_spi_init(void);
419int buspirate_spi_shutdown(void);
420int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
421int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
422int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
423
424/* dediprog.c */
425int dediprog_init(void);
426int dediprog_shutdown(void);
427int dediprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
428int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
429
430/* flashrom.c */
431struct decode_sizes {
432 uint32_t parallel;
433 uint32_t lpc;
434 uint32_t fwh;
435 uint32_t spi;
436};
437extern struct decode_sizes max_rom_decode;
438extern int programmer_may_write;
439extern unsigned long flashbase;
440void check_chip_supported(struct flashchip *flash);
441int check_max_decode(enum chipbustype buses, uint32_t size);
442char *extract_programmer_param(char *param_name);
443
444/* layout.c */
445int show_id(uint8_t *bios, int size, int force);
446
447/* spi.c */
448enum spi_controller {
449 SPI_CONTROLLER_NONE,
450#if CONFIG_INTERNAL == 1
451#if defined(__i386__) || defined(__x86_64__)
452 SPI_CONTROLLER_ICH7,
453 SPI_CONTROLLER_ICH9,
454 SPI_CONTROLLER_IT87XX,
455 SPI_CONTROLLER_SB600,
456 SPI_CONTROLLER_VIA,
457 SPI_CONTROLLER_WBSIO,
458#endif
459#endif
460#if CONFIG_FT2232_SPI == 1
461 SPI_CONTROLLER_FT2232,
462#endif
463#if CONFIG_DUMMY == 1
464 SPI_CONTROLLER_DUMMY,
465#endif
466#if CONFIG_BUSPIRATE_SPI == 1
467 SPI_CONTROLLER_BUSPIRATE,
468#endif
469#if CONFIG_DEDIPROG == 1
470 SPI_CONTROLLER_DEDIPROG,
471#endif
472#if CONFIG_RAYER_SPI == 1
473 SPI_CONTROLLER_RAYER,
474#endif
475 SPI_CONTROLLER_INVALID /* This must always be the last entry. */
476};
477extern const int spi_programmer_count;
478struct spi_programmer {
479 int (*command)(unsigned int writecnt, unsigned int readcnt,
480 const unsigned char *writearr, unsigned char *readarr);
481 int (*multicommand)(struct spi_command *cmds);
482
483 /* Optimized functions for this programmer */
484 int (*read)(struct flashchip *flash, uint8_t *buf, int start, int len);
485 int (*write_256)(struct flashchip *flash, uint8_t *buf, int start, int len);
486};
487
488extern enum spi_controller spi_controller;
489extern const struct spi_programmer spi_programmer[];
490int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
491 const unsigned char *writearr, unsigned char *readarr);
492int default_spi_send_multicommand(struct spi_command *cmds);
493
494/* ichspi.c */
495#if CONFIG_INTERNAL == 1
496extern uint32_t ichspi_bbar;
497int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
498 int ich_generation);
499int via_init_spi(struct pci_dev *dev);
500int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
501 const unsigned char *writearr, unsigned char *readarr);
502int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
503int ich_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len);
504int ich_spi_send_multicommand(struct spi_command *cmds);
505#endif
506
507/* it87spi.c */
508void enter_conf_mode_ite(uint16_t port);
509void exit_conf_mode_ite(uint16_t port);
510struct superio probe_superio_ite(void);
511int init_superio_ite(void);
512int it87spi_init(void);
513int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
514 const unsigned char *writearr, unsigned char *readarr);
515int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
516int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
517
518/* sb600spi.c */
519#if CONFIG_INTERNAL == 1
520int sb600_probe_spi(struct pci_dev *dev);
521int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt,
522 const unsigned char *writearr, unsigned char *readarr);
523int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
524int sb600_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
525#endif
526
527/* wbsio_spi.c */
528#if CONFIG_INTERNAL == 1
529int wbsio_check_for_spi(void);
530int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt,
531 const unsigned char *writearr, unsigned char *readarr);
532int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
533#endif
534
535/* serprog.c */
536int serprog_init(void);
537int serprog_shutdown(void);
538void serprog_chip_writeb(uint8_t val, chipaddr addr);
539uint8_t serprog_chip_readb(const chipaddr addr);
540void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
541void serprog_delay(int delay);
542
543/* serial.c */
544#if _WIN32
545typedef HANDLE fdtype;
546#else
547typedef int fdtype;
548#endif
549
550void sp_flush_incoming(void);
551fdtype sp_openserport(char *dev, unsigned int baud);
552void __attribute__((noreturn)) sp_die(char *msg);
553extern fdtype sp_fd;
554int serialport_shutdown(void);
555int serialport_write(unsigned char *buf, unsigned int writecnt);
556int serialport_read(unsigned char *buf, unsigned int readcnt);
557
558#endif /* !__PROGRAMMER_H__ */