Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions pci.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#ifndef UAPI_PCI_VERSION
#define UAPI_PCI_VERSION 1
#endif

#if UAPI_PCI_VERSION != 1
#error pci.h API version mismatch, make sure all uDrivers are using the same base
#endif

#ifndef UAPI_PCI_INCLUDED
#define UAPI_PCI_INCLUDED

#ifndef UAPI_KERNEL_API
#error this header should not be included directly, use kernel_api.h
#endif

#ifndef UAPI_WANTS_PCI
#error pci.h is not used by any of the included uDrivers and should not be included
#endif

#include "platform/types.h"
#include "platform/compiler.h"
#include "types.h"

UAPI_BEGIN_DECLS

/*
* Open a PCI device at 'address'. The returned 'out_handle' may be used for
* all compiled-in uAPI PCI functions.
*/
uapi_status uapi_pci_device_open(
uapi_pci_address *address, uapi_handle *out_handle
);

/*
* Read & write PCI configuration space for a previously open PCI device handle.
*
* NOTE:
* 'byte_width' is ALWAYS one of 1, 2, 4. Since PCI registers are 32 bits wide
* this must be able to handle e.g. a 1-byte access by reading at the nearest
* 4-byte aligned offset below, then masking the value to select the target
* byte.
*/
uapi_status uapi_kernel_pci_cfg_read(
uapi_handle, uapi_size offset, uapi_u8 byte_width, uapi_u64 *value
);
uapi_status uapi_kernel_pci_cfg_write(
uapi_handle, uapi_size offset, uapi_u8 byte_width, uapi_u64 value
);

UAPI_END_DECLS

#endif
36 changes: 36 additions & 0 deletions status.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#ifndef UAPI_STATUS_VERSION
#define UAPI_STATUS_VERSION 1
#endif

#if UAPI_STATUS_VERSION != 1
#error status.h API version mismatch, make sure all uDrivers are using the same base
#endif

#ifndef UAPI_STATUS_INCLUDED
#define UAPI_STATUS_INCLUDED

#include "platform/types.h"
#include "platform/compiler.h"

UAPI_BEGIN_DECLS

#ifndef UAPI_STATUS_BASE
#define UAPI_STATUS_BASE 0
#endif

typedef enum uapi_status {
UAPI_STATUS_OK = UAPI_STATUS_BASE,
UAPI_STATUS_MAPPING_FAILED,
UAPI_STATUS_OUT_OF_MEMORY,
UAPI_STATUS_BAD_CHECKSUM,
UAPI_STATUS_NOT_FOUND,
UAPI_STATUS_INVALID_ARGUMENT,
UAPI_STATUS_UNIMPLEMENTED,
UAPI_STATUS_ALREADY_EXISTS,
UAPI_STATUS_INTERNAL_ERROR,
UAPI_STATUS_TIMEOUT,
} uapi_status;

UAPI_END_DECLS

#endif
28 changes: 28 additions & 0 deletions types.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef UAPI_TYPES_VERSION
#define UAPI_TYPES_VERSION 1
#endif

#if UAPI_TYPES_VERSION != 1
#error types.h API version mismatch, make sure all uDrivers are using the same base
#endif

#ifndef UAPI_TYPES_INCLUDED
#define UAPI_TYPES_INCLUDED

#include "platform/types.h"
#include "platform/compiler.h"

UAPI_BEGIN_DECLS

typedef void *uapi_handle;

typedef struct uapi_pci_address {
uapi_u16 segment;
uapi_u8 bus;
uapi_u8 device;
uapi_u8 function;
} uapi_pci_address;

UAPI_END_DECLS

#endif