blob: b3f99b497615207d49ba5fed8b1f29b63acd3d51 [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 */
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000400#if CONFIG_FT2232_SPI == 1
401struct usbdev_status {
Uwe Hermann48ec1b12010-08-08 17:01:18 +0000402 uint16_t vendor_id;
403 uint16_t device_id;
404 int status;
405 const char *vendor_name;
406 const char *device_name;
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000407};
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000408int ft2232_spi_init(void);
409int ft2232_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
410int ft2232_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
411int ft2232_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
Jörg Fischer6529b9f2010-07-29 15:54:53 +0000412extern const struct usbdev_status devs_ft2232spi[];
413void print_supported_usbdevs(const struct usbdev_status *devs);
414#endif
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000415
416/* rayer_spi.c */
417#if CONFIG_RAYER_SPI == 1
418int rayer_spi_init(void);
419#endif
420
Carl-Daniel Hailfinger2f436162010-07-28 15:08:35 +0000421/* mcp6x_spi.c */
422#if CONFIG_INTERNAL == 1
423#if defined(__i386__) || defined(__x86_64__)
424int mcp6x_spi_init(int want_spi);
425#endif
426#endif
427
Carl-Daniel Hailfinger5b997c32010-07-27 22:41:39 +0000428/* bitbang_spi.c */
429int bitbang_spi_init(const struct bitbang_spi_master *master, int halfperiod);
430int bitbang_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
431int bitbang_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
432int bitbang_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
433
434/* buspirate_spi.c */
435struct buspirate_spispeeds {
436 const char *name;
437 const int speed;
438};
439int buspirate_spi_init(void);
440int buspirate_spi_shutdown(void);
441int buspirate_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
442int buspirate_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
443int buspirate_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
444
445/* dediprog.c */
446int dediprog_init(void);
447int dediprog_shutdown(void);
448int dediprog_spi_send_command(unsigned int writecnt, unsigned int readcnt, const unsigned char *writearr, unsigned char *readarr);
449int dediprog_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
450
451/* flashrom.c */
452struct decode_sizes {
453 uint32_t parallel;
454 uint32_t lpc;
455 uint32_t fwh;
456 uint32_t spi;
457};
458extern struct decode_sizes max_rom_decode;
459extern int programmer_may_write;
460extern unsigned long flashbase;
461void check_chip_supported(struct flashchip *flash);
462int check_max_decode(enum chipbustype buses, uint32_t size);
463char *extract_programmer_param(char *param_name);
464
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,
475 SPI_CONTROLLER_IT87XX,
476 SPI_CONTROLLER_SB600,
477 SPI_CONTROLLER_VIA,
478 SPI_CONTROLLER_WBSIO,
Carl-Daniel Hailfinger2f436162010-07-28 15:08:35 +0000479 SPI_CONTROLLER_MCP6X_BITBANG,
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
494#if CONFIG_RAYER_SPI == 1
495 SPI_CONTROLLER_RAYER,
496#endif
497 SPI_CONTROLLER_INVALID /* This must always be the last entry. */
498};
499extern const int spi_programmer_count;
500struct spi_programmer {
501 int (*command)(unsigned int writecnt, unsigned int readcnt,
502 const unsigned char *writearr, unsigned char *readarr);
503 int (*multicommand)(struct spi_command *cmds);
504
505 /* Optimized functions for this programmer */
506 int (*read)(struct flashchip *flash, uint8_t *buf, int start, int len);
507 int (*write_256)(struct flashchip *flash, uint8_t *buf, int start, int len);
508};
509
510extern enum spi_controller spi_controller;
511extern const struct spi_programmer spi_programmer[];
512int default_spi_send_command(unsigned int writecnt, unsigned int readcnt,
513 const unsigned char *writearr, unsigned char *readarr);
514int default_spi_send_multicommand(struct spi_command *cmds);
515
516/* ichspi.c */
517#if CONFIG_INTERNAL == 1
518extern uint32_t ichspi_bbar;
519int ich_init_spi(struct pci_dev *dev, uint32_t base, void *rcrb,
520 int ich_generation);
521int via_init_spi(struct pci_dev *dev);
522int ich_spi_send_command(unsigned int writecnt, unsigned int readcnt,
523 const unsigned char *writearr, unsigned char *readarr);
524int ich_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
525int ich_spi_write_256(struct flashchip *flash, uint8_t * buf, int start, int len);
526int ich_spi_send_multicommand(struct spi_command *cmds);
527#endif
528
529/* it87spi.c */
530void enter_conf_mode_ite(uint16_t port);
531void exit_conf_mode_ite(uint16_t port);
532struct superio probe_superio_ite(void);
533int init_superio_ite(void);
534int it87spi_init(void);
535int it8716f_spi_send_command(unsigned int writecnt, unsigned int readcnt,
536 const unsigned char *writearr, unsigned char *readarr);
537int it8716f_spi_chip_read(struct flashchip *flash, uint8_t *buf, int start, int len);
538int it8716f_spi_chip_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
539
540/* sb600spi.c */
541#if CONFIG_INTERNAL == 1
542int sb600_probe_spi(struct pci_dev *dev);
543int sb600_spi_send_command(unsigned int writecnt, unsigned int readcnt,
544 const unsigned char *writearr, unsigned char *readarr);
545int sb600_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
546int sb600_spi_write_256(struct flashchip *flash, uint8_t *buf, int start, int len);
547#endif
548
549/* wbsio_spi.c */
550#if CONFIG_INTERNAL == 1
551int wbsio_check_for_spi(void);
552int wbsio_spi_send_command(unsigned int writecnt, unsigned int readcnt,
553 const unsigned char *writearr, unsigned char *readarr);
554int wbsio_spi_read(struct flashchip *flash, uint8_t *buf, int start, int len);
555#endif
556
557/* serprog.c */
558int serprog_init(void);
559int serprog_shutdown(void);
560void serprog_chip_writeb(uint8_t val, chipaddr addr);
561uint8_t serprog_chip_readb(const chipaddr addr);
562void serprog_chip_readn(uint8_t *buf, const chipaddr addr, size_t len);
563void serprog_delay(int delay);
564
565/* serial.c */
566#if _WIN32
567typedef HANDLE fdtype;
568#else
569typedef int fdtype;
570#endif
571
572void sp_flush_incoming(void);
573fdtype sp_openserport(char *dev, unsigned int baud);
574void __attribute__((noreturn)) sp_die(char *msg);
575extern fdtype sp_fd;
576int serialport_shutdown(void);
577int serialport_write(unsigned char *buf, unsigned int writecnt);
578int serialport_read(unsigned char *buf, unsigned int readcnt);
579
580#endif /* !__PROGRAMMER_H__ */