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