Skip to content

Commit

Permalink
Add network driver stub
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldfish64 committed Aug 14, 2021
1 parent 3a3bcfc commit df0ccca
Show file tree
Hide file tree
Showing 5 changed files with 125 additions and 0 deletions.
18 changes: 18 additions & 0 deletions MacHyperVSupport.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
418F843E2648BA38003F8520 /* HyperVStorage.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 418F843C2648BA38003F8520 /* HyperVStorage.hpp */; };
419B88C2263F0169005A9977 /* Hypercalls.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 419B88C1263F0169005A9977 /* Hypercalls.cpp */; };
419B88C5263F1F85005A9977 /* VMBus.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 419B88C4263F1F85005A9977 /* VMBus.cpp */; };
41B41BDD26C74B4C00926A0D /* HyperVNetwork.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41B41BDB26C74B4C00926A0D /* HyperVNetwork.cpp */; };
41B41BDE26C74B4C00926A0D /* HyperVNetwork.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 41B41BDC26C74B4C00926A0D /* HyperVNetwork.hpp */; };
41BE411A263EDFAF0018C52B /* HyperVVMBusController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41BE4118263EDFAF0018C52B /* HyperVVMBusController.cpp */; };
41BE411B263EDFAF0018C52B /* HyperVVMBusController.hpp in Headers */ = {isa = PBXBuildFile; fileRef = 41BE4119263EDFAF0018C52B /* HyperVVMBusController.hpp */; };
41E2EC78263F894300BBE18F /* SynIC.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41E2EC77263F894300BBE18F /* SynIC.cpp */; };
Expand Down Expand Up @@ -109,6 +111,9 @@
418F84412648BA88003F8520 /* HyperVStorageRegs.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = HyperVStorageRegs.hpp; sourceTree = "<group>"; };
419B88C1263F0169005A9977 /* Hypercalls.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Hypercalls.cpp; sourceTree = "<group>"; };
419B88C4263F1F85005A9977 /* VMBus.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = VMBus.cpp; sourceTree = "<group>"; };
41B41BDB26C74B4C00926A0D /* HyperVNetwork.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = HyperVNetwork.cpp; sourceTree = "<group>"; };
41B41BDC26C74B4C00926A0D /* HyperVNetwork.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = HyperVNetwork.hpp; sourceTree = "<group>"; };
41B41BE126C80DEC00926A0D /* HyperVNetworkRegs.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = HyperVNetworkRegs.hpp; sourceTree = "<group>"; };
41BE4104263EDE380018C52B /* MacHyperVSupport.kext */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = MacHyperVSupport.kext; sourceTree = BUILT_PRODUCTS_DIR; };
41BE410B263EDE380018C52B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
41BE4113263EDEA10018C52B /* libkmod.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libkmod.a; path = MacKernelSDK/Library/x86_64/libkmod.a; sourceTree = "<group>"; };
Expand Down Expand Up @@ -232,6 +237,16 @@
path = Storage;
sourceTree = "<group>";
};
41B41BDA26C74B2700926A0D /* Network */ = {
isa = PBXGroup;
children = (
41B41BDB26C74B4C00926A0D /* HyperVNetwork.cpp */,
41B41BDC26C74B4C00926A0D /* HyperVNetwork.hpp */,
41B41BE126C80DEC00926A0D /* HyperVNetworkRegs.hpp */,
);
path = Network;
sourceTree = "<group>";
};
41BE40FA263EDE370018C52B = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -259,6 +274,7 @@
418F051F26483C3C00E1D14C /* IntegrationComponents */,
418219632648605D00619C15 /* Keyboard */,
418F84312648B06E003F8520 /* Mouse */,
41B41BDA26C74B2700926A0D /* Network */,
41F2E45926683AF900CE26CE /* PCIRoot */,
41F2E42A2665B61800CE26CE /* PlatformProvider */,
418F843A2648B9AA003F8520 /* Storage */,
Expand Down Expand Up @@ -432,6 +448,7 @@
41F2E40B2665B42200CE26CE /* x86.h in Headers */,
41F2E3FD2665B42200CE26CE /* plugin_start.hpp in Headers */,
41F2E4062665B42200CE26CE /* capstone.h in Headers */,
41B41BDE26C74B4C00926A0D /* HyperVNetwork.hpp in Headers */,
41F2E3F42665B42200CE26CE /* kern_config.hpp in Headers */,
41F2E3F72665B42200CE26CE /* kern_nvram.hpp in Headers */,
418219672648607600619C15 /* HyperVKeyboard.hpp in Headers */,
Expand Down Expand Up @@ -556,6 +573,7 @@
418F843D2648BA38003F8520 /* HyperVStorage.cpp in Sources */,
41F2E42D2665B64D00CE26CE /* HyperVPlatformProvider.cpp in Sources */,
41225F572644D98500574E86 /* HyperVHeartbeat.cpp in Sources */,
41B41BDD26C74B4C00926A0D /* HyperVNetwork.cpp in Sources */,
41078473264603F1005894D4 /* VMBusChannel.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
14 changes: 14 additions & 0 deletions MacHyperVSupport/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,20 @@
<key>VendorID</key>
<integer>1118</integer>
</dict>
<key>HyperVNetwork</key>
<dict>
<key>CFBundleIdentifier</key>
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
<key>IOClass</key>
<string>HyperVNetwork</string>
<key>IOPropertyMatch</key>
<dict>
<key>HVType</key>
<string>f8615163-df3e-46c5-913f-f2d2f965ed0e</string>
</dict>
<key>IOProviderClass</key>
<string>HyperVVMBusDevice</string>
</dict>
<key>HyperVPCIProviderGen2</key>
<dict>
<key>CFBundleIdentifier</key>
Expand Down
44 changes: 44 additions & 0 deletions MacHyperVSupport/Network/HyperVNetwork.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// HyperVNetwork.cpp
// Hyper-V network driver
//
// Copyright © 2021 Goldfish64. All rights reserved.
//

#include "HyperVNetwork.hpp"
#include "HyperVNetworkRegs.hpp"

OSDefineMetaClassAndStructors(HyperVNetwork, super);

bool HyperVNetwork::start(IOService *provider) {
if (!super::start(provider)) {
return false;
}

DBGLOG("Initializing Hyper-V Synthetic Networking");

//
// Get parent VMBus device object.
//
hvDevice = OSDynamicCast(HyperVVMBusDevice, provider);
if (hvDevice == NULL) {
super::stop(provider);
return false;
}
hvDevice->retain();

//
// Configure the channel.
//
if (!hvDevice->openChannel(kHyperVNetworkRingBufferSize, kHyperVNetworkRingBufferSize, this, OSMemberFunctionCast(IOInterruptEventAction, this, &HyperVNetwork::handleInterrupt))) {
super::stop(provider);
return false;
}

SYSLOG("Initialized Hyper-V Synthetic Networking");
return true;
}

void HyperVNetwork::handleInterrupt(OSObject *owner, IOInterruptEventSource *sender, int count) {
DBGLOG("Interrupt");
}
36 changes: 36 additions & 0 deletions MacHyperVSupport/Network/HyperVNetwork.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// HyperVNetwork.cpp
// Hyper-V network driver
//
// Copyright © 2021 Goldfish64. All rights reserved.
//

#ifndef HyperVNetwork_hpp
#define HyperVNetwork_hpp

#include "HyperVVMBusDevice.hpp"

#define super IOService

#define SYSLOG(str, ...) SYSLOG_PRINT("HyperVNetwork", str, ## __VA_ARGS__)
#define DBGLOG(str, ...) DBGLOG_PRINT("HyperVNetwork", str, ## __VA_ARGS__)

class HyperVNetwork : public IOService {
OSDeclareDefaultStructors(HyperVNetwork);

private:
//
// Parent VMBus device.
//
HyperVVMBusDevice *hvDevice;

void handleInterrupt(OSObject *owner, IOInterruptEventSource *sender, int count);

public:
//
// IOService overrides.
//
virtual bool start(IOService *provider) APPLE_KEXT_OVERRIDE;
};

#endif /* HyperVNetwork_hpp */
13 changes: 13 additions & 0 deletions MacHyperVSupport/Network/HyperVNetworkRegs.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// HyperVNetworkRegs.cpp
// Hyper-V network driver
//
// Copyright © 2021 Goldfish64. All rights reserved.
//

#ifndef HyperVNetworkRegs_h
#define HyperVNetworkRegs_h

#define kHyperVNetworkRingBufferSize (128 * PAGE_SIZE)

#endif /* HyperVNetworkRegs_h */

0 comments on commit df0ccca

Please sign in to comment.