xref: /aosp_15_r20/external/flashrom/internal_par.c (revision 0d6140be3aa665ecc836e8907834fcd3e3b018fc)
1 /*
2  * This file is part of the flashrom project.
3  *
4  * Copyright (C) 2009 Carl-Daniel Hailfinger
5  *
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  */
16 
17 #include "programmer.h"
18 #include "hwaccess_physmap.h"
19 
internal_chip_writeb(const struct flashctx * flash,uint8_t val,chipaddr addr)20 static void internal_chip_writeb(const struct flashctx *flash, uint8_t val,
21 				 chipaddr addr)
22 {
23 	mmio_writeb(val, (void *) addr);
24 }
25 
internal_chip_writew(const struct flashctx * flash,uint16_t val,chipaddr addr)26 static void internal_chip_writew(const struct flashctx *flash, uint16_t val,
27 				 chipaddr addr)
28 {
29 	mmio_writew(val, (void *) addr);
30 }
31 
internal_chip_writel(const struct flashctx * flash,uint32_t val,chipaddr addr)32 static void internal_chip_writel(const struct flashctx *flash, uint32_t val,
33 				 chipaddr addr)
34 {
35 	mmio_writel(val, (void *) addr);
36 }
37 
internal_chip_readb(const struct flashctx * flash,const chipaddr addr)38 static uint8_t internal_chip_readb(const struct flashctx *flash,
39 				   const chipaddr addr)
40 {
41 	return mmio_readb((void *) addr);
42 }
43 
internal_chip_readw(const struct flashctx * flash,const chipaddr addr)44 static uint16_t internal_chip_readw(const struct flashctx *flash,
45 				    const chipaddr addr)
46 {
47 	return mmio_readw((void *) addr);
48 }
49 
internal_chip_readl(const struct flashctx * flash,const chipaddr addr)50 static uint32_t internal_chip_readl(const struct flashctx *flash,
51 				    const chipaddr addr)
52 {
53 	return mmio_readl((void *) addr);
54 }
55 
internal_chip_readn(const struct flashctx * flash,uint8_t * buf,const chipaddr addr,size_t len)56 static void internal_chip_readn(const struct flashctx *flash, uint8_t *buf,
57 				const chipaddr addr, size_t len)
58 {
59 	mmio_readn((void *)addr, buf, len);
60 	return;
61 }
62 
63 static const struct par_master par_master_internal = {
64 	.map_flash_region	= physmap,
65 	.unmap_flash_region	= physunmap,
66 	.chip_readb	= internal_chip_readb,
67 	.chip_readw	= internal_chip_readw,
68 	.chip_readl	= internal_chip_readl,
69 	.chip_readn	= internal_chip_readn,
70 	.chip_writeb	= internal_chip_writeb,
71 	.chip_writew	= internal_chip_writew,
72 	.chip_writel	= internal_chip_writel,
73 };
74 
internal_par_init(enum chipbustype buses)75 void internal_par_init(enum chipbustype buses)
76 {
77 	if (buses & BUS_NONSPI)
78 		register_par_master(&par_master_internal, internal_buses_supported, NULL);
79 }
80