iPXE
pcibios.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26#include <stdint.h>
27#include <ipxe/pci.h>
28#include <realmode.h>
29
30/** @file
31 *
32 * PCI configuration space access via PCI BIOS
33 *
34 */
35
36/**
37 * Find next PCI bus:dev.fn address range in system
38 *
39 * @v busdevfn Starting PCI bus:dev.fn address
40 * @v range PCI bus:dev.fn address range to fill in
41 */
43 struct pci_range *range ) {
44 int discard_a, discard_D;
45 uint16_t num_bus;
46
47 /* We issue this call using flat real mode, to work around a
48 * bug in some HP BIOSes.
49 */
50 __asm__ __volatile__ ( REAL_CODE ( "call flatten_real_mode\n\t"
51 "stc\n\t"
52 "int $0x1a\n\t"
53 "movzbw %%cl, %%cx\n\t"
54 "incw %%cx\n\t"
55 "jnc 1f\n\t"
56 "xorw %%cx, %%cx\n\t"
57 "\n1:\n\t" )
58 : "=c" ( num_bus ), "=a" ( discard_a ),
59 "=D" ( discard_D )
60 : "a" ( PCIBIOS_INSTALLATION_CHECK >> 16 ),
61 "D" ( 0 )
62 : "ebx", "edx" );
63
64 /* Populate range */
65 range->start = PCI_BUSDEVFN ( 0, 0, 0, 0 );
66 range->count = PCI_BUSDEVFN ( 0, num_bus, 0, 0 );
67}
68
69/**
70 * Read configuration space via PCI BIOS
71 *
72 * @v pci PCI device
73 * @v command PCI BIOS command
74 * @v value Value read
75 * @ret rc Return status code
76 */
78 int discard_b, discard_D;
80
81 __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
82 "int $0x1a\n\t"
83 "jnc 1f\n\t"
84 "xorl %%eax, %%eax\n\t"
85 "decl %%eax\n\t"
86 "movl %%eax, %%ecx\n\t"
87 "\n1:\n\t" )
88 : "=a" ( status ), "=b" ( discard_b ),
89 "=c" ( *value ), "=D" ( discard_D )
90 : "a" ( command >> 16 ), "D" ( command ),
91 "b" ( pci->busdevfn )
92 : "edx" );
93
94 return ( status >> 8 );
95}
96
97/**
98 * Write configuration space via PCI BIOS
99 *
100 * @v pci PCI device
101 * @v command PCI BIOS command
102 * @v value Value to be written
103 * @ret rc Return status code
104 */
106 int discard_b, discard_c, discard_D;
108
109 __asm__ __volatile__ ( REAL_CODE ( "stc\n\t"
110 "int $0x1a\n\t"
111 "jnc 1f\n\t"
112 "movb $0xff, %%ah\n\t"
113 "\n1:\n\t" )
114 : "=a" ( status ), "=b" ( discard_b ),
115 "=c" ( discard_c ), "=D" ( discard_D )
116 : "a" ( command >> 16 ), "D" ( command ),
117 "b" ( pci->busdevfn ), "c" ( value )
118 : "edx" );
119
120 return ( status >> 8 );
121}
122
pseudo_bit_t value[0x00020]
Definition arbel.h:2
__asm__ __volatile__("call *%9" :"=a"(result), "=c"(discard_ecx), "=d"(discard_edx) :"d"(0), "a"(code), "b"(0), "c"(in_phys), "D"(0), "S"(out_phys), "m"(hypercall))
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
void * discard_D
Definition bigint.h:32
long discard_c
Definition bigint.h:33
uint8_t status
Status.
Definition ena.h:5
uint16_t busdevfn
PCI bus:dev.fn address.
Definition ena.h:17
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
int pci_can_probe(struct pci_device *pci)
Check if PCI bus probing is allowed.
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
int pci_read_config_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition pci_io.h:30
#define PROVIDE_PCIAPI_RUNTIME(subsys, priority)
Provide a runtime selectable PCI I/O API.
Definition pci_io.h:202
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
int pci_write_config_word(struct pci_device *pci, unsigned int where, uint16_t value)
Write 16-bit word to PCI configuration space.
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.
#define PCIAPI_PRIORITY_PCBIOS
PCI BIOS calls.
Definition pci_io.h:198
#define PROVIDE_PCIAPI(_subsys, _api_func, _func)
Provide a PCI I/O API implementation.
Definition pci_io.h:51
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
#define PROVIDE_PCIAPI_INLINE(_subsys, _api_func)
Provide a static inline PCI I/O API implementation.
Definition pci_io.h:60
#define REAL_CODE(asm_code_str)
Definition libkir.h:226
PCI bus.
int pcibios_write(struct pci_device *pci, uint32_t command, uint32_t value)
Write configuration space via PCI BIOS.
Definition pcibios.c:105
static void pcibios_discover(uint32_t busdevfn __unused, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
Definition pcibios.c:42
int pcibios_read(struct pci_device *pci, uint32_t command, uint32_t *value)
Read configuration space via PCI BIOS.
Definition pcibios.c:77
#define PCIBIOS_INSTALLATION_CHECK
Definition pcibios.h:23
struct pci_range range
PCI bus:dev.fn address range.
Definition pcicloud.c:40
__asm__(".section \".rodata\", \"a\", " PROGBITS "\n\t" "\nprivate_key_data:\n\t" ".size private_key_data, ( . - private_key_data )\n\t" ".equ private_key_len, ( . - private_key_data )\n\t" ".previous\n\t")
A command-line command.
Definition command.h:10
A PCI device.
Definition pci.h:211
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition pci.h:238
A PCI bus:dev.fn address range.
Definition pci_io.h:23