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

FreeBSD support #68

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion Source/Common/AssertTracer/AssertTracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ void __stdcall ReportAssertETW( const unsigned short compId,
#endif
}

#elif defined( __linux__ ) && defined( _RELEASE_INTERNAL ) && !defined( __ANDROID__ )
#elif defined( _RELEASE_INTERNAL ) && !defined( _WIN32 ) && !defined( __ANDROID__ )
#include <algorithm>
#include <syslog.h>
#include <execinfo.h>
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/AssertTracer/AssertTracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void __stdcall ReportAssertETW(const unsigned short compId,
}
#endif

#elif defined( __linux__ ) && defined( _RELEASE_INTERNAL ) && !defined( __ANDROID__ )
#elif defined( _RELEASE_INTERNAL ) && !defined( _WIN32 ) && !defined( __ANDROID__ )
// do while() is missing ";" at the end and this is intentional
// As invoking assert looks like this: assert(expr); So semicolon will
// be stuck to do.. while() and that way sorting out possible
Expand Down
2 changes: 1 addition & 1 deletion Source/GmmLib/CachePolicy/GmmGen8CachePolicy.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ DEFINE_CACHE_ELEMENT(GMM_RESOURCE_USAGE_SURFACE_REF_ENCODE
DEFINE_CACHE_ELEMENT(GMM_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE , 1 , 1 , 1 , 0 , 1);
DEFINE_CACHE_ELEMENT(GMM_RESOURCE_USAGE_SURFACE_HME_DOWNSAMPLED_ENCODE_DST , 1 , 1 , 0 , 0 , 1);
DEFINE_CACHE_ELEMENT(GMM_RESOURCE_USAGE_SURFACE_ME_DISTORTION_ENCODE , 1 , 1 , 1 , 0 , 1);
#if defined(__linux__) && !defined(ANDROID)
#if !defined(_WIN32) && !defined(ANDROID)
DEFINE_CACHE_ELEMENT(GMM_RESOURCE_USAGE_SURFACE_MV_DATA_ENCODE , 1 , 1 , 0 , 0 , 1);
DEFINE_CACHE_ELEMENT(GMM_RESOURCE_USAGE_SURFACE_BRC_ME_DISTORTION_ENCODE , 1 , 1 , 0 , 0 , 1);
DEFINE_CACHE_ELEMENT(GMM_RESOURCE_USAGE_PAK_OBJECT_ENCODE , 1 , 1 , 0 , 0 , 1);
Expand Down
4 changes: 2 additions & 2 deletions Source/GmmLib/GlobalInfo/GmmInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,7 @@ int32_t GmmLib::Context::IncrementRefCount()
{
int32_t *Ref = &RefCount;

#if defined(__linux__)
#if defined(__GNUC__)
// returns 0 only when registering the first client
return (__sync_fetch_and_add(Ref, 1));
#endif
Expand Down Expand Up @@ -974,7 +974,7 @@ int32_t GmmLib::Context::DecrementRefCount()
{
break;
}
#if defined(__linux__)
#if defined(__GNUC__)
} while(!__sync_bool_compare_and_swap(Ref, CurrentValue, TargetValue));
#endif
return TargetValue;
Expand Down
4 changes: 2 additions & 2 deletions Source/GmmLib/Resource/Linux/GmmResourceInfoLinCWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OTHER DEALINGS IN THE SOFTWARE.

#include "Internal/Common/GmmLibInc.h"

#if defined(__linux__) && !LHDM
#if !defined(_WIN32) && !LHDM
#include "Internal/Linux/GmmResourceInfoLinInt.h"

/////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -176,4 +176,4 @@ GMM_TRANSLATIONTABLE_CALLBACKS DummyTTCB = {
.pfWriteL3Adr = DummyWriteL3Adr,
};

