Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/benh/powerpc
[linux-2.6.git] / arch / s390 / kernel / sclp.S
1 /*
2  * Mini SCLP driver.
3  *
4  * Copyright IBM Corp. 2004,2009
5  *
6  *   Author(s): Peter Oberparleiter <Peter.Oberparleiter@de.ibm.com>,
7  *              Heiko Carstens <heiko.carstens@de.ibm.com>,
8  *
9  */
10
11 #include <linux/linkage.h>
12
13 LC_EXT_NEW_PSW          = 0x58                  # addr of ext int handler
14 LC_EXT_NEW_PSW_64       = 0x1b0                 # addr of ext int handler 64 bit
15 LC_EXT_INT_PARAM        = 0x80                  # addr of ext int parameter
16 LC_EXT_INT_CODE         = 0x86                  # addr of ext int code
17 LC_AR_MODE_ID           = 0xa3
18
19 #
20 # Subroutine which waits synchronously until either an external interruption
21 # or a timeout occurs.
22 #
23 # Parameters:
24 #   R2  = 0 for no timeout, non-zero for timeout in (approximated) seconds
25 #
26 # Returns:
27 #   R2  = 0 on interrupt, 2 on timeout
28 #   R3  = external interruption parameter if R2=0
29 #
30
31 _sclp_wait_int:
32         stm     %r6,%r15,24(%r15)               # save registers
33         basr    %r13,0                          # get base register
34 .LbaseS1:
35         ahi     %r15,-96                        # create stack frame
36         la      %r8,LC_EXT_NEW_PSW              # register int handler
37         la      %r9,.LextpswS1-.LbaseS1(%r13)
38 #ifdef CONFIG_64BIT
39         tm      LC_AR_MODE_ID,1
40         jno     .Lesa1
41         la      %r8,LC_EXT_NEW_PSW_64           # register int handler 64 bit
42         la      %r9,.LextpswS1_64-.LbaseS1(%r13)
43 .Lesa1:
44 #endif
45         mvc     .LoldpswS1-.LbaseS1(16,%r13),0(%r8)
46         mvc     0(16,%r8),0(%r9)
47         lhi     %r6,0x0200                      # cr mask for ext int (cr0.54)
48         ltr     %r2,%r2
49         jz      .LsetctS1
50         ahi     %r6,0x0800                      # cr mask for clock int (cr0.52)
51         stck    .LtimeS1-.LbaseS1(%r13)         # initiate timeout
52         al      %r2,.LtimeS1-.LbaseS1(%r13)
53         st      %r2,.LtimeS1-.LbaseS1(%r13)
54         sckc    .LtimeS1-.LbaseS1(%r13)
55
56 .LsetctS1:
57         stctl   %c0,%c0,.LctlS1-.LbaseS1(%r13)  # enable required interrupts
58         l       %r0,.LctlS1-.LbaseS1(%r13)
59         lhi     %r1,~(0x200 | 0x800)            # clear old values
60         nr      %r1,%r0
61         or      %r1,%r6                         # set new value
62         st      %r1,.LctlS1-.LbaseS1(%r13)
63         lctl    %c0,%c0,.LctlS1-.LbaseS1(%r13)
64         st      %r0,.LctlS1-.LbaseS1(%r13)
65         lhi     %r2,2                           # return code for timeout
66 .LloopS1:
67         lpsw    .LwaitpswS1-.LbaseS1(%r13)      # wait until interrupt
68 .LwaitS1:
69         lh      %r7,LC_EXT_INT_CODE
70         chi     %r7,0x1004                      # timeout?
71         je      .LtimeoutS1
72         chi     %r7,0x2401                      # service int?
73         jne     .LloopS1
74         sr      %r2,%r2
75         l       %r3,LC_EXT_INT_PARAM
76 .LtimeoutS1:
77         lctl    %c0,%c0,.LctlS1-.LbaseS1(%r13)  # restore interrupt setting
78         # restore old handler
79         mvc     0(16,%r8),.LoldpswS1-.LbaseS1(%r13)
80         lm      %r6,%r15,120(%r15)              # restore registers
81         br      %r14                            # return to caller
82
83         .align  8
84 .LoldpswS1:
85         .long   0, 0, 0, 0                      # old ext int PSW
86 .LextpswS1:
87         .long   0x00080000, 0x80000000+.LwaitS1 # PSW to handle ext int
88 #ifdef CONFIG_64BIT
89 .LextpswS1_64:
90         .quad   0x0000000180000000, .LwaitS1    # PSW to handle ext int, 64 bit
91 #endif
92 .LwaitpswS1:
93         .long   0x010a0000, 0x00000000+.LloopS1 # PSW to wait for ext int
94 .LtimeS1:
95         .quad   0                               # current time
96 .LctlS1:
97         .long   0                               # CT0 contents
98
99 #
100 # Subroutine to synchronously issue a service call.
101 #
102 # Parameters:
103 #   R2  = command word
104 #   R3  = sccb address
105 #
106 # Returns:
107 #   R2  = 0 on success, 1 on failure
108 #   R3  = sccb response code if R2 = 0
109 #
110
111 _sclp_servc:
112         stm     %r6,%r15,24(%r15)               # save registers
113         ahi     %r15,-96                        # create stack frame
114         lr      %r6,%r2                         # save command word
115         lr      %r7,%r3                         # save sccb address
116 .LretryS2:
117         lhi     %r2,1                           # error return code
118         .insn   rre,0xb2200000,%r6,%r7          # servc
119         brc     1,.LendS2                       # exit if not operational
120         brc     8,.LnotbusyS2                   # go on if not busy
121         sr      %r2,%r2                         # wait until no longer busy
122         bras    %r14,_sclp_wait_int
123         j       .LretryS2                       # retry
124 .LnotbusyS2:
125         sr      %r2,%r2                         # wait until result
126         bras    %r14,_sclp_wait_int
127         sr      %r2,%r2
128         lh      %r3,6(%r7)
129 .LendS2:
130         lm      %r6,%r15,120(%r15)              # restore registers
131         br      %r14
132
133 #
134 # Subroutine to set up the SCLP interface.
135 #
136 # Parameters:
137 #   R2  = 0 to activate, non-zero to deactivate
138 #
139 # Returns:
140 #   R2  = 0 on success, non-zero on failure
141 #
142
143 _sclp_setup:
144         stm     %r6,%r15,24(%r15)               # save registers
145         ahi     %r15,-96                        # create stack frame
146         basr    %r13,0                          # get base register
147 .LbaseS3:
148         l       %r6,.LsccbS0-.LbaseS3(%r13)     # prepare init mask sccb
149         mvc     0(.LinitendS3-.LinitsccbS3,%r6),.LinitsccbS3-.LbaseS3(%r13)
150         ltr     %r2,%r2                         # initialization?
151         jz      .LdoinitS3                      # go ahead
152         # clear masks
153         xc      .LinitmaskS3-.LinitsccbS3(8,%r6),.LinitmaskS3-.LinitsccbS3(%r6)
154 .LdoinitS3:
155         l       %r2,.LwritemaskS3-.LbaseS3(%r13)# get command word
156         lr      %r3,%r6                         # get sccb address
157         bras    %r14,_sclp_servc                # issue service call
158         ltr     %r2,%r2                         # servc successful?
159         jnz     .LerrorS3
160         chi     %r3,0x20                        # write mask successful?
161         jne     .LerrorS3
162         # check masks
163         la      %r2,.LinitmaskS3-.LinitsccbS3(%r6)
164         l       %r1,0(%r2)                      # receive mask ok?
165         n       %r1,12(%r2)
166         cl      %r1,0(%r2)
167         jne     .LerrorS3
168         l       %r1,4(%r2)                      # send mask ok?
169         n       %r1,8(%r2)
170         cl      %r1,4(%r2)
171         sr      %r2,%r2
172         je      .LendS3
173 .LerrorS3:
174         lhi     %r2,1                           # error return code
175 .LendS3:
176         lm      %r6,%r15,120(%r15)              # restore registers
177         br      %r14
178 .LwritemaskS3:
179         .long   0x00780005                      # SCLP command for write mask
180 .LinitsccbS3:
181         .word   .LinitendS3-.LinitsccbS3
182         .byte   0,0,0,0
183         .word   0
184         .word   0
185         .word   4
186 .LinitmaskS3:
187         .long   0x80000000
188         .long   0x40000000
189         .long   0
190         .long   0
191 .LinitendS3:
192
193 #
194 # Subroutine which prints a given text to the SCLP console.
195 #
196 # Parameters:
197 #   R2  = address of nil-terminated ASCII text
198 #
199 # Returns:
200 #   R2  = 0 on success, 1 on failure
201 #
202
203 _sclp_print:
204         stm     %r6,%r15,24(%r15)               # save registers
205         ahi     %r15,-96                        # create stack frame
206         basr    %r13,0                          # get base register
207 .LbaseS4:
208         l       %r8,.LsccbS0-.LbaseS4(%r13)     # prepare write data sccb
209         mvc     0(.LmtoS4-.LwritesccbS4,%r8),.LwritesccbS4-.LbaseS4(%r13)
210         la      %r7,.LmtoS4-.LwritesccbS4(%r8)  # current mto addr
211         sr      %r0,%r0
212         l       %r10,.Lascebc-.LbaseS4(%r13)    # address of translation table
213 .LinitmtoS4:
214         # initialize mto
215         mvc     0(.LmtoendS4-.LmtoS4,%r7),.LmtoS4-.LbaseS4(%r13)
216         lhi     %r6,.LmtoendS4-.LmtoS4          # current mto length
217 .LloopS4:
218         ic      %r0,0(%r2)                      # get character
219         ahi     %r2,1
220         ltr     %r0,%r0                         # end of string?
221         jz      .LfinalizemtoS4
222         chi     %r0,0x15                        # end of line (NL)?
223         jz      .LfinalizemtoS4
224         stc     %r0,0(%r6,%r7)                  # copy to mto
225         la      %r11,0(%r6,%r7)
226         tr      0(1,%r11),0(%r10)               # translate to EBCDIC
227         ahi     %r6,1
228         j       .LloopS4
229 .LfinalizemtoS4:
230         sth     %r6,0(%r7)                      # update mto length
231         lh      %r9,.LmdbS4-.LwritesccbS4(%r8)  # update mdb length
232         ar      %r9,%r6
233         sth     %r9,.LmdbS4-.LwritesccbS4(%r8)
234         lh      %r9,.LevbufS4-.LwritesccbS4(%r8)# update evbuf length
235         ar      %r9,%r6
236         sth     %r9,.LevbufS4-.LwritesccbS4(%r8)
237         lh      %r9,0(%r8)                      # update sccb length
238         ar      %r9,%r6
239         sth     %r9,0(%r8)
240         ar      %r7,%r6                         # update current mto address
241         ltr     %r0,%r0                         # more characters?
242         jnz     .LinitmtoS4
243         l       %r2,.LwritedataS4-.LbaseS4(%r13)# write data
244         lr      %r3,%r8
245         bras    %r14,_sclp_servc
246         ltr     %r2,%r2                         # servc successful?
247         jnz     .LendS4
248         chi     %r3,0x20                        # write data successful?
249         je      .LendS4
250         lhi     %r2,1                           # error return code
251 .LendS4:
252         lm      %r6,%r15,120(%r15)              # restore registers
253         br      %r14
254
255 #
256 # Function which prints a given text to the SCLP console.
257 #
258 # Parameters:
259 #   R2  = address of nil-terminated ASCII text
260 #
261 # Returns:
262 #   R2  = 0 on success, 1 on failure
263 #
264
265 ENTRY(_sclp_print_early)
266         stm     %r6,%r15,24(%r15)               # save registers
267         ahi     %r15,-96                        # create stack frame
268 #ifdef CONFIG_64BIT
269         tm      LC_AR_MODE_ID,1
270         jno     .Lesa2
271         ahi     %r15,-80
272         stmh    %r6,%r15,96(%r15)               # store upper register halves
273 .Lesa2:
274 #endif
275         lr      %r10,%r2                        # save string pointer
276         lhi     %r2,0
277         bras    %r14,_sclp_setup                # enable console
278         ltr     %r2,%r2
279         jnz     .LendS5
280         lr      %r2,%r10
281         bras    %r14,_sclp_print                # print string
282         ltr     %r2,%r2
283         jnz     .LendS5
284         lhi     %r2,1
285         bras    %r14,_sclp_setup                # disable console
286 .LendS5:
287 #ifdef CONFIG_64BIT
288         tm      LC_AR_MODE_ID,1
289         jno     .Lesa3
290         lmh     %r6,%r15,96(%r15)               # store upper register halves
291         ahi     %r15,80
292 .Lesa3:
293 #endif
294         lm      %r6,%r15,120(%r15)              # restore registers
295         br      %r14
296
297 .LwritedataS4:
298         .long   0x00760005                      # SCLP command for write data
299 .LwritesccbS4:
300         # sccb
301         .word   .LmtoS4-.LwritesccbS4
302         .byte   0
303         .byte   0,0,0
304         .word   0
305
306         # evbuf
307 .LevbufS4:
308         .word   .LmtoS4-.LevbufS4
309         .byte   0x02
310         .byte   0
311         .word   0
312
313 .LmdbS4:
314         # mdb
315         .word   .LmtoS4-.LmdbS4
316         .word   1
317         .long   0xd4c4c240
318         .long   1
319
320         # go
321 .LgoS4:
322         .word   .LmtoS4-.LgoS4
323         .word   1
324         .long   0
325         .byte   0,0,0,0,0,0,0,0
326         .byte   0,0,0
327         .byte   0
328         .byte   0,0,0,0,0,0,0
329         .byte   0
330         .word   0
331         .byte   0,0,0,0,0,0,0,0,0,0
332         .byte   0,0,0,0,0,0,0,0
333         .byte   0,0,0,0,0,0,0,0
334
335 .LmtoS4:
336         .word   .LmtoendS4-.LmtoS4
337         .word   4
338         .word   0x1000
339         .byte   0
340         .byte   0,0,0
341 .LmtoendS4:
342
343         # Global constants
344 .LsccbS0:
345         .long   _sclp_work_area
346 .Lascebc:
347         .long   _ascebc
348
349 .section .data,"aw",@progbits
350         .balign 4096
351 _sclp_work_area:
352         .fill   4096
353 .previous