diff --git a/pci.h b/pci.h new file mode 100644 index 0000000..95beb21 --- /dev/null +++ b/pci.h @@ -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 diff --git a/status.h b/status.h new file mode 100644 index 0000000..ebb524c --- /dev/null +++ b/status.h @@ -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 diff --git a/types.h b/types.h new file mode 100644 index 0000000..3724883 --- /dev/null +++ b/types.h @@ -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