#endif /*__linux__*/
#endif /*!_WIN32*/
2 changes: 1 addition & 1 deletion Source/GmmLib/Texture/GmmTextureAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ GMM_STATUS GmmLib::GmmTextureCalc::FillTexPitchAndSize(GMM_TEXTURE_INFO * pTexIn
}
else
{
#if defined(__GMM_KMD__) || defined(__linux__)
#if defined(__GMM_KMD__) || !defined(_WIN32)
GMM_ASSERTDPF(0, "Surface too large!");
#endif
Status = GMM_ERROR;
Expand Down
6 changes: 3 additions & 3 deletions Source/GmmLib/TranslationTable/GmmPageTableMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Description: UMD-TT manager (manages both TR-TT and AUX-TT in user mode space)
#include "../TranslationTable/GmmUmdTranslationTable.h"
#include "External/Common/GmmClientContext.h"

#if defined(__linux__)
#if !defined(_WIN32)
#include "Internal/Linux/GmmResourceInfoLinInt.h"
#endif

Expand All @@ -44,7 +44,7 @@ Description: UMD-TT manager (manages both TR-TT and AUX-TT in user mode space)
LeaveCriticalSection(&PoolLock); \
}
extern GMM_MA_LIB_CONTEXT *pGmmMALibContext;
#if defined(__linux__)
#if !defined(_WIN32)
GMM_STATUS GmmLib::__GmmDeviceAlloc(GmmClientContext * pClientContext,
GMM_DEVICE_CALLBACKS_INT *pDeviceCbInt,
GMM_DEVICE_ALLOC * pAlloc)
Expand Down Expand Up @@ -608,7 +608,7 @@ GMM_STATUS GmmLib::GmmPageTableMgr::UpdateAuxTable(const GMM_DDI_UPDATEAUXTABLE
return GMM_SUCCESS;
}

#if defined(__linux__) && !_WIN32
#if !defined(_WIN32)
/////////////////////////////////////////////////////////////////////////////////////
/// Gets size of PageTable buffer object (BOs) list
///
Expand Down
2 changes: 1 addition & 1 deletion Source/GmmLib/TranslationTable/GmmUmdTranslationTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Description: Contains functions of internal classes

#if !defined(__GMM_KMD)

#if defined(__linux__)
#if !defined(_WIN32)
#include "Internal/Linux/GmmResourceInfoLinInt.h"

#define _aligned_free(ptr) free(ptr)
Expand Down
11 changes: 3 additions & 8 deletions Source/GmmLib/TranslationTable/GmmUmdTranslationTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Description: This file contains the class definitions for GmmPageTablePool
#pragma once
#include "External/Common/GmmPageTableMgr.h"

#ifdef __linux__
#ifndef _WIN32
#include <pthread.h>
#include <string.h>

Expand Down Expand Up @@ -60,12 +60,7 @@ static inline int _BitScanForward(uint32_t *index, uint32_t mask)
{
int i;

#ifdef __ANDROID__
i = ffs(mask);
#else
i = ffsl(mask);
#endif

i = __builtin_ffsl(mask);
if(i > 0)
{
*index = (uint32_t)(i - 1);
Expand Down Expand Up @@ -448,7 +443,7 @@ namespace GmmLib
public:
#ifdef _WIN32
CRITICAL_SECTION TTLock; //synchronized access of PageTable obj
#elif defined __linux__
#else
pthread_mutex_t TTLock;
#endif

Expand Down
2 changes: 1 addition & 1 deletion Source/GmmLib/ULT/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ target_link_libraries(${EXE_NAME} igfx_gmmumd_dll)

target_link_libraries(${EXE_NAME}
pthread
dl
${CMAKE_DL_LIBS}
)

add_custom_target(Run_ULT ALL DEPENDS GMMULT)
Expand Down
4 changes: 2 additions & 2 deletions Source/GmmLib/ULT/GmmAuxTableULT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
============================================================================*/

#if defined (__linux__) && !defined(__i386__)
#if !defined (_WIN32) && !defined(__i386__)

#include "GmmAuxTableULT.h"

Expand Down Expand Up @@ -262,4 +262,4 @@ TEST_F(CTestAuxTable, TestAuxTableContent)
pGmmULTClientContext->DestroyPageTblMgrObject(mgr);
}

#endif /* __linux__ */
#endif /* !_WIN32 */
5 changes: 2 additions & 3 deletions Source/GmmLib/ULT/GmmAuxTableULT.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ OTHER DEALINGS IN THE SOFTWARE.

#pragma once

#if defined (__linux__) && !defined(__i386__)
#if !defined (_WIN32) && !defined(__i386__)

#ifndef _ISOC11_SOURCE
#define _ISOC11_SOURCE 1
#endif

#include "GmmGen10ResourceULT.h"
#include <stdlib.h>
#include <malloc.h>

#ifndef ALIGN
#define ALIGN(v, a) (((v) + ((a)-1)) & ~((a)-1))
Expand Down Expand Up @@ -249,4 +248,4 @@ class CTestAuxTable : public CTestGen10Resource
};
};

