blob: 92a26b02b6d2c9b74ea50cbbef66ba8712a0e471 [file] [log] [blame]
hailfinger428f6852010-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.
hailfinger428f6852010-07-27 22:41:39 +000018 */
19
20#ifndef __PROGRAMMER_H__
21#define __PROGRAMMER_H__ 1
22
Edward O'Callaghana6673bd2019-06-24 15:22:28 +100023#include <stdint.h>
24
Souvik Ghoshd75cd672016-06-17 14:21:39 -070025#include "flash.h" /* for chipaddr and flashctx */
hailfingerfe7cd9e2011-11-04 21:35:26 +000026
hailfinger428f6852010-07-27 22:41:39 +000027enum 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,
uwe6764e922010-09-03 18:21:21 +000039#endif
hailfinger428f6852010-07-27 22:41:39 +000040#if CONFIG_NICNATSEMI == 1
41 PROGRAMMER_NICNATSEMI,
uwe6764e922010-09-03 18:21:21 +000042#endif
hailfinger428f6852010-07-27 22:41:39 +000043#if CONFIG_GFXNVIDIA == 1
44 PROGRAMMER_GFXNVIDIA,
45#endif
46#if CONFIG_DRKAISER == 1
47 PROGRAMMER_DRKAISER,
48#endif
49#if CONFIG_SATASII == 1
50 PROGRAMMER_SATASII,
51#endif
52#if CONFIG_ATAHPT == 1
53 PROGRAMMER_ATAHPT,
54#endif
hailfinger428f6852010-07-27 22:41:39 +000055#if CONFIG_FT2232_SPI == 1
56 PROGRAMMER_FT2232_SPI,
57#endif
58#if CONFIG_SERPROG == 1
59 PROGRAMMER_SERPROG,
60#endif
61#if CONFIG_BUSPIRATE_SPI == 1
62 PROGRAMMER_BUSPIRATE_SPI,
63#endif
Anton Staafb2647882014-09-17 15:13:43 -070064#if CONFIG_RAIDEN_DEBUG_SPI == 1
65 PROGRAMMER_RAIDEN_DEBUG_SPI,
66#endif
hailfinger428f6852010-07-27 22:41:39 +000067#if CONFIG_DEDIPROG == 1
68 PROGRAMMER_DEDIPROG,
69#endif
70#if CONFIG_RAYER_SPI == 1
71 PROGRAMMER_RAYER_SPI,
72#endif
hailfinger7949b652011-05-08 00:24:18 +000073#if CONFIG_NICINTEL == 1
74 PROGRAMMER_NICINTEL,
75#endif
uwe6764e922010-09-03 18:21:21 +000076#if CONFIG_NICINTEL_SPI == 1
77 PROGRAMMER_NICINTEL_SPI,
78#endif
hailfingerfb1f31f2010-12-03 14:48:11 +000079#if CONFIG_OGP_SPI == 1
80 PROGRAMMER_OGP_SPI,
81#endif
hailfinger935365d2011-02-04 21:37:59 +000082#if CONFIG_SATAMV == 1
83 PROGRAMMER_SATAMV,
84#endif
David Hendrickscebee892015-05-23 20:30:30 -070085#if CONFIG_LINUX_MTD == 1
86 PROGRAMMER_LINUX_MTD,
87#endif
uwe7df6dda2011-09-03 18:37:52 +000088#if CONFIG_LINUX_SPI == 1
89 PROGRAMMER_LINUX_SPI,
90#endif
Shiyu Sun9dde7162020-04-16 17:32:55 +100091#if CONFIG_LSPCON_I2C_SPI == 1
92 PROGRAMMER_LSPCON_I2C_SPI,
93#endif
Edward O'Callaghan97dd9262020-03-26 00:00:41 +110094#if CONFIG_REALTEK_MST_I2C_SPI == 1
95 PROGRAMMER_REALTEK_MST_I2C_SPI,
96#endif
Edward O'Callaghand8f72232020-09-30 14:21:42 +100097#if CONFIG_GOOGLE_EC == 1
98 PROGRAMMER_GOOGLE_EC,
99#endif
hailfinger428f6852010-07-27 22:41:39 +0000100 PROGRAMMER_INVALID /* This must always be the last entry. */
101};
102
David Hendricksba0827a2013-05-03 20:25:40 -0700103enum alias_type {
104 ALIAS_NONE = 0, /* no alias (default) */
105 ALIAS_EC, /* embedded controller */
106 ALIAS_HOST, /* chipset / PCH / SoC / etc. */
107};
108
109struct programmer_alias {
110 const char *name;
111 enum alias_type type;
112};
113
114extern struct programmer_alias *alias;
115extern struct programmer_alias aliases[];
116
Vadim Bendebury066143d2018-07-16 18:20:33 -0700117/*
118 * This function returns 'true' if current flashrom invocation is programming
119 * the EC.
120 */
121static inline int programming_ec(void) {
122 return alias && (alias->type == ALIAS_EC);
123}
124
Edward O'Callaghan0949b782019-11-10 23:23:20 +1100125enum programmer_type {
126 PCI = 1, /* to detect uninitialized values */
127 USB,
128 OTHER,
129};
130
131struct dev_entry {
132 uint16_t vendor_id;
133 uint16_t device_id;
134 const enum test_state status;
135 const char *vendor_name;
136 const char *device_name;
137};
138
hailfinger428f6852010-07-27 22:41:39 +0000139struct programmer_entry {
hailfinger428f6852010-07-27 22:41:39 +0000140 const char *name;
Edward O'Callaghan0949b782019-11-10 23:23:20 +1100141 const enum programmer_type type;
142 union {
143 const struct dev_entry *const dev;
144 const char *const note;
145 } devs;
hailfinger428f6852010-07-27 22:41:39 +0000146
David Hendricksac1d25c2016-08-09 17:00:58 -0700147 int (*init) (void);
hailfinger428f6852010-07-27 22:41:39 +0000148
Patrick Georgi4befc162017-02-03 18:32:01 +0100149 void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000150 void (*unmap_flash_region) (void *virt_addr, size_t len);
151
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000152 void (*delay) (unsigned int usecs);
David Hendricks55cdd9c2015-11-25 14:37:26 -0800153
154 /*
155 * If set, use extra precautions such as erasing with small block sizes
156 * and verifying more rigorously. This will incur a performance penalty
157 * but is good for programming the ROM in-system on a live machine.
158 */
159 int paranoid;
hailfinger428f6852010-07-27 22:41:39 +0000160};
161
162extern const struct programmer_entry programmer_table[];
163
Edward O'Callaghanb2257cc2020-07-25 22:19:47 +1000164int programmer_init(enum programmer prog, const char *param);
David Hendricks93784b42016-08-09 17:00:38 -0700165int programmer_shutdown(void);
hailfinger428f6852010-07-27 22:41:39 +0000166
hailfinger428f6852010-07-27 22:41:39 +0000167struct bitbang_spi_master {
hailfinger428f6852010-07-27 22:41:39 +0000168 /* Note that CS# is active low, so val=0 means the chip is active. */
169 void (*set_cs) (int val);
170 void (*set_sck) (int val);
171 void (*set_mosi) (int val);
172 int (*get_miso) (void);
hailfinger12cba9a2010-09-15 00:17:37 +0000173 void (*request_bus) (void);
174 void (*release_bus) (void);
Patrick Georgie081d5d2017-03-22 21:18:18 +0100175
176 /* Length of half a clock period in usecs. */
177 unsigned int half_period;
hailfinger428f6852010-07-27 22:41:39 +0000178};
179
Edward O'Callaghan63e1dbf2020-10-03 00:50:45 +1000180#if NEED_PCI == 1
Mayur Panchalf4796862019-08-05 15:46:12 +1000181struct pci_dev;
Edward O'Callaghan63e1dbf2020-10-03 00:50:45 +1000182
183/* pcidev.c */
184// FIXME: This needs to be local, not global(?)
185extern struct pci_access *pacc;
186int pci_init_common(void);
187uintptr_t pcidev_readbar(struct pci_dev *dev, int bar);
188struct pci_dev *pcidev_init(const struct dev_entry *devs, int bar);
189/* rpci_write_* are reversible writes. The original PCI config space register
190 * contents will be restored on shutdown.
191 * To clone the pci_dev instances internally, the `pacc` global
192 * variable has to reference a pci_access method that is compatible
193 * with the given pci_dev handle. The referenced pci_access (not
194 * the variable) has to stay valid until the shutdown handlers are
195 * finished.
196 */
197int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data);
198int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data);
199int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data);
200#endif
201
202#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000203struct penable {
204 uint16_t vendor_id;
205 uint16_t device_id;
Edward O'Callaghan01c39672020-05-27 19:13:26 +1000206 enum chipbustype buses;
stefanct6d836ba2011-05-26 01:35:19 +0000207 int status; /* OK=0 and NT=1 are defines only. Beware! */
hailfinger428f6852010-07-27 22:41:39 +0000208 const char *vendor_name;
209 const char *device_name;
210 int (*doit) (struct pci_dev *dev, const char *name);
211};
212
213extern const struct penable chipset_enables[];
214
hailfingere52e9f82011-05-05 07:12:40 +0000215enum board_match_phase {
216 P1,
217 P2,
218 P3
219};
220
hailfinger4640bdb2011-08-31 16:19:50 +0000221struct board_match {
hailfinger428f6852010-07-27 22:41:39 +0000222 /* Any device, but make it sensible, like the ISA bridge. */
223 uint16_t first_vendor;
224 uint16_t first_device;
225 uint16_t first_card_vendor;
226 uint16_t first_card_device;
227
228 /* Any device, but make it sensible, like
229 * the host bridge. May be NULL.
230 */
231 uint16_t second_vendor;
232 uint16_t second_device;
233 uint16_t second_card_vendor;
234 uint16_t second_card_device;
235
stefanct6d836ba2011-05-26 01:35:19 +0000236 /* Pattern to match DMI entries. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000237 const char *dmi_pattern;
238
stefanct6d836ba2011-05-26 01:35:19 +0000239 /* The vendor / part name from the coreboot table. May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000240 const char *lb_vendor;
241 const char *lb_part;
242
hailfingere52e9f82011-05-05 07:12:40 +0000243 enum board_match_phase phase;
244
hailfinger428f6852010-07-27 22:41:39 +0000245 const char *vendor_name;
246 const char *board_name;
247
248 int max_rom_decode_parallel;
249 int status;
stefanct6d836ba2011-05-26 01:35:19 +0000250 int (*enable) (void); /* May be NULL. */
hailfinger428f6852010-07-27 22:41:39 +0000251};
252
hailfinger4640bdb2011-08-31 16:19:50 +0000253extern const struct board_match board_matches[];
hailfinger428f6852010-07-27 22:41:39 +0000254
255struct board_info {
256 const char *vendor;
257 const char *name;
258 const int working;
259#ifdef CONFIG_PRINT_WIKI
260 const char *url;
261 const char *note;
262#endif
263};
264
265extern const struct board_info boards_known[];
266extern const struct board_info laptops_known[];
267#endif
268
269/* udelay.c */
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000270void myusec_delay(unsigned int usecs);
hailfinger428f6852010-07-27 22:41:39 +0000271void myusec_calibrate_delay(void);
Nikolai Artemievc40dd0e2020-07-15 15:57:55 +1000272void internal_sleep(unsigned int usecs);
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000273void internal_delay(unsigned int usecs);
Nikolai Artemievdf53e852020-08-28 15:57:00 +1000274void internal_sleep(unsigned int usecs);
hailfinger428f6852010-07-27 22:41:39 +0000275
hailfingere20dc562011-06-09 20:06:34 +0000276#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000277/* board_enable.c */
278void w836xx_ext_enter(uint16_t port);
279void w836xx_ext_leave(uint16_t port);
280int it8705f_write_enable(uint8_t port);
281uint8_t sio_read(uint16_t port, uint8_t reg);
282void sio_write(uint16_t port, uint8_t reg, uint8_t data);
283void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask);
hailfingere52e9f82011-05-05 07:12:40 +0000284void board_handle_before_superio(void);
285void board_handle_before_laptop(void);
hailfinger428f6852010-07-27 22:41:39 +0000286int board_flash_enable(const char *vendor, const char *part);
287
288/* chipset_enable.c */
289int chipset_flash_enable(void);
Louis Yung-Chieh Lo6b8f0462011-01-06 12:49:46 +0800290int get_target_bus_from_chipset(enum chipbustype *target_bus);
hailfinger428f6852010-07-27 22:41:39 +0000291
292/* processor_enable.c */
293int processor_flash_enable(void);
hailfingere52e9f82011-05-05 07:12:40 +0000294#endif
hailfinger428f6852010-07-27 22:41:39 +0000295
296/* physmap.c */
Patrick Georgi4befc162017-02-03 18:32:01 +0100297void *physmap(const char *descr, uintptr_t phys_addr, size_t len);
Patrick Georgi220f4b52017-03-21 16:55:04 +0100298void *rphysmap(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan64a4db22019-05-30 03:13:07 -0400299void *physmap_ro(const char *descr, uintptr_t phys_addr, size_t len);
Edward O'Callaghan0822bc22019-10-29 14:26:30 +1100300void *physmap_ro_unaligned(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000301void physunmap(void *virt_addr, size_t len);
Edward O'Callaghanb2878982019-05-30 03:44:32 -0400302void physunmap_unaligned(void *virt_addr, size_t len);
hailfingere20dc562011-06-09 20:06:34 +0000303#if CONFIG_INTERNAL == 1
hailfinger428f6852010-07-27 22:41:39 +0000304int setup_cpu_msr(int cpu);
305void cleanup_cpu_msr(void);
306
307/* cbtable.c */
Edward O'Callaghan481cce82019-05-31 15:03:50 +1000308int cb_parse_table(const char **vendor, const char **model);
Edward O'Callaghan0d105752020-09-18 12:15:41 +1000309int cb_check_image(const uint8_t *bios, unsigned int size);
Carl-Daniel Hailfingere5ec66e2016-08-03 16:10:19 -0700310void lb_vendor_dev_from_string(const char *boardstring);
hailfinger428f6852010-07-27 22:41:39 +0000311extern int partvendor_from_cbtable;
312
313/* dmi.c */
314extern int has_dmi_support;
315void dmi_init(void);
316int dmi_match(const char *pattern);
317
318/* internal.c */
hailfinger428f6852010-07-27 22:41:39 +0000319struct superio {
320 uint16_t vendor;
321 uint16_t port;
322 uint16_t model;
323};
hailfinger94e090c2011-04-27 14:34:08 +0000324extern struct superio superios[];
325extern int superio_count;
hailfinger428f6852010-07-27 22:41:39 +0000326#define SUPERIO_VENDOR_NONE 0x0
327#define SUPERIO_VENDOR_ITE 0x1
hailfingere20dc562011-06-09 20:06:34 +0000328#endif
329#if NEED_PCI == 1
Mayur Panchalf4796862019-08-05 15:46:12 +1000330struct pci_filter;
uwe922946a2011-07-13 11:22:03 +0000331struct pci_dev *pci_dev_find_vendorclass(uint16_t vendor, uint16_t devclass);
hailfinger428f6852010-07-27 22:41:39 +0000332struct pci_dev *pci_dev_find(uint16_t vendor, uint16_t device);
333struct pci_dev *pci_card_find(uint16_t vendor, uint16_t device,
334 uint16_t card_vendor, uint16_t card_device);
335#endif
Patrick Georgi2a2d67f2017-03-09 10:15:39 +0100336int rget_io_perms(void);
hailfinger428f6852010-07-27 22:41:39 +0000337#if CONFIG_INTERNAL == 1
338extern int is_laptop;
hailfingere52e9f82011-05-05 07:12:40 +0000339extern int laptop_ok;
hailfinger428f6852010-07-27 22:41:39 +0000340extern int force_boardenable;
341extern int force_boardmismatch;
342void probe_superio(void);
hailfinger94e090c2011-04-27 14:34:08 +0000343int register_superio(struct superio s);
hailfinger76bb7e92011-11-09 23:40:00 +0000344extern enum chipbustype internal_buses_supported;
David Hendricksac1d25c2016-08-09 17:00:58 -0700345int internal_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000346#endif
347
348/* hwaccess.c */
349void mmio_writeb(uint8_t val, void *addr);
350void mmio_writew(uint16_t val, void *addr);
351void mmio_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000352uint8_t mmio_readb(const void *addr);
353uint16_t mmio_readw(const void *addr);
354uint32_t mmio_readl(const void *addr);
355void mmio_readn(const void *addr, uint8_t *buf, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000356void mmio_le_writeb(uint8_t val, void *addr);
357void mmio_le_writew(uint16_t val, void *addr);
358void mmio_le_writel(uint32_t val, void *addr);
Edward O'Callaghan46b1e492019-06-02 16:04:48 +1000359uint8_t mmio_le_readb(const void *addr);
360uint16_t mmio_le_readw(const void *addr);
361uint32_t mmio_le_readl(const void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000362#define pci_mmio_writeb mmio_le_writeb
363#define pci_mmio_writew mmio_le_writew
364#define pci_mmio_writel mmio_le_writel
365#define pci_mmio_readb mmio_le_readb
366#define pci_mmio_readw mmio_le_readw
367#define pci_mmio_readl mmio_le_readl
hailfinger1e2e3442011-05-03 21:49:41 +0000368void rmmio_writeb(uint8_t val, void *addr);
369void rmmio_writew(uint16_t val, void *addr);
370void rmmio_writel(uint32_t val, void *addr);
371void rmmio_le_writeb(uint8_t val, void *addr);
372void rmmio_le_writew(uint16_t val, void *addr);
373void rmmio_le_writel(uint32_t val, void *addr);
374#define pci_rmmio_writeb rmmio_le_writeb
375#define pci_rmmio_writew rmmio_le_writew
376#define pci_rmmio_writel rmmio_le_writel
377void rmmio_valb(void *addr);
378void rmmio_valw(void *addr);
379void rmmio_vall(void *addr);
hailfinger428f6852010-07-27 22:41:39 +0000380
hailfinger428f6852010-07-27 22:41:39 +0000381/* dummyflasher.c */
382#if CONFIG_DUMMY == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700383int dummy_init(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100384void *dummy_map(const char *descr, uintptr_t phys_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000385void dummy_unmap(void *virt_addr, size_t len);
hailfinger428f6852010-07-27 22:41:39 +0000386#endif
387
388/* nic3com.c */
389#if CONFIG_NIC3COM == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700390int nic3com_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100391extern const struct dev_entry nics_3com[];
hailfinger428f6852010-07-27 22:41:39 +0000392#endif
393
394/* gfxnvidia.c */
395#if CONFIG_GFXNVIDIA == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700396int gfxnvidia_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100397extern const struct dev_entry gfx_nvidia[];
hailfinger428f6852010-07-27 22:41:39 +0000398#endif
399
400/* drkaiser.c */
401#if CONFIG_DRKAISER == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700402int drkaiser_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100403extern const struct dev_entry drkaiser_pcidev[];
hailfinger428f6852010-07-27 22:41:39 +0000404#endif
405
406/* nicrealtek.c */
407#if CONFIG_NICREALTEK == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700408int nicrealtek_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100409extern const struct dev_entry nics_realtek[];
hailfinger428f6852010-07-27 22:41:39 +0000410#endif
411
412/* nicnatsemi.c */
413#if CONFIG_NICNATSEMI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700414int nicnatsemi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100415extern const struct dev_entry nics_natsemi[];
hailfinger428f6852010-07-27 22:41:39 +0000416#endif
417
hailfinger7949b652011-05-08 00:24:18 +0000418/* nicintel.c */
419#if CONFIG_NICINTEL == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700420int nicintel_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100421extern const struct dev_entry nics_intel[];
hailfinger7949b652011-05-08 00:24:18 +0000422#endif
423
uwe6764e922010-09-03 18:21:21 +0000424/* nicintel_spi.c */
425#if CONFIG_NICINTEL_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700426int nicintel_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100427extern const struct dev_entry nics_intel_spi[];
uwe6764e922010-09-03 18:21:21 +0000428#endif
429
hailfingerfb1f31f2010-12-03 14:48:11 +0000430/* ogp_spi.c */
431#if CONFIG_OGP_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700432int ogp_spi_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100433extern const struct dev_entry ogp_spi[];
hailfingerfb1f31f2010-12-03 14:48:11 +0000434#endif
435
hailfinger935365d2011-02-04 21:37:59 +0000436/* satamv.c */
437#if CONFIG_SATAMV == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700438int satamv_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100439extern const struct dev_entry satas_mv[];
hailfinger935365d2011-02-04 21:37:59 +0000440#endif
441
hailfinger428f6852010-07-27 22:41:39 +0000442/* satasii.c */
443#if CONFIG_SATASII == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700444int satasii_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100445extern const struct dev_entry satas_sii[];
hailfinger428f6852010-07-27 22:41:39 +0000446#endif
447
448/* atahpt.c */
449#if CONFIG_ATAHPT == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700450int atahpt_init(void);
Patrick Georgi8ae16572017-03-09 15:59:25 +0100451extern const struct dev_entry ata_hpt[];
hailfinger428f6852010-07-27 22:41:39 +0000452#endif
453
454/* ft2232_spi.c */
hailfinger888410e2010-07-29 15:54:53 +0000455#if CONFIG_FT2232_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700456int ft2232_spi_init(void);
Nikolai Artemievc347a852020-04-29 12:17:08 +1000457extern const struct dev_entry devs_ft2232spi[];
hailfinger888410e2010-07-29 15:54:53 +0000458#endif
hailfinger428f6852010-07-27 22:41:39 +0000459
460/* rayer_spi.c */
461#if CONFIG_RAYER_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700462int rayer_spi_init(void);
hailfinger428f6852010-07-27 22:41:39 +0000463#endif
464
465/* bitbang_spi.c */
Craig Hesling65eb8812019-08-01 09:33:56 -0700466int register_spi_bitbang_master(const struct bitbang_spi_master *master);
David Hendricksac1d25c2016-08-09 17:00:58 -0700467int bitbang_spi_shutdown(const struct bitbang_spi_master *master);
hailfinger428f6852010-07-27 22:41:39 +0000468
469/* buspirate_spi.c */
hailfingere20dc562011-06-09 20:06:34 +0000470#if CONFIG_BUSPIRATE_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700471int buspirate_spi_init(void);
hailfingere20dc562011-06-09 20:06:34 +0000472#endif
hailfinger428f6852010-07-27 22:41:39 +0000473
Anton Staafb2647882014-09-17 15:13:43 -0700474/* raiden_debug_spi.c */
475#if CONFIG_RAIDEN_DEBUG_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700476int raiden_debug_spi_init(void);
Brian J. Nemecb42d6c12020-07-23 03:07:38 -0700477extern const struct dev_entry devs_raiden[];
Anton Staafb2647882014-09-17 15:13:43 -0700478#endif
479
David Hendrickscebee892015-05-23 20:30:30 -0700480/* linux_mtd.c */
481#if CONFIG_LINUX_MTD == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700482int linux_mtd_init(void);
David Hendrickscebee892015-05-23 20:30:30 -0700483#endif
484
uwe7df6dda2011-09-03 18:37:52 +0000485/* linux_spi.c */
486#if CONFIG_LINUX_SPI == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700487int linux_spi_init(void);
uwe7df6dda2011-09-03 18:37:52 +0000488#endif
489
hailfinger428f6852010-07-27 22:41:39 +0000490/* dediprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000491#if CONFIG_DEDIPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700492int dediprog_init(void);
Edward O'Callaghanac1678b2020-07-27 15:55:45 +1000493extern const struct dev_entry devs_dediprog[];
hailfingere20dc562011-06-09 20:06:34 +0000494#endif
hailfinger428f6852010-07-27 22:41:39 +0000495
496/* flashrom.c */
497struct decode_sizes {
498 uint32_t parallel;
499 uint32_t lpc;
500 uint32_t fwh;
501 uint32_t spi;
502};
Edward O'Callaghan929b6382020-05-15 12:47:24 +1000503// FIXME: These need to be local, not global
hailfinger428f6852010-07-27 22:41:39 +0000504extern struct decode_sizes max_rom_decode;
505extern int programmer_may_write;
506extern unsigned long flashbase;
hailfinger428f6852010-07-27 22:41:39 +0000507int check_max_decode(enum chipbustype buses, uint32_t size);
stefanct52700282011-06-26 17:38:17 +0000508char *extract_programmer_param(const char *param_name);
hailfinger428f6852010-07-27 22:41:39 +0000509
hailfinger428f6852010-07-27 22:41:39 +0000510/* spi.c */
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100511extern const int spi_master_count;
mkarcher8fb57592011-05-11 17:07:02 +0000512
513#define MAX_DATA_UNSPECIFIED 0
514#define MAX_DATA_READ_UNLIMITED 64 * 1024
515#define MAX_DATA_WRITE_UNLIMITED 256
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000516
517#define SPI_MASTER_4BA (1U << 0) /**< Can handle 4-byte addresses */
Edward O'Callaghandaf990f2019-11-11 14:57:13 +1100518#define SPI_MASTER_NO_4BA_MODES (1U << 1) /**< Compatibility modes (i.e. extended address
519 register, 4BA mode switch) don't work */
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000520
Patrick Georgif4f1e2f2017-03-10 17:38:40 +0100521struct spi_master {
Edward O'Callaghana6673bd2019-06-24 15:22:28 +1000522 uint32_t features;
stefanctc5eb8a92011-11-23 09:13:48 +0000523 unsigned int max_data_read;
524 unsigned int max_data_write;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700525 int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000526 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700527 int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds);
hailfinger428f6852010-07-27 22:41:39 +0000528
Patrick Georgie39d6442017-03-22 21:23:35 +0100529 /* Optimized functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700530 int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100531 int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghan9cf8b7c2020-04-15 12:40:45 +1000532 int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
533 const void *data;
hailfinger428f6852010-07-27 22:41:39 +0000534};
535
Craig Hesling65eb8812019-08-01 09:33:56 -0700536extern const struct spi_master *spi_master;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700537int default_spi_send_command(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt,
hailfinger428f6852010-07-27 22:41:39 +0000538 const unsigned char *writearr, unsigned char *readarr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700539int default_spi_send_multicommand(const struct flashctx *flash, struct spi_command *cmds);
540int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100541int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Edward O'Callaghan20ba6152019-08-26 23:21:09 +1000542int register_spi_master(const struct spi_master *programmer);
hailfinger428f6852010-07-27 22:41:39 +0000543
Edward O'Callaghanea053772019-08-13 10:32:30 +1000544/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000545enum ich_chipset {
stefanctc035c192011-11-06 23:51:09 +0000546 CHIPSET_ICH_UNKNOWN,
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000547 CHIPSET_ICH,
548 CHIPSET_ICH2345,
Edward O'Callaghanea053772019-08-13 10:32:30 +1000549 CHIPSET_ICH6,
Edward O'Callaghan9ff09132019-09-04 13:48:46 +1000550 CHIPSET_POULSBO, /* SCH U* */
551 CHIPSET_TUNNEL_CREEK, /* Atom E6xx */
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000552 CHIPSET_CENTERTON, /* Atom S1220 S1240 S1260 */
Edward O'Callaghanea053772019-08-13 10:32:30 +1000553 CHIPSET_ICH7,
stefanctc035c192011-11-06 23:51:09 +0000554 CHIPSET_ICH8,
555 CHIPSET_ICH9,
556 CHIPSET_ICH10,
557 CHIPSET_5_SERIES_IBEX_PEAK,
558 CHIPSET_6_SERIES_COUGAR_POINT,
Duncan Laurie32e60552013-02-28 09:42:07 -0800559 CHIPSET_7_SERIES_PANTHER_POINT,
560 CHIPSET_8_SERIES_LYNX_POINT,
Edward O'Callaghan595c4382020-07-29 10:44:59 +1000561 CHIPSET_BAYTRAIL, /* Actually all with Silvermont architecture: Bay Trail, Avoton/Rangeley */
Duncan Laurie32e60552013-02-28 09:42:07 -0800562 CHIPSET_8_SERIES_LYNX_POINT_LP,
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000563 CHIPSET_8_SERIES_WELLSBURG,
Duncan Laurie9bd2af82014-05-12 10:17:38 -0700564 CHIPSET_9_SERIES_WILDCAT_POINT,
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000565 CHIPSET_9_SERIES_WILDCAT_POINT_LP,
566 CHIPSET_100_SERIES_SUNRISE_POINT, /* also 6th/7th gen Core i/o (LP) variants */
Edward O'Callaghanc8e0a112020-05-26 21:38:37 +1000567 CHIPSET_C620_SERIES_LEWISBURG,
568 CHIPSET_300_SERIES_CANNON_POINT,
Edward O'Callaghan595c4382020-07-29 10:44:59 +1000569 CHIPSET_APOLLO_LAKE,
stefanctc035c192011-11-06 23:51:09 +0000570};
571
Edward O'Callaghan595c4382020-07-29 10:44:59 +1000572
Edward O'Callaghanea053772019-08-13 10:32:30 +1000573/* ichspi.c */
Stefan Tauner34f6f5a2016-08-03 11:20:38 -0700574#if CONFIG_INTERNAL == 1
Vadim Bendebury622128c2018-06-21 15:50:28 -0700575
576/*
577 * This global variable is used to communicate the type of ICH found on the
578 * device. When running on non-intel platforms default value of
579 * CHIPSET_ICH_UNKNOWN is used.
580*/
Edward O'Callaghane3e30562019-09-03 13:10:58 +1000581extern enum ich_chipset g_ich_generation;
Vadim Bendebury066143d2018-07-16 18:20:33 -0700582
Edward O'Callaghanbb51dcc2020-05-27 12:22:55 +1000583int ich_init_spi(void *spibar, enum ich_chipset ich_generation);
Edward O'Callaghan3300e4e2019-10-03 13:20:09 +1000584int via_init_spi(uint32_t mmio_base);
hailfinger428f6852010-07-27 22:41:39 +0000585
Rong Changaaa1acf2012-06-21 19:21:18 +0800586/* ene_lpc.c */
Victor Ding7fd63dc2020-08-19 23:03:23 +1000587int ene_probe_spi_flash();
ivy_jian8e0c4e52017-08-23 09:17:56 +0800588/* amd_imc.c */
589int amd_imc_shutdown(struct pci_dev *dev);
Rong Changaaa1acf2012-06-21 19:21:18 +0800590
hailfinger2b46a862011-02-28 23:58:15 +0000591/* it85spi.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700592int it85xx_spi_init(struct superio s);
593int it8518_spi_init(struct superio s);
hailfinger2b46a862011-02-28 23:58:15 +0000594
hailfinger428f6852010-07-27 22:41:39 +0000595/* it87spi.c */
596void enter_conf_mode_ite(uint16_t port);
597void exit_conf_mode_ite(uint16_t port);
hailfinger94e090c2011-04-27 14:34:08 +0000598void probe_superio_ite(void);
David Hendricksac1d25c2016-08-09 17:00:58 -0700599int init_superio_ite(void);
hailfinger428f6852010-07-27 22:41:39 +0000600
hailfingere20dc562011-06-09 20:06:34 +0000601/* mcp6x_spi.c */
602int mcp6x_spi_init(int want_spi);
603
David Hendricks46d32e32011-01-19 16:01:52 -0800604/* mec1308.c */
Victor Dinga2c921c2020-08-18 18:55:20 +1000605int mec1308_probe_spi_flash();
David Hendricks46d32e32011-01-19 16:01:52 -0800606
hailfinger428f6852010-07-27 22:41:39 +0000607/* sb600spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000608int sb600_probe_spi(struct pci_dev *dev);
hailfinger428f6852010-07-27 22:41:39 +0000609
610/* wbsio_spi.c */
hailfinger428f6852010-07-27 22:41:39 +0000611int wbsio_check_for_spi(void);
hailfinger428f6852010-07-27 22:41:39 +0000612#endif
613
hailfingerfe7cd9e2011-11-04 21:35:26 +0000614/* opaque.c */
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000615struct opaque_master {
hailfingerfe7cd9e2011-11-04 21:35:26 +0000616 int max_data_read;
617 int max_data_write;
Edward O'Callaghan929b6382020-05-15 12:47:24 +1000618 /* Specific functions for this master */
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700619 int (*probe) (struct flashctx *flash);
620 int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len);
Patrick Georgiab8353e2017-02-03 18:32:01 +0100621 int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700622 int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen);
623 uint8_t (*read_status) (const struct flashctx *flash);
624 int (*write_status) (const struct flashctx *flash, int status);
Duncan Laurie25a4ca22019-04-25 12:08:52 -0700625 int (*check_access) (const struct flashctx *flash, unsigned int start, unsigned int len, int read);
David Hendricks5d481e12012-05-24 14:14:14 -0700626 const void *data;
hailfingerfe7cd9e2011-11-04 21:35:26 +0000627};
Craig Hesling65eb8812019-08-01 09:33:56 -0700628extern struct opaque_master *opaque_master;
629void register_opaque_master(struct opaque_master *pgm);
hailfingerfe7cd9e2011-11-04 21:35:26 +0000630
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700631/* programmer.c */
632int noop_shutdown(void);
Patrick Georgi4befc162017-02-03 18:32:01 +0100633void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700634void fallback_unmap(void *virt_addr, size_t len);
David Hendricksac1d25c2016-08-09 17:00:58 -0700635uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700636void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr);
637void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr);
638void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100639void fallback_chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700640uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr);
641uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr);
642void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100643struct par_master {
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700644 void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr);
645 void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr);
646 void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr);
Stuart langleyc98e43f2020-03-26 20:27:36 +1100647 void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700648 uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr);
649 uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr);
650 uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr);
651 void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000652 const void *data;
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700653};
Craig Hesling65eb8812019-08-01 09:33:56 -0700654extern const struct par_master *par_master;
655void register_par_master(const struct par_master *pgm, const enum chipbustype buses);
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000656struct registered_master {
657 enum chipbustype buses_supported;
658 union {
659 struct par_master par;
660 struct spi_master spi;
Edward O'Callaghanabd30192019-05-14 15:58:19 +1000661 struct opaque_master opaque;
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000662 };
663};
664extern struct registered_master registered_masters[];
665extern int registered_master_count;
666int register_master(const struct registered_master *mst);
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700667
hailfinger428f6852010-07-27 22:41:39 +0000668/* serprog.c */
hailfingere20dc562011-06-09 20:06:34 +0000669#if CONFIG_SERPROG == 1
David Hendricksac1d25c2016-08-09 17:00:58 -0700670int serprog_init(void);
Edward O'Callaghan8ebbd502019-09-03 15:11:02 +1000671void serprog_delay(unsigned int usecs);
hailfingere20dc562011-06-09 20:06:34 +0000672#endif
hailfinger428f6852010-07-27 22:41:39 +0000673
674/* serial.c */
Kangheui Won0c485a72019-09-10 14:27:04 +1000675#if IS_WINDOWS
hailfinger428f6852010-07-27 22:41:39 +0000676typedef HANDLE fdtype;
Kangheui Won0c485a72019-09-10 14:27:04 +1000677#define SER_INV_FD INVALID_HANDLE_VALUE
hailfinger428f6852010-07-27 22:41:39 +0000678#else
679typedef int fdtype;
Kangheui Won0c485a72019-09-10 14:27:04 +1000680#define SER_INV_FD -1
hailfinger428f6852010-07-27 22:41:39 +0000681#endif
682
David Hendricksc801adb2010-12-09 16:58:56 -0800683/* wpce775x.c */
David Hendricksac1d25c2016-08-09 17:00:58 -0700684int wpce775x_probe_spi_flash(const char *name);
David Hendricksc801adb2010-12-09 16:58:56 -0800685
Simon Glasscd597032013-05-23 17:18:44 -0700686/**
687 * Probe the Google Chrome OS EC device
688 *
689 * @return 0 if found correct, non-zero if not found or error
690 */
David Hendricksac1d25c2016-08-09 17:00:58 -0700691int cros_ec_probe_dev(void);
Simon Glasscd597032013-05-23 17:18:44 -0700692
David Hendricksac1d25c2016-08-09 17:00:58 -0700693int cros_ec_need_2nd_pass(void);
694int cros_ec_finish(void);
695int cros_ec_prepare(uint8_t *image, int size);
Louis Yung-Chieh Loedb0cba2011-12-09 17:06:54 +0800696
hailfinger428f6852010-07-27 22:41:39 +0000697void sp_flush_incoming(void);
Kangheui Won0c485a72019-09-10 14:27:04 +1000698fdtype sp_openserport(char *dev, int baud);
hailfinger428f6852010-07-27 22:41:39 +0000699extern fdtype sp_fd;
Kangheui Won0c485a72019-09-10 14:27:04 +1000700int serialport_config(fdtype fd, int baud);
dhendrix0ffc2eb2011-06-14 01:35:36 +0000701int serialport_shutdown(void *data);
Kangheui Won0c485a72019-09-10 14:27:04 +1000702int serialport_write(const unsigned char *buf, unsigned int writecnt);
703int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote);
hailfinger428f6852010-07-27 22:41:39 +0000704int serialport_read(unsigned char *buf, unsigned int readcnt);
Kangheui Won0c485a72019-09-10 14:27:04 +1000705int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read);
706
707/* Serial port/pin mapping:
708
709 1 CD <-
710 2 RXD <-
711 3 TXD ->
712 4 DTR ->
713 5 GND --
714 6 DSR <-
715 7 RTS ->
716 8 CTS <-
717 9 RI <-
718*/
719enum SP_PIN {
720 PIN_CD = 1,
721 PIN_RXD,
722 PIN_TXD,
723 PIN_DTR,
724 PIN_GND,
725 PIN_DSR,
726 PIN_RTS,
727 PIN_CTS,
728 PIN_RI,
729};
730
731void sp_set_pin(enum SP_PIN pin, int val);
732int sp_get_pin(enum SP_PIN pin);
733
Edward O'Callaghandaf990f2019-11-11 14:57:13 +1100734/* spi_master feature checks */
735static inline bool spi_master_4ba(const struct flashctx *const flash)
736{
737 return flash->mst->buses_supported & BUS_SPI &&
738 flash->mst->spi.features & SPI_MASTER_4BA;
739}
740static inline bool spi_master_no_4ba_modes(const struct flashctx *const flash)
741{
742 return flash->mst->buses_supported & BUS_SPI &&
743 flash->mst->spi.features & SPI_MASTER_NO_4BA_MODES;
744}
hailfinger428f6852010-07-27 22:41:39 +0000745
Edward O'Callaghana88395f2019-02-27 18:44:04 +1100746/* usbdev.c */
747struct libusb_device_handle;
748struct libusb_context;
749struct libusb_device_handle *usb_dev_get_by_vid_pid_serial(
750 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, const char *serialno);
751struct libusb_device_handle *usb_dev_get_by_vid_pid_number(
752 struct libusb_context *usb_ctx, uint16_t vid, uint16_t pid, unsigned int num);
753
Shiyu Sun9dde7162020-04-16 17:32:55 +1000754/* lspcon_i2c_spi.c */
755#if CONFIG_LSPCON_I2C_SPI == 1
756int lspcon_i2c_spi_init(void);
757#endif
758
Edward O'Callaghan97dd9262020-03-26 00:00:41 +1100759/* realtek_mst_i2c_spi.c */
760#if CONFIG_REALTEK_MST_I2C_SPI == 1
761int realtek_mst_i2c_spi_init(void);
762#endif
763
hailfinger428f6852010-07-27 22:41:39 +0000764#endif /* !__PROGRAMMER_H__ */