Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
triazo
/
kernel
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
3
Merge Requests
0
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
52744cce
authored
Nov 05, 2015
by
triazo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add more useful output for pci enumeration
parent
6a365bd5
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
17 deletions
src/pci.c
src/pci.h
src/pci.c
View file @
52744cce
...
@@ -7,7 +7,7 @@
...
@@ -7,7 +7,7 @@
#include "serial.h"
#include "serial.h"
// reads a word from the io port using the pci addressing scheme
// reads a word from the io port using the pci addressing scheme
uint
16
_t
pciConfigReadWord
(
uint8_t
bus
,
uint8_t
slot
,
uint8_t
func
,
uint8_t
offset
)
uint
32
_t
pciConfigReadWord
(
uint8_t
bus
,
uint8_t
slot
,
uint8_t
func
,
uint8_t
offset
)
{
{
uint32_t
address
;
uint32_t
address
;
uint32_t
lbus
=
(
uint32_t
)
bus
;
uint32_t
lbus
=
(
uint32_t
)
bus
;
...
@@ -19,10 +19,25 @@ uint16_t pciConfigReadWord(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offs
...
@@ -19,10 +19,25 @@ uint16_t pciConfigReadWord(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offs
(
lfunc
<<
8
)
|
(
lfunc
<<
8
)
|
(
offset
&
0xfc
)
|
(
offset
&
0xfc
)
|
((
uint32_t
)
0x80000000
));
((
uint32_t
)
0x80000000
));
outl
(
PCI_CONFIG_
OUT
,
address
);
outl
(
PCI_CONFIG_
ACCESS
,
address
);
// return the contents of the address clipped
// return the contents of the address clipped
return
(
uint16_t
)((
inl
(
0xCFC
)
>>
((
offset
&
2
)
*
8
))
&
0xffff
);
uint32_t
data
=
inl
(
PCI_CONFIG_DATA
);
if
(
data
!=
-
1
)
{
serial_writestring
(
"address 0x"
);
serial_hexword
(
address
);
serial_writestring
(
" returned 0x"
);
serial_hexword
(
data
);
serial_writestring
(
" on bus "
);
serial_hexbyte
(
bus
);
serial_writestring
(
" device "
);
serial_hexbyte
(
slot
);
serial_writestring
(
" function "
);
serial_hexbyte
(
func
);
serial_writechar
(
'\n'
);
}
return
data
;
}
}
// Check function also prints out stuff
// Check function also prints out stuff
...
@@ -34,13 +49,7 @@ void checkFunction(uint8_t bus, uint8_t device, uint8_t function) {
...
@@ -34,13 +49,7 @@ void checkFunction(uint8_t bus, uint8_t device, uint8_t function) {
// Print out information about the device
// Print out information about the device
serial_writestring
(
"0x"
);
serial_writestring
(
"0x"
);
serial_hexhword
(
class
);
serial_hexhword
(
class
);
serial_writestring
(
" on bus "
);
serial_hexbyte
(
bus
);
serial_writestring
(
" device "
);
serial_hexbyte
(
bus
);
serial_writestring
(
" function "
);
serial_hexbyte
(
function
);
serial_writestring
(
"
\n
"
);
}
}
void
checkDevice
(
uint8_t
bus
,
uint8_t
device
)
void
checkDevice
(
uint8_t
bus
,
uint8_t
device
)
...
@@ -55,12 +64,16 @@ void checkDevice(uint8_t bus, uint8_t device)
...
@@ -55,12 +64,16 @@ void checkDevice(uint8_t bus, uint8_t device)
checkFunction
(
bus
,
device
,
function
);
checkFunction
(
bus
,
device
,
function
);
uint8_t
headerType
=
(
pciConfigReadWord
(
bus
,
device
,
function
,
0x0C
)
&
0xff00
)
>>
8
;
uint8_t
headerType
=
(
pciConfigReadWord
(
bus
,
device
,
function
,
0x0C
)
&
0xff00
)
>>
8
;
/* serial_writestring("Header type: "); */
/* serial_hexhword(pciConfigReadWord(bus, device, function, 0x0C)); */
/* serial_writestring("\n"); */
if
(
(
headerType
&
0x80
)
!=
0
)
if
(
(
headerType
&
0x80
)
!=
0
)
{
{
// It is a multi-function device, so check remaining functions
// It is a multi-function device, so check remaining functions
for
(
function
=
1
;
function
<
8
;
function
++
)
for
(
function
=
0
;
function
<
8
;
function
++
)
{
{
if
(
pciConfigReadWord
(
bus
,
device
,
function
,
2
)
!=
0xFFFF
)
serial_writestring
(
"found a function
\n
"
);
if
(
pciConfigReadWord
(
bus
,
device
,
function
,
0
)
!=
0x0000FFFF
)
{
{
checkFunction
(
bus
,
device
,
function
);
checkFunction
(
bus
,
device
,
function
);
}
}
...
@@ -71,14 +84,24 @@ void checkDevice(uint8_t bus, uint8_t device)
...
@@ -71,14 +84,24 @@ void checkDevice(uint8_t bus, uint8_t device)
void
checkAllBuses
(
void
)
void
checkAllBuses
(
void
)
{
{
serial_writestring
(
"Enumerating PCI busses
\n
"
);
uint8_t
bus
;
uint8_t
bus
;
uint8_t
device
;
uint8_t
device
;
uint8_t
function
;
for
(
bus
=
0
;
bus
<
255
;
bus
++
)
for
(
bus
=
0
;
bus
<
255
;
bus
++
)
{
{
for
(
device
=
0
;
device
<
32
;
device
++
)
for
(
device
=
0
;
device
<
32
;
device
++
)
{
{
checkDevice
(
bus
,
device
);
for
(
function
=
0
;
function
<
8
;
function
++
)
{
if
(
pciConfigReadWord
(
bus
,
device
,
function
,
0
)
!=
0xffffffff
)
{
serial_writestring
(
"- - - - - - - - - - - - - - - - - - - -
\n
"
);
pciConfigReadWord
(
bus
,
device
,
function
,
8
);
serial_writestring
(
"=======================================
\n
"
);
}
}
}
}
}
}
}
}
src/pci.h
View file @
52744cce
...
@@ -9,12 +9,11 @@
...
@@ -9,12 +9,11 @@
#include "asm.h"
#include "asm.h"
#define PCI_CONFIG_
OUT
0xCF8
#define PCI_CONFIG_
ACCESS
0xCF8
#define PCI_CONFIG_
IN 0xCF8
#define PCI_CONFIG_
DATA 0xCFC
uint
16
_t
pciConfigReadWord
(
uint8_t
bus
,
uint8_t
slot
,
uint8_t
func
,
uint8_t
offset
);
uint
32
_t
pciConfigReadWord
(
uint8_t
bus
,
uint8_t
slot
,
uint8_t
func
,
uint8_t
offset
);
uint16_t
pciCheckVendor
(
uint8_t
bus
,
uint8_t
slot
);
void
checkAllBuses
(
void
);
void
checkAllBuses
(
void
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment