xref: /freebsd/sys/arm64/arm64/bus_space_asm.S (revision 069ac184)
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 <machine/asm.h>
29ENTRY(generic_bs_r_1)
30	ldrb	w0, [x1, x2]
31	ret
32END(generic_bs_r_1)
33
34ENTRY(generic_bs_r_2)
35	ldrh	w0, [x1, x2]
36	ret
37END(generic_bs_r_2)
38
39ENTRY(generic_bs_r_4)
40	ldr	w0, [x1, x2]
41	ret
42END(generic_bs_r_4)
43
44ENTRY(generic_bs_r_8)
45	ldr	x0, [x1, x2]
46	ret
47END(generic_bs_r_8)
48
49ENTRY(generic_bs_rm_1)
50	/* If there is anything to read. */
51	cbz	x4, 2f
52
53	/* Calculate the device address. */
54	add	x0, x1, x2
55	/*
56	 * x0 = The device address.
57	 * x3 = The kernel address.
58	 * x4 = Count
59	 */
60
61	/* Read the data. */
621:	ldrb	w1, [x0]
63	strb	w1, [x3], #1
64	subs	x4, x4, #1
65	b.ne	1b
66
672:	ret
68END(generic_bs_rm_1)
69
70ENTRY(generic_bs_rm_2)
71	/* If there is anything to read. */
72	cbz	x4, 2f
73
74	/* Calculate the device address. */
75	add	x0, x1, x2
76	/*
77	 * x0 = The device address.
78	 * x3 = The kernel address.
79	 * x4 = Count
80	 */
81
82	/* Read the data. */
831:	ldrh	w1, [x0]
84	strh	w1, [x3], #2
85	subs	x4, x4, #1
86	b.ne	1b
87
882:	ret
89END(generic_bs_rm_2)
90
91ENTRY(generic_bs_rm_4)
92	/* If there is anything to read. */
93	cbz	x4, 2f
94
95	/* Calculate the device address. */
96	add	x0, x1, x2
97	/*
98	 * x0 = The device address.
99	 * x3 = The kernel address.
100	 * x4 = Count
101	 */
102
103	/* Read the data. */
1041:	ldr	w1, [x0]
105	str	w1, [x3], #4
106	subs	x4, x4, #1
107	b.ne	1b
108
1092:	ret
110END(generic_bs_rm_4)
111
112ENTRY(generic_bs_rm_8)
113	/* If there is anything to read. */
114	cbz	x4, 2f
115
116	/* Calculate the device address. */
117	add	x0, x1, x2
118	/*
119	 * x0 = The device address.
120	 * x3 = The kernel address.
121	 * x4 = Count
122	 */
123
124	/* Read the data. */
1251:	ldr	x1, [x0]
126	str	x1, [x3], #8
127	subs	x4, x4, #1
128	b.ne	1b
129
1302:	ret
131END(generic_bs_rm_8)
132
133ENTRY(generic_bs_rr_1)
134	/* Is there is anything to read. */
135	cbz	x4, 2f
136
137	/* Calculate the device address. */
138	add	x0, x1, x2
139	/*
140	 * x0 = The device address.
141	 * x3 = The kernel address.
142	 * x4 = Count
143	 */
144
145	/* Read the data. */
1461:	ldrb	w1, [x0], #1
147	strb	w1, [x3], #1
148	subs	x4, x4, #1
149	b.ne	1b
150
1512:	ret
152END(generic_bs_rr_1)
153
154ENTRY(generic_bs_rr_2)
155	/* Is there is anything to read. */
156	cbz	x4, 2f
157
158	/* Calculate the device address. */
159	add	x0, x1, x2
160	/*
161	 * x0 = The device address.
162	 * x3 = The kernel address.
163	 * x4 = Count
164	 */
165
166	/* Read the data. */
1671:	ldrh	w1, [x0], #2
168	strh	w1, [x3], #2
169	subs	x4, x4, #1
170	b.ne	1b
171
1722:	ret
173END(generic_bs_rr_2)
174
175ENTRY(generic_bs_rr_4)
176	/* Is there is anything to read. */
177	cbz	x4, 2f
178
179	/* Calculate the device address. */
180	add	x0, x1, x2
181	/*
182	 * x0 = The device address.
183	 * x3 = The kernel address.
184	 * x4 = Count
185	 */
186
187	/* Read the data. */
1881:	ldr	w1, [x0], #4
189	str	w1, [x3], #4
190	subs	x4, x4, #1
191	b.ne	1b
192
1932:	ret
194END(generic_bs_rr_4)
195
196ENTRY(generic_bs_rr_8)
197	/* Is there is anything to read. */
198	cbz	x4, 2f
199
200	/* Calculate the device address. */
201	add	x0, x1, x2
202	/*
203	 * x0 = The device address.
204	 * x3 = The kernel address.
205	 * x4 = Count
206	 */
207
208	/* Read the data. */
2091:	ldr	x1, [x0], #8
210	str	x1, [x3], #8
211	subs	x4, x4, #1
212	b.ne	1b
213
2142:	ret
215END(generic_bs_rr_8)
216
217
218ENTRY(generic_bs_w_1)
219	strb	w3, [x1, x2]
220	ret
221END(generic_bs_w_1)
222
223ENTRY(generic_bs_w_2)
224	strh	w3, [x1, x2]
225	ret
226END(generic_bs_w_2)
227
228ENTRY(generic_bs_w_4)
229	str	w3, [x1, x2]
230	ret
231END(generic_bs_w_4)
232
233ENTRY(generic_bs_w_8)
234	str	x3, [x1, x2]
235	ret
236END(generic_bs_w_8)
237
238ENTRY(generic_bs_wm_1)
239	/* If there is anything to write. */
240	cbz	x4, 2f
241
242	add	x0, x1, x2
243	/*
244	 * x0 = The device address.
245	 * x3 = The kernel address.
246	 * x4 = Count
247	 */
248
249	/* Write the data */
2501:	ldrb	w1, [x3], #1
251	strb	w1, [x0]
252	subs	x4, x4, #1
253	b.ne	1b
254
2552:	ret
256END(generic_bs_wm_1)
257
258ENTRY(generic_bs_wm_2)
259	/* If there is anything to write. */
260	cbz	x4, 2f
261
262	add	x0, x1, x2
263	/*
264	 * x0 = The device address.
265	 * x3 = The kernel address.
266	 * x4 = Count
267	 */
268
269	/* Write the data */
2701:	ldrh	w1, [x3], #2
271	strh	w1, [x0]
272	subs	x4, x4, #1
273	b.ne	1b
274
2752:	ret
276END(generic_bs_wm_2)
277
278ENTRY(generic_bs_wm_4)
279	/* If there is anything to write. */
280	cbz	x4, 2f
281
282	add	x0, x1, x2
283	/*
284	 * x0 = The device address.
285	 * x3 = The kernel address.
286	 * x4 = Count
287	 */
288
289	/* Write the data */
2901:	ldr	w1, [x3], #4
291	str	w1, [x0]
292	subs	x4, x4, #1
293	b.ne	1b
294
2952:	ret
296END(generic_bs_wm_4)
297
298ENTRY(generic_bs_wm_8)
299	/* If there is anything to write. */
300	cbz	x4, 2f
301
302	add	x0, x1, x2
303	/*
304	 * x0 = The device address.
305	 * x3 = The kernel address.
306	 * x4 = Count
307	 */
308
309	/* Write the data */
3101:	ldr	x1, [x3], #8
311	str	x1, [x0]
312	subs	x4, x4, #1
313	b.ne	1b
314
3152:	ret
316END(generic_bs_wm_8)
317
318ENTRY(generic_bs_wr_1)
319	/* Is there is anything to write. */
320	cbz	x4, 2f
321
322	add	x0, x1, x2
323	/*
324	 * x0 = The device address.
325	 * x3 = The kernel address.
326	 * x4 = Count
327	 */
328
329	/* Write the data */
3301:	ldrb	w1, [x3], #1
331	strb	w1, [x0], #1
332	subs	x4, x4, #1
333	b.ne	1b
334
3352:	ret
336END(generic_bs_wr_1)
337
338ENTRY(generic_bs_wr_2)
339	/* Is there is anything to write. */
340	cbz	x4, 2f
341
342	add	x0, x1, x2
343	/*
344	 * x0 = The device address.
345	 * x3 = The kernel address.
346	 * x4 = Count
347	 */
348
349	/* Write the data */
3501:	ldrh	w1, [x3], #2
351	strh	w1, [x0], #2
352	subs	x4, x4, #1
353	b.ne	1b
354
3552:	ret
356END(generic_bs_wr_2)
357
358ENTRY(generic_bs_wr_4)
359	/* Is there is anything to write. */
360	cbz	x4, 2f
361
362	add	x0, x1, x2
363	/*
364	 * x0 = The device address.
365	 * x3 = The kernel address.
366	 * x4 = Count
367	 */
368
369	/* Write the data */
3701:	ldr	w1, [x3], #4
371	str	w1, [x0], #4
372	subs	x4, x4, #1
373	b.ne	1b
374
3752:	ret
376END(generic_bs_wr_4)
377
378ENTRY(generic_bs_wr_8)
379	/* Is there is anything to write. */
380	cbz	x4, 2f
381
382	add	x0, x1, x2
383	/*
384	 * x0 = The device address.
385	 * x3 = The kernel address.
386	 * x4 = Count
387	 */
388
389	/* Write the data */
3901:	ldr	x1, [x3], #8
391	str	x1, [x0], #8
392	subs	x4, x4, #1
393	b.ne	1b
394
3952:	ret
396END(generic_bs_wr_8)
397
398ENTRY(generic_bs_fault)
399	mov	x0, #-1
400	ret
401END(generic_bs_fault)
402
403ENTRY(generic_bs_peek_1)
404	.globl	generic_bs_peek_1f
405generic_bs_peek_1f:
406	ldrb	w0, [x1, x2]	/* Checked instruction */
407	dsb	sy
408	strb	w0,[x3]
409	mov	x0, #0
410	ret
411END(generic_bs_peek_1)
412
413ENTRY(generic_bs_peek_2)
414	.globl	generic_bs_peek_2f
415generic_bs_peek_2f:
416	ldrh	w0, [x1, x2]	/* Checked instruction */
417	dsb	sy
418	strh	w0,[x3]
419	mov	x0, #0
420	ret
421END(generic_bs_peek_2)
422
423ENTRY(generic_bs_peek_4)
424	.globl	generic_bs_peek_4f
425generic_bs_peek_4f:
426	ldr	w0, [x1, x2]	/* Checked instruction */
427	dsb	sy
428	str	w0,[x3]
429	mov	x0, #0
430	ret
431END(generic_bs_peek_4)
432
433ENTRY(generic_bs_peek_8)
434	.globl	generic_bs_peek_8f
435generic_bs_peek_8f:
436	ldr	x0, [x1, x2]	/* Checked instruction */
437	dsb	sy
438	str	x0,[x3]
439	mov	x0, #0
440	ret
441END(generic_bs_peek_8)
442
443ENTRY(generic_bs_poke_1)
444	.globl	generic_bs_poke_1f
445generic_bs_poke_1f:
446	strb	w3, [x1, x2]	/* Checked instruction */
447	dsb	sy
448	mov	x0, #0
449	ret
450END(generic_bs_poke_1)
451
452ENTRY(generic_bs_poke_2)
453	.globl	generic_bs_poke_2f
454generic_bs_poke_2f:
455	strh	w3, [x1, x2]	/* Checked instruction */
456	dsb	sy
457	mov	x0, #0
458	ret
459END(generic_bs_poke_2)
460
461ENTRY(generic_bs_poke_4)
462	.globl	generic_bs_poke_4f
463generic_bs_poke_4f:
464	str	w3, [x1, x2]	/* Checked instruction */
465	dsb	sy
466	mov	x0, #0
467	ret
468END(generic_bs_poke_4)
469
470ENTRY(generic_bs_poke_8)
471	.globl	generic_bs_poke_8f
472generic_bs_poke_8f:
473	str	x3, [x1, x2]	/* Checked instruction */
474	dsb	sy
475	mov	x0, #0
476	ret
477END(generic_bs_poke_8)
478