blob: f098ffc1537c8b5d9ccc3ecaca4a8c8957eb295c [file] [log] [blame]
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +00001/*
2 * This file is part of the flashrom project.
3 *
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +00004 * Copyright (C) 2011,2013,2014 Carl-Daniel Hailfinger
Carl-Daniel Hailfinger532c7172011-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.
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000014 */
15
16/*
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000017 * Contains the opaque master framework.
18 * An opaque master is a master which does not provide direct access
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000019 * to the flash chip and which abstracts all flash chip properties into a
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000020 * master specific interface.
Carl-Daniel Hailfinger532c7172011-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
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000029int probe_opaque(struct flashctx *flash)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000030{
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000031 return flash->mst->opaque.probe(flash);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000032}
33
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000034int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000035{
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000036 return flash->mst->opaque.read(flash, buf, start, len);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000037}
38
Mark Marshallf20b7be2014-05-09 21:16:21 +000039int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000040{
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000041 return flash->mst->opaque.write(flash, buf, start, len);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000042}
43
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000044int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000045{
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000046 return flash->mst->opaque.erase(flash, blockaddr, blocklen);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000047}
48
Anastasia Klimchuk9309bed2021-05-13 12:28:47 +100049int register_opaque_master(const struct opaque_master *mst, void *data)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000050{
Edward O'Callaghan4eef6512021-02-03 11:19:41 +110051 struct registered_master rmst = {0};
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +000052
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000053 if (!mst->probe || !mst->read || !mst->write || !mst->erase) {
54 msg_perr("%s called with incomplete master definition. "
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +000055 "Please report a bug at flashrom@flashrom.org\n",
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000056 __func__);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +000057 return ERROR_FLASHROM_BUG;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000058 }
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000059 rmst.buses_supported = BUS_PROG;
60 rmst.opaque = *mst;
Anastasia Klimchuk9309bed2021-05-13 12:28:47 +100061 if (data)
62 rmst.opaque.data = data;
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000063 return register_master(&rmst);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000064}