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 
24 FILE_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 
131 
132 struct pci_api pcibios_api = PCIAPI_RUNTIME ( pcbios );
uint32_t start
Starting bus:dev.fn address.
Definition: pci_io.h:23
unsigned short uint16_t
Definition: stdint.h:11
static __always_inline void struct pci_range * range
Definition: efi_pci_api.h:43
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
A command-line command.
Definition: command.h:9
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_word(struct pci_device *pci, unsigned int where, uint16_t *value)
Read 16-bit word from PCI configuration space.
struct pci_api pcibios_api
Definition: pcibios.c:132
uint8_t status
Status.
Definition: ena.h:16
uint16_t busdevfn
PCI bus:dev.fn address.
Definition: ena.h:28
int pci_read_config_dword(struct pci_device *pci, unsigned int where, uint32_t *value)
Read 32-bit dword from PCI configuration space.
#define PCIAPI_RUNTIME(_subsys)
Provide a runtime selectable PCI I/O API.
Definition: pci_io.h:167
A PCI bus:dev.fn address range.
Definition: pci_io.h:21
int pcibios_write(struct pci_device *pci, uint32_t command, uint32_t value)
Write configuration space via PCI BIOS.
Definition: pcibios.c:105
PROVIDE_PCIAPI(pcbios, pci_discover, pcibios_discover)
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
#define PCI_BUSDEVFN(segment, bus, slot, func)
Definition: pci_io.h:28
int pcibios_read(struct pci_device *pci, uint32_t command, uint32_t *value)
Read configuration space via PCI BIOS.
Definition: pcibios.c:77
int pci_write_config_byte(struct pci_device *pci, unsigned int where, uint8_t value)
Write byte to PCI configuration space.
#define PCIBIOS_INSTALLATION_CHECK
Definition: pcibios.h:22
PCI bus.
A PCI device.
Definition: pci.h:206
A runtime selectable PCI I/O API.
Definition: pci_io.h:154
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
__asm__ __volatile__("\n1:\n\t" "movb -1(%3,%1), %%al\n\t" "stosb\n\t" "loop 1b\n\t" "xorl %%eax, %%eax\n\t" "mov %4, %1\n\t" "rep stosb\n\t" :"=&D"(discard_D), "=&c"(discard_c), "+m"(*value) :"r"(data), "g"(pad_len), "0"(value0), "1"(len) :"eax")
void * discard_D
Definition: bigint.h:31
unsigned int uint32_t
Definition: stdint.h:12
unsigned int count
Number of bus:dev.fn addresses within this range.
Definition: pci_io.h:25
void pci_discover(uint32_t busdevfn, struct pci_range *range)
Find next PCI bus:dev.fn address range in system.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
uint32_t busdevfn
Segment, bus, device, and function (bus:dev.fn) number.
Definition: pci.h:231
__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")
int pci_write_config_dword(struct pci_device *pci, unsigned int where, uint32_t value)
Write 32-bit dword to PCI configuration space.
PROVIDE_PCIAPI_INLINE(pcbios, pci_read_config_byte)
long discard_c
Definition: bigint.h:32
void * pci_ioremap(struct pci_device *pci, unsigned long bus_addr, size_t len)
Map PCI bus address as an I/O address.
#define REAL_CODE(asm_code_str)
Definition: libkir.h:226
int pci_read_config_byte(struct pci_device *pci, unsigned int where, uint8_t *value)
Read byte from PCI configuration space.