blob: 1af52b0981262ffd3616087a42b6057f56971e4d [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
Patrick Georgi0a9533a2017-02-03 19:28:38 +010029static const struct par_master par_master_none = {
David Hendricksac1d25c2016-08-09 17:00:58 -070030 .chip_readb = noop_chip_readb,
31 .chip_readw = fallback_chip_readw,
32 .chip_readl = fallback_chip_readl,
33 .chip_readn = fallback_chip_readn,
34 .chip_writeb = noop_chip_writeb,
35 .chip_writew = fallback_chip_writew,
36 .chip_writel = fallback_chip_writel,
37 .chip_writen = fallback_chip_writen,
38};
39
Patrick Georgi0a9533a2017-02-03 19:28:38 +010040const struct par_master *par_master = &par_master_none;
David Hendricksac1d25c2016-08-09 17:00:58 -070041
hailfingerec022272010-01-06 10:21:00 +000042/* No-op shutdown() for programmers which don't need special handling */
43int noop_shutdown(void)
44{
45 return 0;
46}
47
48/* Fallback map() for programmers which don't need special handling */
Patrick Georgi4befc162017-02-03 18:32:01 +010049void *fallback_map(const char *descr, uintptr_t phys_addr, size_t len)
hailfingerec022272010-01-06 10:21:00 +000050{
51 /* FIXME: Should return phys_addr. */
stepand0d220f2011-01-24 19:15:51 +000052 return NULL;
hailfingerec022272010-01-06 10:21:00 +000053}
54
55/* No-op/fallback unmap() for programmers which don't need special handling */
56void fallback_unmap(void *virt_addr, size_t len)
57{
58}
59
David Hendricksac1d25c2016-08-09 17:00:58 -070060/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
61uint8_t noop_chip_readb(const struct flashctx *flash, const chipaddr addr)
62{
63 return 0xff;
64}
65
66/* No-op chip_writeb() for drivers not supporting addr/data pair accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070067void noop_chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000068{
69}
70
71/* Little-endian fallback for drivers not supporting 16 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070072void fallback_chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000073{
Souvik Ghoshd75cd672016-06-17 14:21:39 -070074 chip_writeb(flash, val & 0xff, addr);
75 chip_writeb(flash, (val >> 8) & 0xff, addr + 1);
hailfingerec022272010-01-06 10:21:00 +000076}
77
78/* Little-endian fallback for drivers not supporting 16 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070079uint16_t fallback_chip_readw(const struct flashctx *flash, const chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000080{
81 uint16_t val;
Souvik Ghoshd75cd672016-06-17 14:21:39 -070082 val = chip_readb(flash, addr);
83 val |= chip_readb(flash, addr + 1) << 8;
hailfingerec022272010-01-06 10:21:00 +000084 return val;
85}
86
87/* Little-endian fallback for drivers not supporting 32 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070088void fallback_chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000089{
Souvik Ghoshd75cd672016-06-17 14:21:39 -070090 chip_writew(flash, val & 0xffff, addr);
91 chip_writew(flash, (val >> 16) & 0xffff, addr + 2);
hailfingerec022272010-01-06 10:21:00 +000092}
93
94/* Little-endian fallback for drivers not supporting 32 bit accesses */
Souvik Ghoshd75cd672016-06-17 14:21:39 -070095uint32_t fallback_chip_readl(const struct flashctx *flash, const chipaddr addr)
hailfingerec022272010-01-06 10:21:00 +000096{
97 uint32_t val;
Souvik Ghoshd75cd672016-06-17 14:21:39 -070098 val = chip_readw(flash, addr);
99 val |= chip_readw(flash, addr + 2) << 16;
hailfingerec022272010-01-06 10:21:00 +0000100 return val;
101}
102
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700103void fallback_chip_writen(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
hailfingerec022272010-01-06 10:21:00 +0000104{
105 size_t i;
106 for (i = 0; i < len; i++)
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700107 chip_writeb(flash, buf[i], addr + i);
hailfingerec022272010-01-06 10:21:00 +0000108 return;
109}
110
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700111void fallback_chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr, size_t len)
hailfingerec022272010-01-06 10:21:00 +0000112{
113 size_t i;
114 for (i = 0; i < len; i++)
Souvik Ghoshd75cd672016-06-17 14:21:39 -0700115 buf[i] = chip_readb(flash, addr + i);
hailfingerec022272010-01-06 10:21:00 +0000116 return;
117}
hailfinger76bb7e92011-11-09 23:40:00 +0000118
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100119void register_par_master(const struct par_master *pgm, const enum chipbustype buses)
hailfinger76bb7e92011-11-09 23:40:00 +0000120{
Patrick Georgi0a9533a2017-02-03 19:28:38 +0100121 par_master = pgm;
David Hendricksac1d25c2016-08-09 17:00:58 -0700122 buses_supported |= buses;
hailfinger76bb7e92011-11-09 23:40:00 +0000123}
David Hendricksba0827a2013-05-03 20:25:40 -0700124
Edward O'Callaghan20596a82019-06-13 14:47:03 +1000125/* The limit of 4 is totally arbitrary. */
126#define MASTERS_MAX 4
127struct registered_master registered_masters[MASTERS_MAX];
128int registered_master_count = 0;
129
130/* This function copies the struct registered_master parameter. */
131int register_master(const struct registered_master *mst)
132{
133 if (registered_master_count >= MASTERS_MAX) {
134 msg_perr("Tried to register more than %i master "
135 "interfaces.\n", MASTERS_MAX);
136 return ERROR_FLASHROM_LIMIT;
137 }
138 registered_masters[registered_master_count] = *mst;
139 registered_master_count++;
140
141 return 0;
142}
143
David Hendricksba0827a2013-05-03 20:25:40 -0700144struct programmer_alias aliases[] = {
David Hendricksac1d25c2016-08-09 17:00:58 -0700145 { "ec", ALIAS_EC },
146 { "host", ALIAS_HOST },
David Hendricksba0827a2013-05-03 20:25:40 -0700147 { NULL },
148};
149struct programmer_alias *alias;