[iscsi] Eliminate variable-length stack allocation in URI parsing
[ipxe.git] / src / arch / arm / core / arm_io.c
1 /*
2 * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 #include <ipxe/io.h>
27 #include <ipxe/arm_io.h>
28
29 /** @file
30 *
31 * iPXE I/O API for ARM
32 *
33 */
34
35 /** An ARM I/O qword */
36 union arm32_io_qword {
37 uint64_t qword;
38 uint32_t dword[2];
39 };
40
41 /**
42 * Read 64-bit qword from memory-mapped device
43 *
44 * @v io_addr I/O address
45 * @ret data Value read
46 *
47 * This is not atomic for ARM32.
48 */
49 static uint64_t arm32_readq ( volatile uint64_t *io_addr ) {
50 volatile union arm32_io_qword *ptr =
51 container_of ( io_addr, union arm32_io_qword, qword );
52 union arm32_io_qword tmp;
53
54 tmp.dword[0] = readl ( &ptr->dword[0] );
55 tmp.dword[1] = readl ( &ptr->dword[1] );
56 return tmp.qword;
57 }
58
59 /**
60 * Write 64-bit qword to memory-mapped device
61 *
62 * @v data Value to write
63 * @v io_addr I/O address
64 *
65 * This is not atomic for ARM32.
66 */
67 static void arm32_writeq ( uint64_t data, volatile uint64_t *io_addr ) {
68 volatile union arm32_io_qword *ptr =
69 container_of ( io_addr, union arm32_io_qword, qword );
70 union arm32_io_qword tmp;
71
72 tmp.qword = data;
73 writel ( tmp.dword[0], &ptr->dword[0] );
74 writel ( tmp.dword[1], &ptr->dword[1] );
75 }
76
77 PROVIDE_IOAPI_INLINE ( arm, phys_to_bus );
78 PROVIDE_IOAPI_INLINE ( arm, bus_to_phys );
79 PROVIDE_IOAPI_INLINE ( arm, readb );
80 PROVIDE_IOAPI_INLINE ( arm, readw );
81 PROVIDE_IOAPI_INLINE ( arm, readl );
82 PROVIDE_IOAPI_INLINE ( arm, writeb );
83 PROVIDE_IOAPI_INLINE ( arm, writew );
84 PROVIDE_IOAPI_INLINE ( arm, writel );
85 PROVIDE_IOAPI_INLINE ( arm, iodelay );
86 PROVIDE_IOAPI_INLINE ( arm, mb );
87 #ifdef __aarch64__
88 PROVIDE_IOAPI_INLINE ( arm, readq );
89 PROVIDE_IOAPI_INLINE ( arm, writeq );
90 #else
91 PROVIDE_IOAPI ( arm, readq, arm32_readq );
92 PROVIDE_IOAPI ( arm, writeq, arm32_writeq );
93 #endif