| 1 |
/* |
| 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 <[email protected]> |
| 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 |
|
| 20 |
#ifndef __PROGRAMMER_H__ |
| 21 |
#define __PROGRAMMER_H__ 1 |
| 22 |
|
| 23 |
#include <stdbool.h> |
| 24 |
#include <stdint.h> |
| 25 |
|
| 26 |
#include "spi.h" |
| 27 |
|
| 28 |
enum programmer_type { |
| 29 |
PCI = 1, /* to detect uninitialized values */ |
| 30 |
USB, |
| 31 |
OTHER, |
| 32 |
}; |
| 33 |
struct board_cfg; |
| 34 |
struct programmer_cfg { |
| 35 |
char *params; |
| 36 |
struct board_cfg *bcfg; |
| 37 |
}; |
| 38 |
|
| 39 |
struct dev_entry { |
| 40 |
uint16_t vendor_id; |
| 41 |
uint16_t device_id; |
| 42 |
const enum test_state status; |
| 43 |
const char *vendor_name; |
| 44 |
const char *device_name; |
| 45 |
}; |
| 46 |
|
| 47 |
struct programmer_entry { |
| 48 |
const char *name; |
| 49 |
const enum programmer_type type; |
| 50 |
union { |
| 51 |
const struct dev_entry *const dev; |
| 52 |
const char *const note; |
| 53 |
} devs; |
| 54 |
|
| 55 |
int (*init) (const struct programmer_cfg *cfg); |
| 56 |
}; |
| 57 |
|
| 58 |
extern const struct programmer_entry *const programmer_table[]; |
| 59 |
extern const size_t programmer_table_size; |
| 60 |
|
| 61 |
/* programmer drivers */ |
| 62 |
extern const struct programmer_entry programmer_asm106x; |
| 63 |
extern const struct programmer_entry programmer_atahpt; |
| 64 |
extern const struct programmer_entry programmer_atapromise; |
| 65 |
extern const struct programmer_entry programmer_atavia; |
| 66 |
extern const struct programmer_entry programmer_buspirate_spi; |
| 67 |
extern const struct programmer_entry programmer_ch341a_spi; |
| 68 |
extern const struct programmer_entry programmer_ch347_spi; |
| 69 |
extern const struct programmer_entry programmer_dediprog; |
| 70 |
extern const struct programmer_entry programmer_developerbox; |
| 71 |
extern const struct programmer_entry programmer_digilent_spi; |
| 72 |
extern const struct programmer_entry programmer_drkaiser; |
| 73 |
extern const struct programmer_entry programmer_dummy; |
| 74 |
extern const struct programmer_entry programmer_ft2232_spi; |
| 75 |
extern const struct programmer_entry programmer_gfxnvidia; |
| 76 |
extern const struct programmer_entry programmer_internal; |
| 77 |
extern const struct programmer_entry programmer_it8212; |
| 78 |
extern const struct programmer_entry programmer_jlink_spi; |
| 79 |
extern const struct programmer_entry programmer_linux_mtd; |
| 80 |
extern const struct programmer_entry programmer_linux_spi; |
| 81 |
extern const struct programmer_entry programmer_parade_lspcon; |
| 82 |
extern const struct programmer_entry programmer_mediatek_i2c_spi; |
| 83 |
extern const struct programmer_entry programmer_mstarddc_spi; |
| 84 |
extern const struct programmer_entry programmer_ni845x_spi; |
| 85 |
extern const struct programmer_entry programmer_nic3com; |
| 86 |
extern const struct programmer_entry programmer_nicintel; |
| 87 |
extern const struct programmer_entry programmer_nicintel_eeprom; |
| 88 |
extern const struct programmer_entry programmer_nicintel_spi; |
| 89 |
extern const struct programmer_entry programmer_nicnatsemi; |
| 90 |
extern const struct programmer_entry programmer_nicrealtek; |
| 91 |
extern const struct programmer_entry programmer_ogp_spi; |
| 92 |
extern const struct programmer_entry programmer_pickit2_spi; |
| 93 |
extern const struct programmer_entry programmer_pony_spi; |
| 94 |
extern const struct programmer_entry programmer_raiden_debug_spi; |
| 95 |
extern const struct programmer_entry programmer_rayer_spi; |
| 96 |
extern const struct programmer_entry programmer_realtek_mst_i2c_spi; |
| 97 |
extern const struct programmer_entry programmer_satamv; |
| 98 |
extern const struct programmer_entry programmer_satasii; |
| 99 |
extern const struct programmer_entry programmer_serprog; |
| 100 |
extern const struct programmer_entry programmer_spidriver; |
| 101 |
extern const struct programmer_entry programmer_stlinkv3_spi; |
| 102 |
extern const struct programmer_entry programmer_usbblaster_spi; |
| 103 |
extern const struct programmer_entry programmer_dirtyjtag_spi; |
| 104 |
|
| 105 |
int programmer_init(const struct programmer_entry *prog, const char *param); |
| 106 |
int programmer_shutdown(void); |
| 107 |
|
| 108 |
struct bitbang_spi_master { |
| 109 |
/* Note that CS# is active low, so val=0 means the chip is active. */ |
| 110 |
void (*set_cs) (int val, void *spi_data); |
| 111 |
void (*set_sck) (int val, void *spi_data); |
| 112 |
void (*set_mosi) (int val, void *spi_data); |
| 113 |
int (*get_miso) (void *spi_data); |
| 114 |
void (*request_bus) (void *spi_data); |
| 115 |
void (*release_bus) (void *spi_data); |
| 116 |
/* optional functions to optimize xfers */ |
| 117 |
void (*set_sck_set_mosi) (int sck, int mosi, void *spi_data); |
| 118 |
int (*set_sck_get_miso) (int sck, void *spi_data); |
| 119 |
/* Length of half a clock period in usecs. */ |
| 120 |
unsigned int half_period; |
| 121 |
}; |
| 122 |
|
| 123 |
struct pci_dev; |
| 124 |
struct pci_filter; |
| 125 |
|
| 126 |
/* pcidev.c */ |
| 127 |
// FIXME: This needs to be local, not global(?) |
| 128 |
extern struct pci_access *pacc; |
| 129 |
int pci_init_common(void); |
| 130 |
uintptr_t pcidev_readbar(struct pci_dev *dev, int bar); |
| 131 |
struct pci_dev *pcidev_init(const struct programmer_cfg *cfg, const struct dev_entry *devs, int bar); |
| 132 |
struct pci_dev *pcidev_scandev(struct pci_filter *filter, struct pci_dev *start); |
| 133 |
struct pci_dev *pcidev_getdevfn(struct pci_dev *dev, const int func); |
| 134 |
struct pci_dev *pcidev_find_vendorclass(uint16_t vendor, uint16_t devclass); |
| 135 |
struct pci_dev *pcidev_card_find(uint16_t vendor, uint16_t device, uint16_t card_vendor, uint16_t card_device); |
| 136 |
struct pci_dev *pcidev_find(uint16_t vendor, uint16_t device); |
| 137 |
/* rpci_write_* are reversible writes. The original PCI config space register |
| 138 |
* contents will be restored on shutdown. |
| 139 |
* To clone the pci_dev instances internally, the `pacc` global |
| 140 |
* variable has to reference a pci_access method that is compatible |
| 141 |
* with the given pci_dev handle. The referenced pci_access (not |
| 142 |
* the variable) has to stay valid until the shutdown handlers are |
| 143 |
* finished. |
| 144 |
*/ |
| 145 |
int rpci_write_byte(struct pci_dev *dev, int reg, uint8_t data); |
| 146 |
int rpci_write_word(struct pci_dev *dev, int reg, uint16_t data); |
| 147 |
int rpci_write_long(struct pci_dev *dev, int reg, uint32_t data); |
| 148 |
|
| 149 |
#if CONFIG_INTERNAL == 1 |
| 150 |
struct penable { |
| 151 |
uint16_t vendor_id; |
| 152 |
uint16_t device_id; |
| 153 |
enum chipbustype buses; |
| 154 |
const enum test_state status; |
| 155 |
const char *vendor_name; |
| 156 |
const char *device_name; |
| 157 |
int (*doit) (const struct programmer_cfg *cfg, struct pci_dev *dev, const char *name); |
| 158 |
}; |
| 159 |
|
| 160 |
extern const struct penable chipset_enables[]; |
| 161 |
|
| 162 |
enum board_match_phase { |
| 163 |
P1, |
| 164 |
P2, |
| 165 |
P3 |
| 166 |
}; |
| 167 |
|
| 168 |
struct board_cfg { |
| 169 |
int is_laptop; |
| 170 |
bool laptop_ok; |
| 171 |
}; |
| 172 |
|
| 173 |
struct board_match { |
| 174 |
/* Any device, but make it sensible, like the ISA bridge. */ |
| 175 |
uint16_t first_vendor; |
| 176 |
uint16_t first_device; |
| 177 |
uint16_t first_card_vendor; |
| 178 |
uint16_t first_card_device; |
| 179 |
|
| 180 |
/* Any device, but make it sensible, like |
| 181 |
* the host bridge. May be NULL. |
| 182 |
*/ |
| 183 |
uint16_t second_vendor; |
| 184 |
uint16_t second_device; |
| 185 |
uint16_t second_card_vendor; |
| 186 |
uint16_t second_card_device; |
| 187 |
|
| 188 |
/* Pattern to match DMI entries. May be NULL. */ |
| 189 |
const char *dmi_pattern; |
| 190 |
|
| 191 |
/* The vendor / part name from the coreboot table. May be NULL. */ |
| 192 |
const char *lb_vendor; |
| 193 |
const char *lb_part; |
| 194 |
|
| 195 |
enum board_match_phase phase; |
| 196 |
|
| 197 |
const char *vendor_name; |
| 198 |
const char *board_name; |
| 199 |
|
| 200 |
int max_rom_decode_parallel; |
| 201 |
const enum test_state status; |
| 202 |
int (*enable) (struct board_cfg *cfg); /* May be NULL. */ |
| 203 |
}; |
| 204 |
|
| 205 |
extern const struct board_match board_matches[]; |
| 206 |
extern const size_t board_matches_size; |
| 207 |
|
| 208 |
struct board_info { |
| 209 |
const char *vendor; |
| 210 |
const char *name; |
| 211 |
const enum test_state working; |
| 212 |
const char *url; |
| 213 |
const char *note; |
| 214 |
}; |
| 215 |
|
| 216 |
extern const struct board_info boards_known[]; |
| 217 |
extern const struct board_info laptops_known[]; |
| 218 |
#endif |
| 219 |
|
| 220 |
#if CONFIG_INTERNAL == 1 |
| 221 |
/* board_enable.c */ |
| 222 |
int selfcheck_board_enables(void); |
| 223 |
int board_parse_parameter(const char *boardstring, char **vendor, char **model); |
| 224 |
void w836xx_ext_enter(uint16_t port); |
| 225 |
void w836xx_ext_leave(uint16_t port); |
| 226 |
void probe_superio_winbond(void); |
| 227 |
int it8705f_write_enable(uint8_t port); |
| 228 |
uint8_t sio_read(uint16_t port, uint8_t reg); |
| 229 |
void sio_write(uint16_t port, uint8_t reg, uint8_t data); |
| 230 |
void sio_mask(uint16_t port, uint8_t reg, uint8_t data, uint8_t mask); |
| 231 |
void board_handle_before_superio(struct board_cfg *cfg, bool force_boardenable); |
| 232 |
void board_handle_before_laptop(struct board_cfg *cfg, bool force_boardenable); |
| 233 |
int board_flash_enable(struct board_cfg *cfg, const char *vendor, const char *model, const char *cb_vendor, const char *cb_model, bool force_boardenable); |
| 234 |
|
| 235 |
/* chipset_enable.c */ |
| 236 |
int chipset_flash_enable(const struct programmer_cfg *cfg); |
| 237 |
|
| 238 |
/* processor_enable.c */ |
| 239 |
int processor_flash_enable(void); |
| 240 |
#endif |
| 241 |
|
| 242 |
#if CONFIG_INTERNAL == 1 |
| 243 |
/* cbtable.c */ |
| 244 |
int cb_parse_table(const char **vendor, const char **model); |
| 245 |
int cb_check_image(const uint8_t *bios, unsigned int size); |
| 246 |
|
| 247 |
/* dmi.c */ |
| 248 |
#if defined(__i386__) || defined(__x86_64__) |
| 249 |
void dmi_init(int *is_laptop); |
| 250 |
bool dmi_is_supported(void); |
| 251 |
int dmi_match(const char *pattern); |
| 252 |
#endif // defined(__i386__) || defined(__x86_64__) |
| 253 |
|
| 254 |
/* internal.c */ |
| 255 |
struct superio { |
| 256 |
uint16_t vendor; |
| 257 |
uint16_t port; |
| 258 |
uint16_t model; |
| 259 |
}; |
| 260 |
extern struct superio superios[]; |
| 261 |
extern int superio_count; |
| 262 |
#define SUPERIO_VENDOR_NONE 0x0 |
| 263 |
#define SUPERIO_VENDOR_ITE 0x1 |
| 264 |
#define SUPERIO_VENDOR_WINBOND 0x2 |
| 265 |
#endif |
| 266 |
|
| 267 |
#if CONFIG_INTERNAL == 1 |
| 268 |
extern bool force_boardmismatch; |
| 269 |
void probe_superio(void); |
| 270 |
int register_superio(struct superio s); |
| 271 |
extern enum chipbustype internal_buses_supported; |
| 272 |
#endif |
| 273 |
|
| 274 |
/* bitbang_spi.c */ |
| 275 |
int register_spi_bitbang_master(const struct bitbang_spi_master *master, void *spi_data); |
| 276 |
|
| 277 |
|
| 278 |
/* flashrom.c */ |
| 279 |
struct decode_sizes { |
| 280 |
uint32_t parallel; |
| 281 |
uint32_t lpc; |
| 282 |
uint32_t fwh; |
| 283 |
uint32_t spi; |
| 284 |
}; |
| 285 |
// FIXME: These need to be local, not global |
| 286 |
extern struct decode_sizes max_rom_decode; |
| 287 |
extern bool programmer_may_write; |
| 288 |
extern uintptr_t flashbase; /* used in programmer_enable.c */ |
| 289 |
char *extract_programmer_param_str(const struct programmer_cfg *cfg, const char *param_name); |
| 290 |
|
| 291 |
/* spi.c */ |
| 292 |
#define MAX_DATA_UNSPECIFIED 0 |
| 293 |
#define MAX_DATA_READ_UNLIMITED 64 * 1024 |
| 294 |
#define MAX_DATA_WRITE_UNLIMITED 256 |
| 295 |
|
| 296 |
#define SPI_MASTER_4BA (1U << 0) /**< Can handle 4-byte addresses */ |
| 297 |
#define SPI_MASTER_NO_4BA_MODES (1U << 1) /**< Compatibility modes (i.e. extended address |
| 298 |
register, 4BA mode switch) don't work */ |
| 299 |
|
| 300 |
struct spi_master { |
| 301 |
uint32_t features; |
| 302 |
unsigned int max_data_read; // (Ideally,) maximum data read size in one go (excluding opcode+address). |
| 303 |
unsigned int max_data_write; // (Ideally,) maximum data write size in one go (excluding opcode+address). |
| 304 |
int (*command)(const struct flashctx *flash, unsigned int writecnt, unsigned int readcnt, |
| 305 |
const unsigned char *writearr, unsigned char *readarr); |
| 306 |
int (*multicommand)(const struct flashctx *flash, struct spi_command *cmds); |
| 307 |
|
| 308 |
/* Optimized functions for this master */ |
| 309 |
void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len); |
| 310 |
void (*unmap_flash_region) (void *virt_addr, size_t len); |
| 311 |
int (*read)(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); |
| 312 |
int (*write_256)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); |
| 313 |
int (*write_aai)(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); |
| 314 |
int (*shutdown)(void *data); |
| 315 |
bool (*probe_opcode)(const struct flashctx *flash, uint8_t opcode); /* NULL func implies true. */ |
| 316 |
void (*delay) (const struct flashctx *flash, unsigned int usecs); |
| 317 |
void (*get_region)(const struct flashctx *flash, unsigned int addr, struct flash_region *region); |
| 318 |
void *data; |
| 319 |
}; |
| 320 |
|
| 321 |
int default_spi_read(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); |
| 322 |
int default_spi_write_256(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); |
| 323 |
int default_spi_write_aai(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); |
| 324 |
int register_spi_master(const struct spi_master *mst, void *data); |
| 325 |
|
| 326 |
/* The following enum is needed by ich_descriptor_tool and ich* code as well as in chipset_enable.c. */ |
| 327 |
enum ich_chipset { |
| 328 |
CHIPSET_ICH_UNKNOWN, |
| 329 |
CHIPSET_ICH, |
| 330 |
CHIPSET_ICH2345, |
| 331 |
CHIPSET_ICH6, |
| 332 |
CHIPSET_POULSBO, /* SCH U* */ |
| 333 |
CHIPSET_TUNNEL_CREEK, /* Atom E6xx */ |
| 334 |
CHIPSET_CENTERTON, /* Atom S1220 S1240 S1260 */ |
| 335 |
CHIPSET_ICH7, |
| 336 |
CHIPSET_ICH8, |
| 337 |
CHIPSET_ICH9, |
| 338 |
CHIPSET_ICH10, |
| 339 |
CHIPSET_5_SERIES_IBEX_PEAK, |
| 340 |
CHIPSET_6_SERIES_COUGAR_POINT, |
| 341 |
CHIPSET_7_SERIES_PANTHER_POINT, |
| 342 |
CHIPSET_8_SERIES_LYNX_POINT, |
| 343 |
CHIPSET_BAYTRAIL, /* Actually all with Silvermont architecture: Bay Trail, Avoton/Rangeley */ |
| 344 |
CHIPSET_8_SERIES_LYNX_POINT_LP, |
| 345 |
CHIPSET_8_SERIES_WELLSBURG, |
| 346 |
CHIPSET_9_SERIES_WILDCAT_POINT, |
| 347 |
CHIPSET_9_SERIES_WILDCAT_POINT_LP, |
| 348 |
CHIPSET_100_SERIES_SUNRISE_POINT, /* also 6th/7th gen Core i/o (LP) variants */ |
| 349 |
CHIPSET_C620_SERIES_LEWISBURG, |
| 350 |
CHIPSET_C740_SERIES_EMMITSBURG, |
| 351 |
CHIPSET_300_SERIES_CANNON_POINT, |
| 352 |
CHIPSET_400_SERIES_COMET_POINT, |
| 353 |
CHIPSET_500_SERIES_TIGER_POINT, |
| 354 |
CHIPSET_600_SERIES_ALDER_POINT, |
| 355 |
CHIPSET_700_SERIES_RAPTOR_POINT, |
| 356 |
CHIPSET_APOLLO_LAKE, |
| 357 |
CHIPSET_GEMINI_LAKE, |
| 358 |
CHIPSET_JASPER_LAKE, |
| 359 |
CHIPSET_ELKHART_LAKE, |
| 360 |
/* All chipsets after METEOR_LAKE should support checking BIOS_BM to get read/write access to of FREG0~15 */ |
| 361 |
CHIPSET_METEOR_LAKE, |
| 362 |
CHIPSET_PANTHER_LAKE, |
| 363 |
}; |
| 364 |
|
| 365 |
/* ichspi.c */ |
| 366 |
#if CONFIG_INTERNAL == 1 |
| 367 |
int ich_init_spi(const struct programmer_cfg *cfg, void *spibar, enum ich_chipset ich_generation); |
| 368 |
int via_init_spi(uint32_t mmio_base); |
| 369 |
|
| 370 |
/* amd_imc.c */ |
| 371 |
int amd_imc_shutdown(struct pci_dev *dev); |
| 372 |
|
| 373 |
/* it87spi.c */ |
| 374 |
void enter_conf_mode_ite(uint16_t port); |
| 375 |
void exit_conf_mode_ite(uint16_t port); |
| 376 |
void probe_superio_ite(void); |
| 377 |
int init_superio_ite(const struct programmer_cfg *cfg); |
| 378 |
|
| 379 |
/* trivial wrapper to avoid cluttering internal_init() with #if */ |
| 380 |
static inline int try_mtd(const struct programmer_cfg *cfg) |
| 381 |
{ |
| 382 |
#if CONFIG_LINUX_MTD == 1 |
| 383 |
return programmer_linux_mtd.init(cfg); |
| 384 |
#else |
| 385 |
return 1; |
| 386 |
#endif |
| 387 |
} |
| 388 |
|
| 389 |
/* mcp6x_spi.c */ |
| 390 |
int mcp6x_spi_init(int want_spi); |
| 391 |
|
| 392 |
/* internal_par.c */ |
| 393 |
void internal_par_init(enum chipbustype buses); |
| 394 |
|
| 395 |
/* sb600spi.c */ |
| 396 |
int sb600_probe_spi(const struct programmer_cfg *cfg, struct pci_dev *dev); |
| 397 |
|
| 398 |
/* wbsio_spi.c */ |
| 399 |
int wbsio_check_for_spi(struct board_cfg *); |
| 400 |
#endif |
| 401 |
|
| 402 |
/* opaque.c */ |
| 403 |
struct opaque_master { |
| 404 |
int max_data_read; |
| 405 |
int max_data_write; |
| 406 |
/* Specific functions for this master */ |
| 407 |
int (*probe) (struct flashctx *flash); |
| 408 |
int (*read) (struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len); |
| 409 |
int (*write) (struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len); |
| 410 |
int (*erase) (struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen); |
| 411 |
/* |
| 412 |
* Callbacks for accessing flash registers. An opaque programmer must |
| 413 |
* provide these functions for writeprotect operations to be available, |
| 414 |
* unless it provides custom wp operations instead. |
| 415 |
*/ |
| 416 |
int (*read_register)(const struct flashctx *flash, enum flash_reg reg, uint8_t *value); |
| 417 |
int (*write_register)(const struct flashctx *flash, enum flash_reg reg, uint8_t value); |
| 418 |
/* Callbacks for overiding default writeprotect operations with custom ones. */ |
| 419 |
enum flashrom_wp_result (*wp_write_cfg)(struct flashctx *, const struct flashrom_wp_cfg *); |
| 420 |
enum flashrom_wp_result (*wp_read_cfg)(struct flashrom_wp_cfg *, struct flashctx *); |
| 421 |
enum flashrom_wp_result (*wp_get_ranges)(struct flashrom_wp_ranges **, struct flashctx *); |
| 422 |
void (*get_region)(const struct flashctx *flash, unsigned int addr, struct flash_region *region); |
| 423 |
int (*shutdown)(void *data); |
| 424 |
void (*delay) (const struct flashctx *flash, unsigned int usecs); |
| 425 |
void *data; |
| 426 |
}; |
| 427 |
int register_opaque_master(const struct opaque_master *mst, void *data); |
| 428 |
|
| 429 |
/* parallel.c */ |
| 430 |
struct par_master { |
| 431 |
void *(*map_flash_region) (const char *descr, uintptr_t phys_addr, size_t len); |
| 432 |
void (*unmap_flash_region) (void *virt_addr, size_t len); |
| 433 |
void (*chip_writeb) (const struct flashctx *flash, uint8_t val, chipaddr addr); |
| 434 |
void (*chip_writew) (const struct flashctx *flash, uint16_t val, chipaddr addr); |
| 435 |
void (*chip_writel) (const struct flashctx *flash, uint32_t val, chipaddr addr); |
| 436 |
void (*chip_writen) (const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len); |
| 437 |
uint8_t (*chip_readb) (const struct flashctx *flash, const chipaddr addr); |
| 438 |
uint16_t (*chip_readw) (const struct flashctx *flash, const chipaddr addr); |
| 439 |
uint32_t (*chip_readl) (const struct flashctx *flash, const chipaddr addr); |
| 440 |
void (*chip_readn) (const struct flashctx *flash, uint8_t *buf, const chipaddr addr, size_t len); |
| 441 |
int (*shutdown)(void *data); |
| 442 |
void (*delay) (const struct flashctx *flash, unsigned int usecs); |
| 443 |
void *data; |
| 444 |
}; |
| 445 |
int register_par_master(const struct par_master *mst, const enum chipbustype buses, void *data); |
| 446 |
|
| 447 |
/* programmer.c */ |
| 448 |
struct registered_master { |
| 449 |
enum chipbustype buses_supported; |
| 450 |
struct { |
| 451 |
struct par_master par; |
| 452 |
struct spi_master spi; |
| 453 |
struct opaque_master opaque; |
| 454 |
}; |
| 455 |
}; |
| 456 |
extern struct registered_master registered_masters[]; |
| 457 |
extern int registered_master_count; |
| 458 |
int register_master(const struct registered_master *mst); |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
/* serial.c */ |
| 463 |
#if IS_WINDOWS |
| 464 |
typedef HANDLE fdtype; |
| 465 |
#define SER_INV_FD INVALID_HANDLE_VALUE |
| 466 |
#else |
| 467 |
typedef int fdtype; |
| 468 |
#define SER_INV_FD -1 |
| 469 |
#endif |
| 470 |
|
| 471 |
void sp_flush_incoming(void); |
| 472 |
fdtype sp_openserport(char *dev, int baud); |
| 473 |
extern fdtype sp_fd; |
| 474 |
int serialport_config(fdtype fd, int baud); |
| 475 |
int serialport_shutdown(void *data); |
| 476 |
int serialport_write(const unsigned char *buf, unsigned int writecnt); |
| 477 |
int serialport_write_nonblock(const unsigned char *buf, unsigned int writecnt, unsigned int timeout, unsigned int *really_wrote); |
| 478 |
int serialport_read(unsigned char *buf, unsigned int readcnt); |
| 479 |
int serialport_read_nonblock(unsigned char *c, unsigned int readcnt, unsigned int timeout, unsigned int *really_read); |
| 480 |
|
| 481 |
/* Serial port/pin mapping: |
| 482 |
|
| 483 |
1 CD <- |
| 484 |
2 RXD <- |
| 485 |
3 TXD -> |
| 486 |
4 DTR -> |
| 487 |
5 GND -- |
| 488 |
6 DSR <- |
| 489 |
7 RTS -> |
| 490 |
8 CTS <- |
| 491 |
9 RI <- |
| 492 |
*/ |
| 493 |
enum SP_PIN { |
| 494 |
PIN_CD = 1, |
| 495 |
PIN_RXD, |
| 496 |
PIN_TXD, |
| 497 |
PIN_DTR, |
| 498 |
PIN_GND, |
| 499 |
PIN_DSR, |
| 500 |
PIN_RTS, |
| 501 |
PIN_CTS, |
| 502 |
PIN_RI, |
| 503 |
}; |
| 504 |
|
| 505 |
void sp_set_pin(enum SP_PIN pin, int val); |
| 506 |
int sp_get_pin(enum SP_PIN pin); |
| 507 |
|
| 508 |
/* spi_master feature checks */ |
| 509 |
static inline bool spi_master_4ba(const struct flashctx *const flash) |
| 510 |
{ |
| 511 |
return flash->mst->buses_supported & BUS_SPI && |
| 512 |
flash->mst->spi.features & SPI_MASTER_4BA; |
| 513 |
} |
| 514 |
static inline bool spi_master_no_4ba_modes(const struct flashctx *const flash) |
| 515 |
{ |
| 516 |
return flash->mst->buses_supported & BUS_SPI && |
| 517 |
flash->mst->spi.features & SPI_MASTER_NO_4BA_MODES; |
| 518 |
} |
| 519 |
/* spi_chip feature checks */ |
| 520 |
static inline bool spi_chip_4ba(const struct flashctx *const flash) |
| 521 |
{ |
| 522 |
return flash->chip->bustype == BUS_SPI && |
| 523 |
(flash->chip->feature_bits & (FEATURE_4BA_ENTER | FEATURE_4BA_ENTER_WREN | FEATURE_4BA_ENTER_EAR7)); |
| 524 |
} |
| 525 |
|
| 526 |
enum chipbustype get_buses_supported(void); |
| 527 |
|
| 528 |
#endif /* !__PROGRAMMER_H__ */ |