Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add macOS/DriverKit through MacVFN #10

Open
wants to merge 23 commits into
base: main
Choose a base branch
from

Conversation

Baekalfen
Copy link
Contributor

This works together with the libvfn4 branch on the MacVFN repo: SamsungDS/MacVFN#1

@Baekalfen Baekalfen force-pushed the driverkit_main branch 4 times, most recently from 63b3c61 to 245a56f Compare May 7, 2024 13:38
@birkelund
Copy link
Collaborator

Cherry-picked the below and merged on main,

  • 14aaa73 ("misc: change void* to union nvme_cmd and struct nvme_cqe in nvme submission")
  • 8f184c3 ("nvme/core: use __mps_to_pageshift for mps checks")
  • b8ce0c4 ("misc: unify use of ETIMEDOUT")
  • c42a81e ("core/misc: remove redundant cid")

.gitignore Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? These files are generated within the meson build directory where meson also generates a .gitignore file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In MacVFN, I'm only using meson to configure, but then I move those files to where Xcode can reach them

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but it doesn't belong in libvfn.

/**
* @serial: Serial number from controller
*/
char serial[20];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bloats struct nvme_ctrl and it does not seem to be used in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought I had put something in the commit message. It's for enumeration in xNVMe. MacVFN reads this serial and applies it to its name in macOS's "IO registry" of devices.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, but it belongs in MacVFN then.

@birkelund
Copy link
Collaborator

8132896 ("iommu/dma: dma_map takes opaque pointer, dma_unmap takes mapping as argument") and 08cd6b1 ("iova/dma_map: change interface to use iova_mapping") seem to change the same interface without any specific use in between.

Can these be squashed?

@Baekalfen Baekalfen force-pushed the driverkit_main branch 12 times, most recently from a9346ab to 22794f5 Compare May 8, 2024 10:17
@Baekalfen
Copy link
Contributor Author

8132896 ("iommu/dma: dma_map takes opaque pointer, dma_unmap takes mapping as argument") and 08cd6b1 ("iova/dma_map: change interface to use iova_mapping") seem to change the same interface without any specific use in between.

Can these be squashed?

Sure

@Baekalfen Baekalfen force-pushed the driverkit_main branch 8 times, most recently from 1c7ebbd to 136a863 Compare May 13, 2024 10:11
Moved file without any changes to prepare for other platforms.

Signed-off-by: Mads Ynddal <[email protected]>
…s into platform/linux

Moved file without any changes to prepare for other platforms.

Signed-off-by: Mads Ynddal <[email protected]>
Simple replacement using built-in byteswap.

Signed-off-by: Mads Ynddal <[email protected]>
Sparsely added definitions needed on macOS+DriverKit.

Signed-off-by: Mads Ynddal <[email protected]>
A port of the Linux log.h using DriverKit os_log.

Signed-off-by: Mads Ynddal <[email protected]>
Added port of mem.h for macOS using DriverKit IOMallocZero and IOFree.

Signed-off-by: Mads Ynddal <[email protected]>
Added port of mmio.h for macOS using faux BAR mappings.

Signed-off-by: Mads Ynddal <[email protected]>
Added port of mutex.h for macOS using IOLock instead of pthread.

Signed-off-by: Mads Ynddal <[email protected]>
…modate C++

For macOS we need to use C++, and it forces us to explicitly do
type-casting etc.

Signed-off-by: Mads Ynddal <[email protected]>
These files are normally ignored when compiling with meson on Linux, but
on macOS, we need to copy them into our source code.

Signed-off-by: Mads Ynddal <[email protected]>
context.h needs to be included from different places, so an include
guard is required to not cause issues.

Signed-off-by: Mads Ynddal <[email protected]>
@Baekalfen Baekalfen force-pushed the driverkit_main branch 4 times, most recently from 9cdfbb5 to 476374a Compare May 22, 2024 11:08
Remove all redundant includes.

Introduce ifdef's for __cplusplus.

Signed-off-by: Mads Ynddal <[email protected]>
Change dma_map, iova_map_add and dma_unmap to take an iova_mapping instead of
individual arguments. This simplified passing the context around, and adding
more attributes transparently later.

Signed-off-by: Mads Ynddal <[email protected]>
arc4 is a cryptographically secure RNG, which we don't need, but is what
we have on macOS+DriverKit.

Signed-off-by: Mads Ynddal <[email protected]>
Added include guard to skiplist.h to avoid duplicate definitions.

Signed-off-by: Mads Ynddal <[email protected]>
Port timeout to macOS+DriverKit using clock_gettime_nsec_np.

Signed-off-by: Mads Ynddal <[email protected]>
Change internal timekeeping to nanoseconds to be universal between Linux
and macOS.

Signed-off-by: Mads Ynddal <[email protected]>
Added serial string to nvme_ctrl to be able to identify the device. This
value is copied from the already issued identify during nvme_init.

Signed-off-by: Mads Ynddal <[email protected]>
Add support for passing opaque pointers around with the pgmap and iommu
functions. This is needed for macOS, where the vaddr is not enough to
free memory or map with the IOMMU.

Signed-off-by: Mads Ynddal <[email protected]>
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]>
Change log-statements from 'log_debug' to 'log_error', when they are in
relation to an unrecoverable error. As a rule of thumb, if the log is
immediately followed by 'return -1', then it's an error. If we can
continue but just log for helping, it's debug.

Signed-off-by: Mads Ynddal <[email protected]>
By setting up the current PR branch as a submodule in MacVFN, we can
build MacVFN and thereby verify the current libvfn branch is valid. No
actual device or code test is performed.

Signed-off-by: Mads Ynddal <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants