From 86c9e3468ec223fb492798f5ff651f419797e45b Mon Sep 17 00:00:00 2001 From: Daniil Tatianin <99danilt@gmail.com> Date: Thu, 26 Dec 2024 13:54:07 +0300 Subject: [PATCH 1/3] Introduce status.h --- status.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 status.h 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 From c4f13753bdf137260cd122950df40bf488eb6061 Mon Sep 17 00:00:00 2001 From: Daniil Tatianin <99danilt@gmail.com> Date: Thu, 26 Dec 2024 13:54:35 +0300 Subject: [PATCH 2/3] Introduce types.h This will contain generic types that are not platform specific. --- types.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 types.h 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 From a8c4ec25047d50249ee1dc07abb004b2f5f690a8 Mon Sep 17 00:00:00 2001 From: Daniil Tatianin <99danilt@gmail.com> Date: Thu, 26 Dec 2024 13:55:12 +0300 Subject: [PATCH 3/3] Introduce pci.h --- pci.h | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 pci.h 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