xref: /minix3/sys/arch/i386/stand/lib/bios_pci.S (revision 58a2b0008e28f606a7f7f5faaeaba4faac57a1ea)
1/*	$NetBSD: bios_pci.S,v 1.6 2005/12/11 12:17:48 christos 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 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29/* minimal calls to PCI BIOS */
30
31#include <machine/asm.h>
32
33#define	addr32	.byte 0x67
34#define	data32	.byte 0x66
35
36#define PCI_FUNCTION_ID 0xb1
37#define PCI_BIOS_PRESENT 0x01
38#define FIND_PCI_DEVICE 0x02
39#define READ_CONFIG_DWORD 0x0a
40#define WRITE_CONFIG_DWORD 0x0d
41
42/* int pcibios_present(int *signature)
43    return: AX from BIOS call, -1 on error
44    var param: EDX from BIOS call, must be signature "PCI "
45*/
46ENTRY(pcibios_present)
47	pushl	%ebp
48	movl	%esp, %ebp
49	pushl	%ebx
50	pushl	%ecx
51	pushl	%edx
52
53	call	_C_LABEL(prot_to_real)	# enter real mode
54	.code16
55
56	movb	$PCI_FUNCTION_ID, %ah
57	movb	$PCI_BIOS_PRESENT, %al
58	int	$0x1a
59
60	jnc	ok1
61	movl	$-1, %ebx
62	jmp err1
63
64ok1:
65	xorl	%ebx, %ebx
66	mov	%ax, %bx
67err1:
68	calll	_C_LABEL(real_to_prot) # back to protected mode
69	.code32
70
71	movl	8(%ebp), %eax
72	movl	%edx, (%eax)
73
74	movl	%ebx, %eax		# return value in %eax
75
76	popl	%edx
77	popl	%ecx
78	popl	%ebx
79	popl	%ebp
80	ret
81
82/* int pcibios_finddev(int vendor, int device, int index, int *busdevfcn)
83    return: AH from BIOS call, -1 on error
84    var param: BX from BIOS call, contains bus/device/function
85*/
86ENTRY(pcibios_finddev)
87	pushl	%ebp
88	movl	%esp, %ebp
89	pushl	%ebx
90	pushl	%ecx
91	pushl	%edx
92	pushl	%esi
93
94	movl	8(%ebp), %edx
95	movl	12(%ebp), %ecx
96	movl	16(%ebp), %esi
97
98	call	_C_LABEL(prot_to_real)	# enter real mode
99	.code16
100
101	movb	$PCI_FUNCTION_ID, %ah
102	movb	$FIND_PCI_DEVICE, %al
103	int	$0x1a
104
105	jnc	ok2
106	movl	$-1, %edx
107	jmp err2
108
109ok2:
110	movl	$0,%edx
111	movb	%ah, %dl
112err2:
113	calll	_C_LABEL(real_to_prot) # back to protected mode
114	.code32
115
116	movl	20(%ebp), %eax
117	mov	%bx, (%eax)
118
119	movl	%edx, %eax		# return value in %eax
120
121	popl	%esi
122	popl	%edx
123	popl	%ecx
124	popl	%ebx
125	popl	%ebp
126	ret
127
128/* int pcibios_cfgread(int busdevfcn, int offset, int *value)
129    return: AH from BIOS call, -1 on error
130    var param: ECX from BIOS call, contains value read
131*/
132ENTRY(pcibios_cfgread)
133	pushl	%ebp
134	movl	%esp, %ebp
135	pushl	%ebx
136	pushl	%ecx
137	pushl	%edx
138	pushl	%edi
139
140	movl	8(%ebp), %ebx
141	movl	12(%ebp), %edi
142
143	call	_C_LABEL(prot_to_real)	# enter real mode
144	.code16
145
146	movb	$PCI_FUNCTION_ID, %ah
147	movb	$READ_CONFIG_DWORD, %al
148	int	$0x1a
149
150	jnc	ok3
151	movl	$-1, %edx
152	jmp err3
153
154ok3:
155	movl	$0,%edx
156	movb	%ah, %dl
157err3:
158	calll	_C_LABEL(real_to_prot) # back to protected mode
159	.code32
160
161	movl	16(%ebp), %eax
162	movl	%ecx, (%eax)
163
164	movl	%edx, %eax		# return value in %eax
165
166	popl	%edi
167	popl	%edx
168	popl	%ecx
169	popl	%ebx
170	popl	%ebp
171	ret
172
173/* int pcibios_cfgwrite(int busdevfcn, int offset, int value)
174    return: AH from BIOS call, -1 on error
175    var param: ECX from BIOS call, contains value read
176*/
177ENTRY(pcibios_cfgwrite)
178	pushl	%ebp
179	movl	%esp, %ebp
180	pushl	%ebx
181	pushl	%ecx
182	pushl	%edx
183	pushl	%edi
184
185	movl	8(%ebp), %ebx
186	movl	12(%ebp), %edi
187	movl	16(%ebp), %ecx
188
189	call	_C_LABEL(prot_to_real)	# enter real mode
190	.code16
191
192	movb	$PCI_FUNCTION_ID, %ah
193	movb	$WRITE_CONFIG_DWORD, %al
194	int	$0x1a
195
196	jnc	ok4
197	movl	$-1, %edx
198	jmp err4
199
200ok4:
201	movl	$0,%edx
202	movb	%ah, %dl
203err4:
204	calll	_C_LABEL(real_to_prot) # back to protected mode
205	.code32
206
207	movl	%edx, %eax		# return value in %eax
208
209	popl	%edi
210	popl	%edx
211	popl	%ecx
212	popl	%ebx
213	popl	%ebp
214	ret
215