Skip to content

Commit

Permalink
Merge pull request #84 from bassaer/mouse
Browse files Browse the repository at this point in the history
fix class code
  • Loading branch information
bassaer committed Mar 20, 2022
2 parents 4013e27 + 8d571af commit 12daab2
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

## ver 2.1.1
- fix class code

## ver 2.1.0
- find PCI devices

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ run: img
qemu-system-x86_64 -name myos \
-monitor stdio \
-bios /usr/share/ovmf/OVMF.fd \
-net none \
-drive format=raw,file=$(IMG) \
-device nec-usb-xhci,id=xhci \
-device usb-mouse \
-device usb-kbd \
-d guest_errors \
|| true


usb: arch/x86/BOOTX64.EFI kernel/vmmyos
sudo mount /dev/sda /mnt
sudo rm -rf /mnt/EFI
Expand Down
32 changes: 20 additions & 12 deletions drivers/xhci.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ UINT8 read_header_type(UINT8 bus, UINT8 device, UINT8 function) {
void read_class_code(UINT8 bus, UINT8 device, UINT8 function, class_code_t* class_code) {
set_config_address(build_address(bus, device, function, 0x08));
UINT32 data = read_data();
class_code->base = (data >> 24) && 0xFFU;
class_code->sub = (data >> 16) && 0xFFU;
class_code->interface = (data >> 8) && 0xFFU;
class_code->base = (data >> 24) & 0xFFU;
class_code->sub = (data >> 16) & 0xFFU;
class_code->interface = (data >> 8) & 0xFFU;
}

UINT32 read_bus_number(UINT8 bus, UINT8 device, UINT8 function) {
Expand Down Expand Up @@ -91,7 +91,7 @@ STATUS find_function(UINT8 bus, UINT8 device) {
}

STATUS find_device(UINT8 bus) {
for (UINT8 device = 0; device < 32; ++device) {
for (UINT8 device = 0; device < MAX_PCI_DEVICE_NUM; ++device) {
if (get_vendor_id(bus, device, 0) == INVALID_ID) {
continue;
}
Expand All @@ -112,7 +112,7 @@ STATUS find_all_device() {
if (is_single_function(header_type)) {
return find_device(0);
}
for (UINT8 function = 0; function < 8; ++function) {
for (UINT8 function = 0; function < MAX_FUNCTION_NUM; ++function) {
if (get_vendor_id(0, 0, function) == INVALID_ID) {
continue;
}
Expand All @@ -124,20 +124,28 @@ STATUS find_all_device() {
return OK;
}

bool is_xhci(class_code_t* code) {
return code->base == 0x0CU && code->sub == 0x03U && code->interface == 0x30U;
}

void init_xhci() {
STATUS status = find_all_device();
int y = 0;
STATUS status = find_all_device();
printf(0, y, "init xhci => %d\n", status);
y += 20;
if (status != OK) {
return;
}
device_t* xhc_device = NULL;
for(int i = 0; i < device_num; i++) {
device_t device = device_list[i];
UINT16 vendor_id = get_vendor_id(device.bus, device.device, device.function);
class_code_t class_code;
read_class_code(device.bus, device.device, device.function, &class_code);
printf(0, y, "bus: %d, device: %d, func: %d, vendor_id: %x, header: %x\n", device.bus, device.device, device.function, vendor_id, device.header_type);
if (is_xhci(&device.class_code)) {
printf(0, y, "bus: %d, device: %d, func: %d, base: %x, sub: %x, interface: %x, vendor_id: %x, header: %x\n",
device.bus, device.device, device.function, device.class_code.base, device.class_code.sub, device.class_code.interface, vendor_id, device.header_type);
xhc_device = &device;
y += 20;
}
}
if (xhc_device == NULL) {
printf(0, y, "not found\n");
y += 20;
}
printf(0, y, "done xhci\n", status);
Expand Down
4 changes: 3 additions & 1 deletion include/drivers/xhci.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

typedef int STATUS;

#define DEVICE_SIZE 32
#define DEVICE_SIZE 64
#define MAX_PCI_DEVICE_NUM 32
#define MAX_FUNCTION_NUM 8
#define CONVERT_STATUS(code) ((STATUS)code)
#define OK CONVERT_STATUS(0)
#define ERROR CONVERT_STATUS(1)
Expand Down

0 comments on commit 12daab2

Please sign in to comment.