-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit introduces the bulk of macOS support to libvfn. This has to be used together with MacVFN, which introduces a System Extension through DriverKit. Signed-off-by: Mads Ynddal <[email protected]>
- Loading branch information
Showing
16 changed files
with
489 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef LIBVFN_VFIO_H | ||
#define LIBVFN_VFIO_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <vfn/driverkit/device.h> | ||
#include <vfn/driverkit/pci.h> | ||
#include <vfn/iommu/dma.h> | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* LIBVFN_VFIO_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* SPDX-License-Identifier: LGPL-2.1-or-later or MIT */ | ||
|
||
/* | ||
* This file is part of libvfn. | ||
* | ||
* Copyright (C) 2022 The libvfn Authors. All Rights Reserved. | ||
* | ||
* This library (libvfn) is dual licensed under the GNU Lesser General | ||
* Public License version 2.1 or later or the MIT license. See the | ||
* COPYING and LICENSE files for more information. | ||
*/ | ||
|
||
#ifndef LIBVFN_DRIVERKIT_DEVICE_H | ||
#define LIBVFN_DRIVERKIT_DEVICE_H | ||
|
||
#include <DriverKit/OSCollection.h> | ||
#include <PCIDriverKit/PCIDriverKit.h> | ||
#include "iommu/context.h" | ||
|
||
struct driverkit_bar_info { | ||
uint8_t type; | ||
uint8_t memory_index; | ||
uint64_t size; | ||
}; | ||
|
||
struct driverkit_pci_device { | ||
IOPCIDevice *dev; | ||
struct iommu_ctx ctx; | ||
OSDictionary *iommu_mappings; | ||
const char *bdf; | ||
|
||
struct driverkit_bar_info bar_region_info[6]; | ||
}; | ||
|
||
#define __iommu_ctx(x) (&((struct driverkit_pci_device *)(x))->ctx) | ||
|
||
#endif /* LIBVFN_DRIVERKIT_DEVICE_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* SPDX-License-Identifier: LGPL-2.1-or-later or MIT */ | ||
|
||
#ifndef LIBVFN_VFIO_PCI_H | ||
#define LIBVFN_VFIO_PCI_H | ||
|
||
#define off_t int | ||
|
||
// NOTE: Dummy PROT to satisfy Linux code | ||
enum { | ||
PROT_READ = 0, | ||
PROT_WRITE = 1, | ||
}; | ||
|
||
// NOTE: Faux open for macOS | ||
int vfio_pci_open(struct driverkit_pci_device *pci, const char *bdf); | ||
|
||
/** | ||
* vfio_pci_map_bar - faux mapping in DriverKit | ||
* @pci: &struct driverkit_pci_device | ||
* @idx: the vfio region index to map | ||
* @len: number of bytes to map | ||
* @offset: offset at which to start mapping | ||
* @prot: what accesses to permit to the mapped area (see ``man mmap``). | ||
* | ||
* Used in place of VFIO map device memory region identified by @idx into virtual memory. | ||
* | ||
* Return: On success, returns the virtual memory address mapped. On error, | ||
* returns ``NULL`` and sets ``errno``. | ||
*/ | ||
void *vfio_pci_map_bar(struct driverkit_pci_device *pci, int idx, size_t len, uint64_t offset, | ||
int prot); | ||
|
||
/** | ||
* vfio_pci_unmap_bar - faux unmap a region in virtual memory for DriverKit | ||
* @pci: &struct driverkit_pci_device | ||
* @idx: the vfio region index to unmap | ||
* @mem: virtual memory address to unmap | ||
* @len: number of bytes to unmap | ||
* @offset: offset at which to start unmapping | ||
* | ||
* Used in place of VFIO to unmap the virtual memory address, previously mapped to the vfio device memory | ||
* region identified by @idx. | ||
*/ | ||
void vfio_pci_unmap_bar(struct driverkit_pci_device *pci, int idx, void *mem, size_t len, | ||
uint64_t offset); | ||
|
||
#endif /* LIBVFN_VFIO_PCI_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: LGPL-2.1-or-later or MIT | ||
|
||
/* | ||
* This file is part of libvfn. | ||
* | ||
* Copyright (C) 2022 The libvfn Authors. All Rights Reserved. | ||
* | ||
* This library (libvfn) is dual licensed under the GNU Lesser General | ||
* Public License version 2.1 or later or the MIT license. See the | ||
* COPYING and LICENSE files for more information. | ||
*/ | ||
|
||
|
||
|
||
#define log_fmt(fmt) "driverkit/pci: " fmt | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <vfn/support.h> | ||
|
||
// NOTE: Faux open for macOS | ||
int vfio_pci_open(struct driverkit_pci_device *pci, const char *bdf) | ||
{ | ||
return 0; | ||
} | ||
|
||
void *vfio_pci_map_bar(struct driverkit_pci_device *pci, int idx, size_t len, uint64_t offset, int prot) | ||
{ | ||
struct macvfn_pci_map_bar *mapping = (struct macvfn_pci_map_bar *) zmallocn(1, sizeof(struct macvfn_pci_map_bar)); | ||
mapping->pci = pci; | ||
mapping->idx = idx; | ||
mapping->len = len; | ||
mapping->offset = offset; | ||
|
||
return mapping; | ||
} | ||
|
||
void vfio_pci_unmap_bar(struct driverkit_pci_device *pci, int idx, void *mem, size_t len, uint64_t offset) | ||
{ | ||
free(mem); | ||
} | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.