xref: /netbsd/sys/arch/i386/stand/lib/bios_pci.S (revision bf9ec67e)
1/*	$NetBSD: bios_pci.S,v 1.3 1997/08/18 22:44:01 hannken Exp $	*/
2
3/*
4 * Copyright (c) 1996
5 *	Matthias Drochner.  All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 *    notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 *    notice, this list of conditions and the following disclaimer in the
14 *    documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 *    must display the following acknowledgement:
17 *	This product includes software developed for the NetBSD Project
18 *	by Matthias Drochner.
19 * 4. The name of the author may not be used to endorse or promote products
20 *    derived from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 */
34
35/* minimal calls to PCI BIOS */
36
37#include <machine/asm.h>
38
39#define	addr32	.byte 0x67
40#define	data32	.byte 0x66
41
42#define PCI_FUNCTION_ID 0xb1
43#define PCI_BIOS_PRESENT 0x01
44#define FIND_PCI_DEVICE 0x02
45#define READ_CONFIG_DWORD 0x0a
46#define WRITE_CONFIG_DWORD 0x0d
47
48/* int pcibios_present(int *signature)
49    return: AX from BIOS call, -1 on error
50    var param: EDX from BIOS call, must be signature "PCI "
51*/
52ENTRY(pcibios_present)
53	pushl	%ebp
54	movl	%esp, %ebp
55	pushl	%ebx
56	pushl	%ecx
57	pushl	%edx
58
59	call	_C_LABEL(prot_to_real)	# enter real mode
60
61	movb	$PCI_FUNCTION_ID, %ah
62	movb	$PCI_BIOS_PRESENT, %al
63	int	$0x1a
64
65	jnc	ok1
66	data32
67	movl	$-1, %ebx
68	jmp err1
69
70ok1:
71	data32
72	movl	$0,%ebx
73	mov	%eax, %ebx		# !!! at run time, it is mov %ax,%bx
74err1:
75	data32
76	call	_C_LABEL(real_to_prot) # back to protected mode
77
78	movl	8(%ebp), %eax
79	movl	%edx, (%eax)
80
81	movl	%ebx, %eax		# return value in %eax
82
83	popl	%edx
84	popl	%ecx
85	popl	%ebx
86	popl	%ebp
87	ret
88
89/* int pcibios_finddev(int vendor, int device, int index, int *busdevfcn)
90    return: AH from BIOS call, -1 on error
91    var param: BX from BIOS call, contains bus/device/function
92*/
93ENTRY(pcibios_finddev)
94	pushl	%ebp
95	movl	%esp, %ebp
96	pushl	%ebx
97	pushl	%ecx
98	pushl	%edx
99	pushl	%esi
100
101	movl	8(%ebp), %edx
102	movl	12(%ebp), %ecx
103	movl	16(%ebp), %esi
104
105	call	_C_LABEL(prot_to_real)	# enter real mode
106
107	movb	$PCI_FUNCTION_ID, %ah
108	movb	$FIND_PCI_DEVICE, %al
109	int	$0x1a
110
111	jnc	ok2
112	data32
113	movl	$-1, %edx
114	jmp err2
115
116ok2:
117	data32
118	movl	$0,%edx
119	movb	%ah, %dl
120err2:
121	data32
122	call	_C_LABEL(real_to_prot) # back to protected mode
123
124	movl	20(%ebp), %eax
125	mov	%bx, (%eax)
126
127	movl	%edx, %eax		# return value in %eax
128
129	popl	%esi
130	popl	%edx
131	popl	%ecx
132	popl	%ebx
133	popl	%ebp
134	ret
135
136/* int pcibios_cfgread(int busdevfcn, int offset, int *value)
137    return: AH from BIOS call, -1 on error
138    var param: ECX from BIOS call, contains value read
139*/
140ENTRY(pcibios_cfgread)
141	pushl	%ebp
142	movl	%esp, %ebp
143	pushl	%ebx
144	pushl	%ecx
145	pushl	%edx
146	pushl	%edi
147
148	movl	8(%ebp), %ebx
149	movl	12(%ebp), %edi
150
151	call	_C_LABEL(prot_to_real)	# enter real mode
152
153	movb	$PCI_FUNCTION_ID, %ah
154	movb	$READ_CONFIG_DWORD, %al
155	int	$0x1a
156
157	jnc	ok3
158	data32
159	movl	$-1, %edx
160	jmp err3
161
162ok3:
163	data32
164	movl	$0,%edx
165	movb	%ah, %dl
166err3:
167	data32
168	call	_C_LABEL(real_to_prot) # back to protected mode
169
170	movl	16(%ebp), %eax
171	movl	%ecx, (%eax)
172
173	movl	%edx, %eax		# return value in %eax
174
175	popl	%edi
176	popl	%edx
177	popl	%ecx
178	popl	%ebx
179	popl	%ebp
180	ret
181
182/* int pcibios_cfgwrite(int busdevfcn, int offset, int value)
183    return: AH from BIOS call, -1 on error
184    var param: ECX from BIOS call, contains value read
185*/
186ENTRY(pcibios_cfgwrite)
187	pushl	%ebp
188	movl	%esp, %ebp
189	pushl	%ebx
190	pushl	%ecx
191	pushl	%edx
192	pushl	%edi
193
194	movl	8(%ebp), %ebx
195	movl	12(%ebp), %edi
196	movl	16(%ebp), %ecx
197
198	call	_C_LABEL(prot_to_real)	# enter real mode
199
200	movb	$PCI_FUNCTION_ID, %ah
201	movb	$WRITE_CONFIG_DWORD, %al
202	int	$0x1a
203
204	jnc	ok4
205	data32
206	movl	$-1, %edx
207	jmp err4
208
209ok4:
210	data32
211	movl	$0,%edx
212	movb	%ah, %dl
213err4:
214	data32
215	call	_C_LABEL(real_to_prot) # back to protected mode
216
217	movl	%edx, %eax		# return value in %eax
218
219	popl	%edi
220	popl	%edx
221	popl	%ecx
222	popl	%ebx
223	popl	%ebp
224	ret
225