Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the flashrom project. |
| 3 | * |
| 4 | * Copyright (C) 2000 Silicon Integrated System Corporation |
| 5 | * Copyright (C) 2004 Tyan Corp <yhlu@tyan.com> |
| 6 | * Copyright (C) 2005-2008 coresystems GmbH |
| 7 | * Copyright (C) 2008,2009 Carl-Daniel Hailfinger |
| 8 | * Copyright (C) 2016 secunet Security Networks AG |
| 9 | * (Written by Nico Huber <nico.huber@secunet.com> for secunet) |
| 10 | * Copyright (C) 2009,2010,2011 Carl-Daniel Hailfinger |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; version 2 of the License. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | */ |
| 21 | |
| 22 | #include "flash.h" |
| 23 | #include "programmer.h" |
| 24 | |
| 25 | void chip_writeb(const struct flashctx *flash, uint8_t val, chipaddr addr) |
| 26 | { |
Nico Huber | 9a11cbf | 2023-01-13 01:19:07 +0100 | [diff] [blame] | 27 | flash->mst.par->chip_writeb(flash, val, addr); |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | void chip_writew(const struct flashctx *flash, uint16_t val, chipaddr addr) |
| 31 | { |
Nico Huber | 9a11cbf | 2023-01-13 01:19:07 +0100 | [diff] [blame] | 32 | flash->mst.par->chip_writew(flash, val, addr); |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void chip_writel(const struct flashctx *flash, uint32_t val, chipaddr addr) |
| 36 | { |
Nico Huber | 9a11cbf | 2023-01-13 01:19:07 +0100 | [diff] [blame] | 37 | flash->mst.par->chip_writel(flash, val, addr); |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | void chip_writen(const struct flashctx *flash, const uint8_t *buf, chipaddr addr, size_t len) |
| 41 | { |
Nico Huber | 9a11cbf | 2023-01-13 01:19:07 +0100 | [diff] [blame] | 42 | flash->mst.par->chip_writen(flash, buf, addr, len); |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | uint8_t chip_readb(const struct flashctx *flash, const chipaddr addr) |
| 46 | { |
Nico Huber | 9a11cbf | 2023-01-13 01:19:07 +0100 | [diff] [blame] | 47 | return flash->mst.par->chip_readb(flash, addr); |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | uint16_t chip_readw(const struct flashctx *flash, const chipaddr addr) |
| 51 | { |
Nico Huber | 9a11cbf | 2023-01-13 01:19:07 +0100 | [diff] [blame] | 52 | return flash->mst.par->chip_readw(flash, addr); |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | uint32_t chip_readl(const struct flashctx *flash, const chipaddr addr) |
| 56 | { |
Nico Huber | 9a11cbf | 2023-01-13 01:19:07 +0100 | [diff] [blame] | 57 | return flash->mst.par->chip_readl(flash, addr); |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void chip_readn(const struct flashctx *flash, uint8_t *buf, chipaddr addr, |
| 61 | size_t len) |
| 62 | { |
Nico Huber | 9a11cbf | 2023-01-13 01:19:07 +0100 | [diff] [blame] | 63 | flash->mst.par->chip_readn(flash, buf, addr, len); |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 64 | } |
| 65 | |
Nico Huber | 89569d6 | 2023-01-12 23:31:40 +0100 | [diff] [blame] | 66 | int register_par_master(const struct par_master *mst, const enum chipbustype buses, |
| 67 | const size_t max_rom_decode, void *data) |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 68 | { |
| 69 | struct registered_master rmst; |
| 70 | |
| 71 | if (mst->shutdown) { |
| 72 | if (register_shutdown(mst->shutdown, data)) { |
| 73 | mst->shutdown(data); /* cleanup */ |
| 74 | return 1; |
| 75 | } |
| 76 | } |
| 77 | |
| 78 | if (!mst->chip_writeb || !mst->chip_writew || !mst->chip_writel || |
| 79 | !mst->chip_writen || !mst->chip_readb || !mst->chip_readw || |
| 80 | !mst->chip_readl || !mst->chip_readn) { |
| 81 | msg_perr("%s called with incomplete master definition.\n" |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame] | 82 | "Please report a bug at flashprog@flashprog.org\n", |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 83 | __func__); |
Nico Huber | c3b02dc | 2023-08-12 01:13:45 +0200 | [diff] [blame] | 84 | return ERROR_FLASHPROG_BUG; |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 85 | } |
| 86 | |
Nico Huber | 89569d6 | 2023-01-12 23:31:40 +0100 | [diff] [blame] | 87 | if (max_rom_decode) |
| 88 | rmst.max_rom_decode = max_rom_decode; |
| 89 | else |
| 90 | rmst.max_rom_decode = DEFAULT_MAX_DECODE_PARALLEL; |
Edward O'Callaghan | 63f6a37 | 2022-08-12 12:56:43 +1000 | [diff] [blame] | 91 | rmst.buses_supported = buses; |
| 92 | rmst.par = *mst; |
| 93 | if (data) |
| 94 | rmst.par.data = data; |
| 95 | return register_master(&rmst); |
| 96 | } |