#endif /* __linux__ */
#endif /* !_WIN32 */
6 changes: 1 addition & 5 deletions Source/GmmLib/Utility/GmmLog/GmmLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ OTHER DEALINGS IN THE SOFTWARE.
#include <sys/stat.h>
#include <unistd.h>
#include <fstream>
#include <linux/limits.h>
#endif

/// Logger instance shared by all of GmmLib within a process
Expand Down Expand Up @@ -197,12 +196,9 @@ bool GmmLib::Logger::GmmLogInit()
#elif defined(__ANDROID__)
// Log to logcat
SpdLogger = spdlog::android_logger(GMM_LOGGER_NAME, GMM_LOG_TAG);
#elif defined(__linux__)
#else
// Log to syslog
SpdLogger = spdlog::syslog_logger(GMM_LOGGER_NAME, GMM_LOG_TAG, 1 /*Log Pid*/);
#else
__GMM_ASSERT(0);
return false;
#endif
}
}
Expand Down
30 changes: 23 additions & 7 deletions Source/GmmLib/Utility/GmmLog/spdlog/details/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,20 @@
#include <unistd.h>
#include <chrono>

#elif __FreeBSD__
#include <sys/thr.h> //Use thr_self() syscall under FreeBSD to get thread id
#elif defined(_AIX)
#include <pthread.h> // for pthread_getthreadid_np

#elif defined(__DragonFly__) || defined(__FreeBSD__)
#include <pthread_np.h> // for pthread_getthreadid_np

#elif defined(__NetBSD__)
#include <lwp.h> // for _lwp_self

#elif defined(__OpenBSD__)
#include <unistd.h> // for getthrid

#elif defined(__sun)
#include <thread.h> // for thr_self

#else
#include <thread>
Expand Down Expand Up @@ -213,7 +225,7 @@ inline size_t filesize(FILE *f)
#else // unix
int fd = fileno(f);
//64 bits(but not in osx, where fstat64 is deprecated)
#if !defined(__FreeBSD__) && !defined(__APPLE__) && (defined(__x86_64__) || defined(__ppc64__))
#if (defined(__linux__) || defined(__sun) || defined(_AIX)) && (defined(__LP64__) || defined(_LP64))
struct stat64 st;
if (fstat64(fd, &st) == 0)
return static_cast<size_t>(st.st_size);
Expand Down Expand Up @@ -302,10 +314,14 @@ inline size_t thread_id()
# define SYS_gettid __NR_gettid
# endif
return static_cast<size_t>(syscall(SYS_gettid));
#elif __FreeBSD__
long tid;
thr_self(&tid);
return static_cast<size_t>(tid);
#elif defined(_AIX) || defined(__DragonFly__) || defined(__FreeBSD__)
return static_cast<size_t>(pthread_getthreadid_np());
#elif defined(__NetBSD__)
return static_cast<size_t>(_lwp_self());
#elif defined(__OpenBSD__)
return static_cast<size_t>(getthrid());
#elif defined(__sun)
return static_cast<size_t>(thr_self());
#else //Default to standard C++11 (OSX and other Unix)
return static_cast<size_t>(std::hash<std::thread::id>()(std::this_thread::get_id()));
#endif
Expand Down
2 changes: 1 addition & 1 deletion Source/GmmLib/Utility/GmmLog/spdlog/tweakme.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
///////////////////////////////////////////////////////////////////////////////
// Uncomment to enable syslog (disabled by default)
//
#if __linux__
#ifndef _WIN32
#define SPDLOG_ENABLE_SYSLOG
#endif
///////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion Source/GmmLib/inc/External/Common/GmmCommonExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extern const SWIZZLE_DESCRIPTOR INTEL_64KB_UNDEFINED_64_128bpp;
#define GMM_NO_FENCE_REG 0xDEADBEEF
#define GMM_MAX_DISPLAYS 3

#if defined __linux__
#ifndef _WIN32
typedef void* HANDLE;
#endif

