blob: 06d1895e789b96352153bd1c4c5328be8de57623 [file] [log] [blame]
hailfingerfe7cd9e2011-11-04 21:35:26 +00001/*
2 * This file is part of the flashrom project.
3 *
Edward O'Callaghanc66827e2020-10-09 12:22:04 +11004 * Copyright (C) 2011,2013,2014 Carl-Daniel Hailfinger
hailfingerfe7cd9e2011-11-04 21:35:26 +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; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
hailfingerfe7cd9e2011-11-04 21:35:26 +000014 */
15
16/*
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110017 * Contains the opaque master framework.
18 * An opaque master is a master which does not provide direct access
hailfingerfe7cd9e2011-11-04 21:35:26 +000019 * to the flash chip and which abstracts all flash chip properties into a
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110020 * master specific interface.
hailfingerfe7cd9e2011-11-04 21:35:26 +000021 */
22
23#include <stdint.h>
24#include "flash.h"
25#include "flashchips.h"
26#include "chipdrivers.h"
27#include "programmer.h"
28
Souvik Ghoshd75cd672016-06-17 14:21:39 -070029int probe_opaque(struct flashctx *flash)
hailfingerfe7cd9e2011-11-04 21:35:26 +000030{
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110031 return flash->mst->opaque.probe(flash);
hailfingerfe7cd9e2011-11-04 21:35:26 +000032}
33
Souvik Ghoshd75cd672016-06-17 14:21:39 -070034int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
hailfingerfe7cd9e2011-11-04 21:35:26 +000035{
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110036 return flash->mst->opaque.read(flash, buf, start, len);
hailfingerfe7cd9e2011-11-04 21:35:26 +000037}
38
Patrick Georgiab8353e2017-02-03 18:32:01 +010039int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
hailfingerfe7cd9e2011-11-04 21:35:26 +000040{
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110041 return flash->mst->opaque.write(flash, buf, start, len);
hailfingerfe7cd9e2011-11-04 21:35:26 +000042}
43
Souvik Ghoshd75cd672016-06-17 14:21:39 -070044int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen)
hailfingerfe7cd9e2011-11-04 21:35:26 +000045{
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110046 return flash->mst->opaque.erase(flash, blockaddr, blocklen);
hailfingerfe7cd9e2011-11-04 21:35:26 +000047}
48
Souvik Ghoshd75cd672016-06-17 14:21:39 -070049uint8_t read_status_opaque(const struct flashctx *flash)
Ramya Vijaykumar4af3f822016-01-27 11:51:27 +053050{
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110051 if (flash->mst->opaque.read_status)
52 return flash->mst->opaque.read_status(flash);
53 return 1;
Ramya Vijaykumar4af3f822016-01-27 11:51:27 +053054}
55
Souvik Ghoshd75cd672016-06-17 14:21:39 -070056int write_status_opaque(const struct flashctx *flash, int status)
Ramya Vijaykumar4af3f822016-01-27 11:51:27 +053057{
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110058 if (flash->mst->opaque.write_status)
59 return flash->mst->opaque.write_status(flash, status);
60 return 1;
David Hendricksac1d25c2016-08-09 17:00:58 -070061}
62
Duncan Laurie25a4ca22019-04-25 12:08:52 -070063int check_access_opaque(const struct flashctx *flash, unsigned int start, unsigned int len, int rw)
64{
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110065 if (flash->mst->opaque.check_access)
66 return flash->mst->opaque.check_access(flash, start, len, rw);
Duncan Laurie25a4ca22019-04-25 12:08:52 -070067 return 1;
68}
69
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110070int register_opaque_master(const struct opaque_master *mst)
David Hendricksac1d25c2016-08-09 17:00:58 -070071{
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110072 struct registered_master rmst;
73
74 if (!mst->probe || !mst->read || !mst->write || !mst->erase) {
75 msg_perr("%s called with incomplete master definition. "
76 "Please report a bug at flashrom@flashrom.org\n",
David Hendricksac1d25c2016-08-09 17:00:58 -070077 __func__);
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110078 return ERROR_FLASHROM_BUG;
David Hendricksac1d25c2016-08-09 17:00:58 -070079 }
Edward O'Callaghanc66827e2020-10-09 12:22:04 +110080 rmst.buses_supported = BUS_PROG;
81 rmst.opaque = *mst;
82 return register_master(&rmst);
hailfingerfe7cd9e2011-11-04 21:35:26 +000083}