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
2f26b3df
authored
Nov 02, 2015
by
triazo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add Pci enumeration files
parent
3347f002
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
0 deletions
src/pci.c
src/pci.h
src/pci.c
0 → 100644
View file @
2f26b3df
// pci.c
//
// Contains implementations of the functions for dealing with PCI
// defined in pci.h
#include "pci.h"
#include "serial.h"
// reads a word from the io port using the pci addressing scheme
uint16_t
pciConfigReadWord
(
uint8_t
bus
,
uint8_t
slot
,
uint8_t
func
,
uint8_t
offset
)
{
uint32_t
address
;
uint32_t
lbus
=
(
uint32_t
)
bus
;
uint32_t
lslot
=
(
uint32_t
)
slot
;
uint32_t
lfunc
=
(
uint32_t
)
func
;
address
=
(
uint32_t
)((
lbus
<<
16
)
|
(
lslot
<<
11
)
|
(
lfunc
<<
8
)
|
(
offset
&
0xfc
)
|
((
uint32_t
)
0x80000000
));
outl
(
PCI_CONFIG_OUT
,
address
);
// return the contents of the address clipped
return
(
uint16_t
)((
inl
(
0xCFC
)
>>
((
offset
&
2
)
*
8
))
&
0xffff
);
}
// Check function also prints out stuff
void
checkFunction
(
uint8_t
bus
,
uint8_t
device
,
uint8_t
function
)
{
uint16_t
class
;
class
=
pciConfigReadWord
(
bus
,
device
,
function
,
0x08
);
// Print out information about the device
serial_writestring
(
"0x"
);
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
)
{
uint8_t
function
=
0
;
uint16_t
vendorID
=
pciConfigReadWord
(
bus
,
device
,
function
,
2
);
if
(
vendorID
==
0xFFFF
)
{
return
;
}
checkFunction
(
bus
,
device
,
function
);
uint8_t
headerType
=
(
pciConfigReadWord
(
bus
,
device
,
function
,
0x0C
)
&
0xff00
)
>>
8
;
if
(
(
headerType
&
0x80
)
!=
0
)
{
// It is a multi-function device, so check remaining functions
for
(
function
=
1
;
function
<
8
;
function
++
)
{
if
(
pciConfigReadWord
(
bus
,
device
,
function
,
2
)
!=
0xFFFF
)
{
checkFunction
(
bus
,
device
,
function
);
}
}
}
}
void
checkAllBuses
(
void
)
{
uint8_t
bus
;
uint8_t
device
;
for
(
bus
=
0
;
bus
<
255
;
bus
++
)
{
for
(
device
=
0
;
device
<
32
;
device
++
)
{
checkDevice
(
bus
,
device
);
}
}
}
src/pci.h
0 → 100644
View file @
2f26b3df
// pci.h
//
// Contains headers for functions related to dealivg with PCI
#ifndef _PCI_INC
#define _PCI_INC
#include <stdint.h>
#include "asm.h"
#define PCI_CONFIG_OUT 0xCF8
#define PCI_CONFIG_IN 0xCF8
uint16_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
);
#endif
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