blob: a5a829c6ad1a1b36c73fcb901cba16eebd1698d7 [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20/*
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000021 * Contains the opaque master framework.
22 * An opaque master is a master which does not provide direct access
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000023 * to the flash chip and which abstracts all flash chip properties into a
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000024 * master specific interface.
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000025 */
26
27#include <stdint.h>
28#include "flash.h"
29#include "flashchips.h"
30#include "chipdrivers.h"
31#include "programmer.h"
32
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000033int probe_opaque(struct flashctx *flash)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000034{
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000035 return flash->mst->opaque.probe(flash);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000036}
37
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000038int read_opaque(struct flashctx *flash, uint8_t *buf, unsigned int start, unsigned int len)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000039{
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000040 return flash->mst->opaque.read(flash, buf, start, len);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000041}
42
Mark Marshallf20b7be2014-05-09 21:16:21 +000043int write_opaque(struct flashctx *flash, const uint8_t *buf, unsigned int start, unsigned int len)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000044{
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000045 return flash->mst->opaque.write(flash, buf, start, len);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000046}
47
Carl-Daniel Hailfinger63fd9022011-12-14 22:25:15 +000048int erase_opaque(struct flashctx *flash, unsigned int blockaddr, unsigned int blocklen)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000049{
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000050 return flash->mst->opaque.erase(flash, blockaddr, blocklen);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000051}
52
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000053int register_opaque_master(const struct opaque_master *mst)
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000054{
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000055 struct registered_master rmst;
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +000056
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000057 if (!mst->probe || !mst->read || !mst->write || !mst->erase) {
58 msg_perr("%s called with incomplete master definition. "
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +000059 "Please report a bug at flashrom@flashrom.org\n",
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000060 __func__);
Carl-Daniel Hailfingerc40cff72011-12-20 00:19:29 +000061 return ERROR_FLASHROM_BUG;
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000062 }
Carl-Daniel Hailfingera5bcbce2014-07-19 22:03:29 +000063 rmst.buses_supported = BUS_PROG;
64 rmst.opaque = *mst;
65 return register_master(&rmst);
Carl-Daniel Hailfinger532c7172011-11-04 21:35:26 +000066}