xref: /freebsd/sys/arm64/arm64/bus_space_asm.S (revision c2e0d56f5e493a8514324fd5e062ddc99a68b599)
1/*-
2 * Copyright (c) 2014 Andrew Turner
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#include <sys/elf_common.h>
29#include <machine/asm.h>
30
31ENTRY(generic_bs_r_1)
32	ldrb	w0, [x1, x2]
33	ret
34END(generic_bs_r_1)
35
36ENTRY(generic_bs_r_2)
37	ldrh	w0, [x1, x2]
38	ret
39END(generic_bs_r_2)
40
41ENTRY(generic_bs_r_4)
42	ldr	w0, [x1, x2]
43	ret
44END(generic_bs_r_4)
45
46ENTRY(generic_bs_r_8)
47	ldr	x0, [x1, x2]
48	ret
49END(generic_bs_r_8)
50
51ENTRY(generic_bs_rm_1)
52	/* If there is anything to read. */
53	cbz	x4, 2f
54
55	/* Calculate the device address. */
56	add	x0, x1, x2
57	/*
58	 * x0 = The device address.
59	 * x3 = The kernel address.
60	 * x4 = Count
61	 */
62
63	/* Read the data. */
641:	ldrb	w1, [x0]
65	strb	w1, [x3], #1
66	subs	x4, x4, #1
67	b.ne	1b
68
692:	ret
70END(generic_bs_rm_1)
71
72ENTRY(generic_bs_rm_2)
73	/* If there is anything to read. */
74	cbz	x4, 2f
75
76	/* Calculate the device address. */
77	add	x0, x1, x2
78	/*
79	 * x0 = The device address.
80	 * x3 = The kernel address.
81	 * x4 = Count
82	 */
83
84	/* Read the data. */
851:	ldrh	w1, [x0]
86	strh	w1, [x3], #2
87	subs	x4, x4, #1
88	b.ne	1b
89
902:	ret
91END(generic_bs_rm_2)
92
93ENTRY(generic_bs_rm_4)
94	/* If there is anything to read. */
95	cbz	x4, 2f
96
97	/* Calculate the device address. */
98	add	x0, x1, x2
99	/*
100	 * x0 = The device address.
101	 * x3 = The kernel address.
102	 * x4 = Count
103	 */
104
105	/* Read the data. */
1061:	ldr	w1, [x0]
107	str	w1, [x3], #4
108	subs	x4, x4, #1
109	b.ne	1b
110
1112:	ret
112END(generic_bs_rm_4)
113
114ENTRY(generic_bs_rm_8)
115	/* If there is anything to read. */
116	cbz	x4, 2f
117
118	/* Calculate the device address. */
119	add	x0, x1, x2
120	/*
121	 * x0 = The device address.
122	 * x3 = The kernel address.
123	 * x4 = Count
124	 */
125
126	/* Read the data. */
1271:	ldr	x1, [x0]
128	str	x1, [x3], #8
129	subs	x4, x4, #1
130	b.ne	1b
131
1322:	ret
133END(generic_bs_rm_8)
134
135ENTRY(generic_bs_rr_1)
136	/* Is there is anything to read. */
137	cbz	x4, 2f
138
139	/* Calculate the device address. */
140	add	x0, x1, x2
141	/*
142	 * x0 = The device address.
143	 * x3 = The kernel address.
144	 * x4 = Count
145	 */
146
147	/* Read the data. */
1481:	ldrb	w1, [x0], #1
149	strb	w1, [x3], #1
150	subs	x4, x4, #1
151	b.ne	1b
152
1532:	ret
154END(generic_bs_rr_1)
155
156ENTRY(generic_bs_rr_2)
157	/* Is there is anything to read. */
158	cbz	x4, 2f
159
160	/* Calculate the device address. */
161	add	x0, x1, x2
162	/*
163	 * x0 = The device address.
164	 * x3 = The kernel address.
165	 * x4 = Count
166	 */
167
168	/* Read the data. */
1691:	ldrh	w1, [x0], #2
170	strh	w1, [x3], #2
171	subs	x4, x4, #1
172	b.ne	1b
173
1742:	ret
175END(generic_bs_rr_2)
176
177ENTRY(generic_bs_rr_4)
178	/* Is there is anything to read. */
179	cbz	x4, 2f
180
181	/* Calculate the device address. */
182	add	x0, x1, x2
183	/*
184	 * x0 = The device address.
185	 * x3 = The kernel address.
186	 * x4 = Count
187	 */
188
189	/* Read the data. */
1901:	ldr	w1, [x0], #4
191	str	w1, [x3], #4
192	subs	x4, x4, #1
193	b.ne	1b
194
1952:	ret
196END(generic_bs_rr_4)
197
198ENTRY(generic_bs_rr_8)
199	/* Is there is anything to read. */
200	cbz	x4, 2f
201
202	/* Calculate the device address. */
203	add	x0, x1, x2
204	/*
205	 * x0 = The device address.
206	 * x3 = The kernel address.
207	 * x4 = Count
208	 */
209
210	/* Read the data. */
2111:	ldr	x1, [x0], #8
212	str	x1, [x3], #8
213	subs	x4, x4, #1
214	b.ne	1b
215
2162:	ret
217END(generic_bs_rr_8)
218
219
220ENTRY(generic_bs_w_1)
221	strb	w3, [x1, x2]
222	ret
223END(generic_bs_w_1)
224
225ENTRY(generic_bs_w_2)
226	strh	w3, [x1, x2]
227	ret
228END(generic_bs_w_2)
229
230ENTRY(generic_bs_w_4)
231	str	w3, [x1, x2]
232	ret
233END(generic_bs_w_4)
234
235ENTRY(generic_bs_w_8)
236	str	x3, [x1, x2]
237	ret
238END(generic_bs_w_8)
239
240ENTRY(generic_bs_wm_1)
241	/* If there is anything to write. */
242	cbz	x4, 2f
243
244	add	x0, x1, x2
245	/*
246	 * x0 = The device address.
247	 * x3 = The kernel address.
248	 * x4 = Count
249	 */
250
251	/* Write the data */
2521:	ldrb	w1, [x3], #1
253	strb	w1, [x0]
254	subs	x4, x4, #1
255	b.ne	1b
256
2572:	ret
258END(generic_bs_wm_1)
259
260ENTRY(generic_bs_wm_2)
261	/* If there is anything to write. */
262	cbz	x4, 2f
263
264	add	x0, x1, x2
265	/*
266	 * x0 = The device address.
267	 * x3 = The kernel address.
268	 * x4 = Count
269	 */
270
271	/* Write the data */
2721:	ldrh	w1, [x3], #2
273	strh	w1, [x0]
274	subs	x4, x4, #1
275	b.ne	1b
276
2772:	ret
278END(generic_bs_wm_2)
279
280ENTRY(generic_bs_wm_4)
281	/* If there is anything to write. */
282	cbz	x4, 2f
283
284	add	x0, x1, x2
285	/*
286	 * x0 = The device address.
287	 * x3 = The kernel address.
288	 * x4 = Count
289	 */
290
291	/* Write the data */
2921:	ldr	w1, [x3], #4
293	str	w1, [x0]
294	subs	x4, x4, #1
295	b.ne	1b
296
2972:	ret
298END(generic_bs_wm_4)
299
300ENTRY(generic_bs_wm_8)
301	/* If there is anything to write. */
302	cbz	x4, 2f
303
304	add	x0, x1, x2
305	/*
306	 * x0 = The device address.
307	 * x3 = The kernel address.
308	 * x4 = Count
309	 */
310
311	/* Write the data */
3121:	ldr	x1, [x3], #8
313	str	x1, [x0]
314	subs	x4, x4, #1
315	b.ne	1b
316
3172:	ret
318END(generic_bs_wm_8)
319
320ENTRY(generic_bs_wr_1)
321	/* Is there is anything to write. */
322	cbz	x4, 2f
323
324	add	x0, x1, x2
325	/*
326	 * x0 = The device address.
327	 * x3 = The kernel address.
328	 * x4 = Count
329	 */
330
331	/* Write the data */
3321:	ldrb	w1, [x3], #1
333	strb	w1, [x0], #1
334	subs	x4, x4, #1
335	b.ne	1b
336
3372:	ret
338END(generic_bs_wr_1)
339
340ENTRY(generic_bs_wr_2)
341	/* Is there is anything to write. */
342	cbz	x4, 2f
343
344	add	x0, x1, x2
345	/*
346	 * x0 = The device address.
347	 * x3 = The kernel address.
348	 * x4 = Count
349	 */
350
351	/* Write the data */
3521:	ldrh	w1, [x3], #2
353	strh	w1, [x0], #2
354	subs	x4, x4, #1
355	b.ne	1b
356
3572:	ret
358END(generic_bs_wr_2)
359
360ENTRY(generic_bs_wr_4)
361	/* Is there is anything to write. */
362	cbz	x4, 2f
363
364	add	x0, x1, x2
365	/*
366	 * x0 = The device address.
367	 * x3 = The kernel address.
368	 * x4 = Count
369	 */
370
371	/* Write the data */
3721:	ldr	w1, [x3], #4
373	str	w1, [x0], #4
374	subs	x4, x4, #1
375	b.ne	1b
376
3772:	ret
378END(generic_bs_wr_4)
379
380ENTRY(generic_bs_wr_8)
381	/* Is there is anything to write. */
382	cbz	x4, 2f
383
384	add	x0, x1, x2
385	/*
386	 * x0 = The device address.
387	 * x3 = The kernel address.
388	 * x4 = Count
389	 */
390
391	/* Write the data */
3921:	ldr	x1, [x3], #8
393	str	x1, [x0], #8
394	subs	x4, x4, #1
395	b.ne	1b
396
3972:	ret
398END(generic_bs_wr_8)
399
400ENTRY(generic_bs_fault)
401	mov	x0, #-1
402	ret
403END(generic_bs_fault)
404
405ENTRY(generic_bs_peek_1)
406	.globl	generic_bs_peek_1f
407generic_bs_peek_1f:
408	ldrb	w0, [x1, x2]	/* Checked instruction */
409	dsb	sy
410	strb	w0,[x3]
411	mov	x0, #0
412	ret
413END(generic_bs_peek_1)
414
415ENTRY(generic_bs_peek_2)
416	.globl	generic_bs_peek_2f
417generic_bs_peek_2f:
418	ldrh	w0, [x1, x2]	/* Checked instruction */
419	dsb	sy
420	strh	w0,[x3]
421	mov	x0, #0
422	ret
423END(generic_bs_peek_2)
424
425ENTRY(generic_bs_peek_4)
426	.globl	generic_bs_peek_4f
427generic_bs_peek_4f:
428	ldr	w0, [x1, x2]	/* Checked instruction */
429	dsb	sy
430	str	w0,[x3]
431	mov	x0, #0
432	ret
433END(generic_bs_peek_4)
434
435ENTRY(generic_bs_peek_8)
436	.globl	generic_bs_peek_8f
437generic_bs_peek_8f:
438	ldr	x0, [x1, x2]	/* Checked instruction */
439	dsb	sy
440	str	x0,[x3]
441	mov	x0, #0
442	ret
443END(generic_bs_peek_8)
444
445ENTRY(generic_bs_poke_1)
446	.globl	generic_bs_poke_1f
447generic_bs_poke_1f:
448	strb	w3, [x1, x2]	/* Checked instruction */
449	dsb	sy
450	mov	x0, #0
451	ret
452END(generic_bs_poke_1)
453
454ENTRY(generic_bs_poke_2)
455	.globl	generic_bs_poke_2f
456generic_bs_poke_2f:
457	strh	w3, [x1, x2]	/* Checked instruction */
458	dsb	sy
459	mov	x0, #0
460	ret
461END(generic_bs_poke_2)
462
463ENTRY(generic_bs_poke_4)
464	.globl	generic_bs_poke_4f
465generic_bs_poke_4f:
466	str	w3, [x1, x2]	/* Checked instruction */
467	dsb	sy
468	mov	x0, #0
469	ret
470END(generic_bs_poke_4)
471
472ENTRY(generic_bs_poke_8)
473	.globl	generic_bs_poke_8f
474generic_bs_poke_8f:
475	str	x3, [x1, x2]	/* Checked instruction */
476	dsb	sy
477	mov	x0, #0
478	ret
479END(generic_bs_poke_8)
480
481GNU_PROPERTY_AARCH64_FEATURE_1_NOTE(GNU_PROPERTY_AARCH64_FEATURE_1_VAL)
482