Expand Down
4 changes: 2 additions & 2 deletions Source/GmmLib/inc/External/Common/GmmInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ namespace GmmLib
{
#if defined(_WIN32)
return(InterlockedIncrement((LONG *)&RefCount) - 1); //InterLockedIncrement() returns incremented value
#elif defined(__linux__)
#elif defined(__GNUC__)
return(__sync_fetch_and_add(&RefCount, 1));
#endif
}
Expand All @@ -163,7 +163,7 @@ namespace GmmLib
}
#if defined(_WIN32)
} while (!(InterlockedCompareExchange((LONG *)&RefCount, TargetValue, CurrentValue) == CurrentValue));
#elif defined(__linux__)
#elif defined(__GNUC__)
} while (!__sync_bool_compare_and_swap(&RefCount, CurrentValue, TargetValue));
#endif

Expand Down
6 changes: 3 additions & 3 deletions Source/GmmLib/inc/External/Common/GmmPageTableMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Description: This file contains the class definitions for GmmPageTableMgr
#pragma once
#include "GmmHw.h"

#ifdef __linux__
#ifndef _WIN32
#include <pthread.h>
#endif

Expand Down Expand Up @@ -108,7 +108,7 @@ namespace GmmLib
GmmClientContext *pClientContext; ///< ClientContext of the client creating this Object

//OS-specific defn
#if defined __linux__
#ifndef _WIN32
pthread_mutex_t PoolLock;
#endif
public:
Expand All @@ -134,7 +134,7 @@ namespace GmmLib
GMM_VIRTUAL GMM_PAGETABLEPool * __GetFreePoolNode(uint32_t * FreePoolNodeIdx, POOL_TYPE PoolType);


#if defined __linux__
#ifndef _WIN32
//returns number of BOs for indicated TTs = NumNodePoolElements+1 BOs for root table and pools
GMM_VIRTUAL int GetNumOfPageTableBOs(uint8_t TTFlags);
//returns BO* list for indicated TT in client allocated memory
Expand Down
2 changes: 1 addition & 1 deletion Source/GmmLib/inc/External/Common/GmmResourceInfoExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ typedef struct GmmLibContext GMM_LIB_CONTEXT;
// Place holder for GMM_RESOURCE_FLAG definition.
//---------------------------------------------------------------------------
#include "GmmResourceFlags.h"
#if defined __linux__
#ifndef _WIN32
#include "External/Linux/GmmResourceInfoLinExt.h"
#endif

Expand Down
4 changes: 2 additions & 2 deletions Source/GmmLib/inc/External/Linux/GmmResourceInfoLinExt.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ OTHER DEALINGS IN THE SOFTWARE.
============================================================================*/
#pragma once

#ifdef __linux__
#ifndef _WIN32

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -93,4 +93,4 @@ typedef struct GMM_UMD_SYNCCONTEXT_REC
}
#endif /*__cplusplus*/

#endif /*__linux__*/
#endif /*!_WIN32*/
4 changes: 2 additions & 2 deletions Source/GmmLib/inc/Internal/Linux/GmmResourceInfoLinInt.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OTHER DEALINGS IN THE SOFTWARE.

#pragma once

#if defined(__linux__) && !LHDM
#if !defined(_WIN32) && !LHDM

// GMM Lib Client Exports
#include "External/Common/GmmCommonExt.h"
Expand Down Expand Up @@ -68,4 +68,4 @@ int GmmCheckForNullDevCbPfn(GMM_CLIENT ClientType, GMM_DEVICE_CALLBACKS_INT *pDe

extern GMM_TRANSLATIONTABLE_CALLBACKS DummyTTCB;

#endif /*__linux__*/
#endif /*!_WIN32*/
3 changes: 3 additions & 0 deletions Source/inc/portable_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ OTHER DEALINGS IN THE SOFTWARE.
#endif

#define __noop
#ifdef __fastcall
#undef __fastcall
#endif
#define __fastcall
#if defined __x86_64__
#define __stdcall // deprecated for x86-64
Expand Down
2 changes: 1 addition & 1 deletion Source/util/gfxDebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ OTHER DEALINGS IN THE SOFTWARE.

#else

#ifndef __linux__
#ifdef _WIN32
#include "igdKrnlEtwMacros.h"
#endif

Expand Down