From d0c7ca3c02eed577cfafe25c1f12bf9abd09dde7 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sat, 19 Oct 2013 23:50:50 +0200 Subject: [PATCH] Port sortix/pci.h from to . --- sortix/pci.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/sortix/pci.cpp b/sortix/pci.cpp index 72e21481..53a892be 100644 --- a/sortix/pci.cpp +++ b/sortix/pci.cpp @@ -1,6 +1,6 @@ /******************************************************************************* - Copyright(C) Jonas 'Sortie' Termansen 2011, 2012. + Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013. This file is part of Sortix. @@ -22,14 +22,12 @@ *******************************************************************************/ +#include +#include + #include -#include #include #include -#include - -// TODO: Verify that the endian conversions in this file actually works. I have -// a sneaking suspicion that they won't work on non-little endian platforms. namespace Sortix { namespace PCI { @@ -66,12 +64,12 @@ void WriteRaw32(uint32_t devaddr, uint8_t off, uint32_t val) uint32_t Read32(uint32_t devaddr, uint8_t off) { - return LittleToHost(ReadRaw32(devaddr, off)); + return le32toh(ReadRaw32(devaddr, off)); } void Write32(uint32_t devaddr, uint8_t off, uint32_t val) { - WriteRaw32(devaddr, off, HostToLittle(val)); + WriteRaw32(devaddr, off, htole32(val)); } uint16_t Read16(uint32_t devaddr, uint8_t off) @@ -81,14 +79,14 @@ uint16_t Read16(uint32_t devaddr, uint8_t off) union { uint16_t val16[2]; uint32_t val32; }; val32 = ReadRaw32(devaddr, alignedoff); uint16_t ret = off & 0x2 ? val16[0] : val16[1]; - return LittleToHost(ret); + return le16toh(ret); } uint8_t Read8(uint32_t devaddr, uint8_t off) { uint8_t alignedoff = off & ~0x1; union { uint8_t val8[2]; uint32_t val16; }; - val16 = HostToLittle(Read16(devaddr, alignedoff)); + val16 = htole16(Read16(devaddr, alignedoff)); uint8_t ret = off & 0x1 ? val8[0] : val8[1]; return ret; }