blob: 9749d86a83a29937987966cf8e441b0b7174425a [file] [log] [blame]
hailfingerec022272010-01-06 10:21:00 +00001/*
2 * This file is part of the flashrom project.
3 *
Souvik Ghoshd75cd672016-06-17 14:21:39 -07004 * Copyright (C) 2009,2010,2011 Carl-Daniel Hailfinger
hailfingerec022272010-01-06 10:21:00 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
hailfingerec022272010-01-06 10:21:00 +000016 */
17
hailfingerec022272010-01-06 10:21:00 +000018#include "flash.h"
hailfinger76bb7e92011-11-09 23:40:00 +000019#include "programmer.h"
20
Vadim Bendebury066143d2018-07-16 18:20:33 -070021/*
22 * The following two variables are used in the code even if the ich support is
23 * not compiled in, this is why they are exported through programmer.h and
24 * defined here.
25 */
26enum ich_chipset ich_generation = CHIPSET_ICH_UNKNOWN;
27int ich_dry_run;
28
hailfingerec022272010-01-06 10:21:00 +000029/* No-op shutdown() for programmers which don't need special handling */
30int noop_shutdown(void)
31{
32 return 0;
33}
34
35/* Fallback map() for programmers which don't need special handling */
Patrick Georgi4befc162017-02-03 18:32:01 +010036void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len)
hailfingerec022272010-01-06 10:21:00 +000037{
38 /* FIXME: Should return phys_addr. */
stepand0d220f2011-01-24 19:15:51 +000039 return NULL;
hailfingerec022272010-01-06 10:21:00 +000040}
41
42/* No-op/fallback unmap() for programmers which don't need special handling */
43void fallback_unmap(void *virt_addr, size_t len)
44{
45}
46
Edward O'Callaghanbcae3752018-12-19 13:11:57 +110047/* No-op chip_writeb() for parallel style drivers not supporting writes */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070048void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000049{
50}
51
52/* Little-endian fallback for drivers not supporting 16 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070053void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000054{
Souvik Ghoshd75cd672016-06-17 14:21:39 -070055 chip_writeb(flash, val & 0xff, addr);
56 chip_writeb(flash, (val >> 8) & 0xff, addr + 1);
hailfingerec022272010-01-06 10:21:00 +000057}
58
59/* Little-endian fallback for drivers not supporting 16 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070060uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000061{
62 uint16_t val;
Souvik Ghoshd75cd672016-06-17 14:21:39 -070063 val = chip_readb(flash, addr);
64 val |= chip_readb(flash, addr + 1) << 8;
hailfingerec022272010-01-06 10:21:00 +000065 return val;
66}
67
68/* Little-endian fallback for drivers not supporting 32 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070069void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000070{
Souvik Ghoshd75cd672016-06-17 14:21:39 -070071 chip_writew(flash, val & 0xffff, addr);
72 chip_writew(flash, (val >> 16) & 0xffff, addr + 2);
hailfingerec022272010-01-06 10:21:00 +000073}
74
75/* Little-endian fallback for drivers not supporting 32 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070076uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000077{
78 uint32_t val;
Souvik Ghoshd75cd672016-06-17 14:21:39 -070079 val = chip_readw(flash, addr);
80 val |= chip_readw(flash, addr + 2) << 16;
hailfingerec022272010-01-06 10:21:00 +000081 return val;
82}
83
Souvik Ghoshd75cd672016-06-17 14:21:39 -070084void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
hailfingerec022272010-01-06 10:21:00 +000085{
86 size_t i;
87 for (i = 0; i < len; i++)
Souvik Ghoshd75cd672016-06-17 14:21:39 -070088 chip_writeb(flash, buf[i], addr + i);
hailfingerec022272010-01-06 10:21:00 +000089 return;
90}
91
Souvik Ghoshd75cd672016-06-17 14:21:39 -070092void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
hailfingerec022272010-01-06 10:21:00 +000093{
94 size_t i;
95 for (i = 0; i < len; i++)
Souvik Ghoshd75cd672016-06-17 14:21:39 -070096 buf[i] = chip_readb(flash, addr + i);
hailfingerec022272010-01-06 10:21:00 +000097 return;
98}
hailfinger76bb7e92011-11-09 23:40:00 +000099
Edward O'Callaghanbcae3752018-12-19 13:11:57 +1100100int register_par_master(const struct par_master *pgm, const enum chipbustype buses)
hailfinger76bb7e92011-11-09 23:40:00 +0000101{
Edward O'Callaghanbcae3752018-12-19 13:11:57 +1100102 struct registered_master rmst;
103
104 if (!pgm->chip_writeb || !pgm->chip_writew || !pgm->chip_writel ||
105 !pgm->chip_writen || !pgm->chip_readb || !pgm->chip_readw ||
106 !pgm->chip_readl || !pgm->chip_readn) {
107 msg_perr("%s called with incomplete master definition. "
108 "Please report a bug at flashrom@flashrom.org\n",
109 __func__);
110 return ERROR_FLASHROM_BUG;
111 }
112
113 rmst.buses_supported = buses;
114 rmst.par = *pgm;
115 return register_master(&rmst);
hailfinger76bb7e92011-11-09 23:40:00 +0000116}
David Hendricksba0827a2013-05-03 20:25:40 -0700117
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000118/* The limit of 4 is totally arbitrary. */
119#define MASTERS_MAX 4
120struct registered_master registered_masters[MASTERS_MAX];
121int registered_master_count = 0;
122
123/* This function copies the struct registered_master parameter. */
124int register_master(const struct registered_master *mst)
125{
126 if (registered_master_count >= MASTERS_MAX) {
127 msg_perr("Tried to register more than %i master "
128 "interfaces.\n", MASTERS_MAX);
129 return ERROR_FLASHROM_LIMIT;
130 }
131 registered_masters[registered_master_count] = *mst;
132 registered_master_count++;
133
134 return 0;
135}
136
David Hendricksba0827a2013-05-03 20:25:40 -0700137struct programmer_alias aliases[] = {
David Hendricksac1d25c2016-08-09 17:00:58 -0700138 { "ec", ALIAS_EC },
139 { "host", ALIAS_HOST },
David Hendricksba0827a2013-05-03 20:25:40 -0700140 { NULL },
141};
142struct programmer_alias *alias;