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
acf84412
authored
Nov 09, 2015
by
triazo
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add function to detect ahci bridge
parent
82512f3e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
51 additions
and
1 deletions
src/kern.c
src/pci.c
src/pci.h
src/kern.c
View file @
acf84412
...
...
@@ -67,10 +67,12 @@ void kernel_main(multiboot_info* mbt, uint32_t magic)
// PCI
checkAllBuses
();
void
*
ahciAddr
=
pciFindAHCI
();
serial_hexstring
(
ahciAddr
,
0x1100
);
test_idt
();
while
(
true
)
{
asm
(
"hlt"
);
asm
(
"hlt"
);
}
}
src/pci.c
View file @
acf84412
...
...
@@ -80,3 +80,50 @@ void checkAllBuses(void)
}
}
}
// pciFindAHCI enumerates the pci bus to find the AHCI controller
void
*
pciFindAHCI
()
{
uint8_t
bus
;
uint8_t
device
;
uint8_t
function
;
void
*
baseAddr
=
0
;
for
(
bus
=
0
;
bus
<
255
;
bus
++
)
{
for
(
device
=
0
;
device
<
32
;
device
++
)
{
for
(
function
=
0
;
function
<
8
;
function
++
)
{
uint16_t
classID
=
pciConfigReadWord
(
bus
,
device
,
function
,
8
)
>>
16
;
if
(
classID
!=
0xffff
)
{
serial_hexhword
(
classID
);
serial_writechar
(
'\n'
);
}
// This class ID is for any
if
(
classID
==
0x0106
)
{
if
(
baseAddr
!=
0
)
{
serial_writestring
(
"Found too many SATA devices!
\n
"
);
return
baseAddr
;
}
serial_writestring
(
"Found AHCI address
\n
"
);
pciSerialInfo
(
bus
,
device
,
function
,
0
);
pciSerialInfo
(
bus
,
device
,
function
,
8
);
serial_writestring
(
"AHCI Base address: 0x"
);
baseAddr
=
(
void
*
)
pciConfigReadWord
(
bus
,
device
,
function
,
0x24
);
serial_hexword
((
uint32_t
)
baseAddr
);
serial_writechar
(
'\n'
);
}
}
}
}
if
(
baseAddr
==
0
)
{
serial_writestring
(
"Could not find an ahci device
\n
"
);
}
return
baseAddr
;
}
src/pci.h
View file @
acf84412
...
...
@@ -16,5 +16,6 @@ uint32_t pciConfigReadWord(uint8_t bus, uint8_t slot, uint8_t func, uint8_t offs
void
checkAllBuses
();
void
*
pciFindAHCI
();
#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