Skip to content

Commit

Permalink
uapi: Fix PCI implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
marv7000 committed Dec 26, 2024
1 parent 781e8ef commit fe6a697
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
20 changes: 12 additions & 8 deletions include/menix/system/pci/pci.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ struct ATTR(packed) PciConfigSpace
// Represents a PCI(e) device.
struct PciDevice
{
volatile PciConfigSpace* config_space; // Configuration space address.
u8 function; // Function index of this device.
Device* dev; // Underlying device.
PciDriver* driver; // The driver managing this device.
usize variant_idx; // Index into a driver-defined structure array.
PciSlot* slot; // The slot this device is on.
union
{
mmio8* config_space_addr; // Configuration space address.
volatile PciConfigSpace* config_space;
};
u8 function; // Function index of this device.
Device* dev; // Underlying device.
PciDriver* driver; // The driver managing this device.
usize variant_idx; // Index into a driver-defined structure array.
PciSlot* slot; // The slot this device is on.
};

struct PciSlot
Expand Down Expand Up @@ -117,7 +121,7 @@ typedef struct
} PciVariant;

// A PCI(e) driver with callbacks.
typedef struct PciDriver
struct PciDriver
{
const char* name; // Name of the device.
const PciVariant* variants; // Array of device variants that the driver can match.
Expand All @@ -133,7 +137,7 @@ typedef struct PciDriver
i32 (*resume)(PciDevice* dev);
// Called to deinitialize a device during shutdown. (Optional).
void (*shutdown)(PciDevice* dev);
} PciDriver;
};

// Abstraction for PCI mechanisms. Can be e.g. x86 port IO or ACPI.
typedef struct
Expand Down
3 changes: 2 additions & 1 deletion kernel/system/uapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
target_sources(menix PUBLIC
pci.c
log.c
malloc.c
)

target_include_directories(menix PUBLIC .)
target_include_directories(menix PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
27 changes: 27 additions & 0 deletions kernel/system/uapi/malloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// uAPI malloc.h implementation

#include <menix/common.h>
#include <menix/util/log.h>

#include <uapi/status.h>
#include <uapi/types.h>

#define UAPI_KERNEL_API
#define UAPI_WANTS_MALLOC
#include <uapi/malloc.h>
#undef UAPI_KERNEL_API

void* uapi_kernel_alloc(uapi_size size)
{
return kmalloc(size);
}

void* uapi_kernel_calloc(uapi_size count, uapi_size size)
{
return kzalloc(count * size);
}

void uapi_kernel_free(void* mem)
{
kfree(mem);
}
12 changes: 6 additions & 6 deletions kernel/system/uapi/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ uapi_status uapi_kernel_pci_cfg_read(uapi_handle handle, uapi_size offset, uapi_
PciDevice* const device = handle;
switch (byte_width)
{
case sizeof(u8): mmio_read8(device->config_space + offset); break;
case sizeof(u16): mmio_read16(device->config_space + offset); break;
case sizeof(u32): mmio_read32(device->config_space + offset); break;
case sizeof(u8): *value = mmio_read8(device->config_space_addr + offset); break;
case sizeof(u16): *value = mmio_read16(device->config_space_addr + offset); break;
case sizeof(u32): *value = mmio_read32(device->config_space_addr + offset); break;
}
return UAPI_STATUS_OK;
}
Expand All @@ -29,9 +29,9 @@ uapi_status uapi_kernel_pci_cfg_write(uapi_handle handle, uapi_size offset, uapi
PciDevice* const device = handle;
switch (byte_width)
{
case sizeof(u8): mmio_write8(device->config_space + offset, value); break;
case sizeof(u16): mmio_write16(device->config_space + offset, value); break;
case sizeof(u32): mmio_write32(device->config_space + offset, value); break;
case sizeof(u8): mmio_write8(device->config_space_addr + offset, value); break;
case sizeof(u16): mmio_write16(device->config_space_addr + offset, value); break;
case sizeof(u32): mmio_write32(device->config_space_addr + offset, value); break;
}
return UAPI_STATUS_OK;
}
2 changes: 1 addition & 1 deletion kernel/system/uapi/uapi
Submodule uapi updated 1 files
+24 −0 utilities/pci.h

0 comments on commit fe6a697

Please sign in to comment.