From 8040911a25d7459b5c007eb35c65cb4abe05eaaa Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Mon, 10 Sep 2012 22:32:20 +0200 Subject: [PATCH 01/23] Use implemented ports mask to check if maximum port count needs to be extended. * This should fix #8953 * Also fix some harmless off-by-one errors --- .../kernel/busses/scsi/ahci/ahci_controller.cpp | 15 ++++++++++++--- src/add-ons/kernel/busses/scsi/ahci/util.cpp | 14 ++++++++++++++ src/add-ons/kernel/busses/scsi/ahci/util.h | 2 ++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp index e7bc95affd..24ded54f21 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp @@ -131,12 +131,21 @@ AHCIController::Init() fPortCountMax = 1 + ((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK); fPortImplementedMask = fRegs->pi; + // reported mask of implemented ports is sometimes empty if (fPortImplementedMask == 0) { fPortImplementedMask = 0xffffffff >> (32 - fPortCountMax); TRACE("ports-implemented mask is zero, using 0x%" B_PRIx32 " instead.\n", fPortImplementedMask); } + // reported number of ports is sometimes too small + int maxPortIndex; + maxPortIndex = fls(fPortImplementedMask); + if (fPortCountMax < maxPortIndex) { + TRACE("reported number of ports is wrong, using %d instead.\n", maxPortIndex); + fPortCountMax = maxPortIndex; + } + fPortCountAvail = count_bits_set(fPortImplementedMask); TRACE("cap: Interface Speed Support: generation %" B_PRIu32 "\n", (fRegs->cap >> CAP_ISS_SHIFT) & CAP_ISS_MASK); @@ -169,7 +178,7 @@ AHCIController::Init() goto err; } - for (int i = 0; i <= fPortCountMax; i++) { + for (int i = 0; i < fPortCountMax; i++) { if (fPortImplementedMask & (1 << i)) { fPort[i] = new (std::nothrow)AHCIPort(this, i); if (!fPort[i]) { @@ -189,7 +198,7 @@ AHCIController::Init() fRegs->ghc |= GHC_IE; FlushPostedWrites(); - for (int i = 0; i <= fPortCountMax; i++) { + for (int i = 0; i < fPortCountMax; i++) { if (fPort[i]) { status_t status = fPort[i]->Init2(); if (status < B_OK) { @@ -215,7 +224,7 @@ AHCIController::Uninit() { TRACE("AHCIController::Uninit\n"); - for (int i = 0; i <= fPortCountMax; i++) { + for (int i = 0; i < fPortCountMax; i++) { if (fPort[i]) { fPort[i]->Uninit(); delete fPort[i]; diff --git a/src/add-ons/kernel/busses/scsi/ahci/util.cpp b/src/add-ons/kernel/busses/scsi/ahci/util.cpp index d630d9f814..ff58f823e8 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/util.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/util.cpp @@ -121,3 +121,17 @@ swap_words(void *data, size_t size) word++; } } + + +int +fls(unsigned mask) +{ + if (mask == 0) + return 0; + int pos = 1; + while (mask != 1) { + mask >>= 1; + pos++; + } + return pos; +} diff --git a/src/add-ons/kernel/busses/scsi/ahci/util.h b/src/add-ons/kernel/busses/scsi/ahci/util.h index 94fc1ac94c..75b4f9dd45 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/util.h +++ b/src/add-ons/kernel/busses/scsi/ahci/util.h @@ -20,6 +20,8 @@ status_t sg_memcpy(const physical_entry *sgTable, int sgCount, const void *data, void swap_words(void *data, size_t size); +int fls(unsigned mask); + #ifdef __cplusplus } #endif From 1bd07482531e9fae514212e729ce94eb7b534f42 Mon Sep 17 00:00:00 2001 From: Ingo Weinhold Date: Tue, 11 Sep 2012 22:31:19 +0200 Subject: [PATCH 02/23] Fix crash in MemoryManager::PerformMaintenance() sFreeAreaCount wasn't decremented after removing an area from sFreeAreas, thus causing the loop to continue until enountering and crashing on a NULL pointer after removing the last area. Introduce helper methods _PushFreeArea() and _PopFreeArea() to ensure this cannot easily happen again. Fixes ticket #8972. --- src/system/kernel/slab/MemoryManager.cpp | 20 +++++++------------- src/system/kernel/slab/MemoryManager.h | 23 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/system/kernel/slab/MemoryManager.cpp b/src/system/kernel/slab/MemoryManager.cpp index 3a6ac26f55..1f1fa8e0ee 100644 --- a/src/system/kernel/slab/MemoryManager.cpp +++ b/src/system/kernel/slab/MemoryManager.cpp @@ -22,7 +22,6 @@ #include "kernel_debug_config.h" #include "ObjectCache.h" -#include "slab_private.h" //#define TRACE_MEMORY_MANAGER @@ -849,15 +848,13 @@ MemoryManager::PerformMaintenance() if (_AllocateArea(0, area) != B_OK) return; - _push(sFreeAreas, area); - if (++sFreeAreaCount > 2) + _PushFreeArea(area); + if (sFreeAreaCount > 2) sMaintenanceNeeded = true; } else { // free until we only have two free ones - while (sFreeAreaCount > 2) { - Area* area = _pop(sFreeAreas); - _FreeArea(area, true, 0); - } + while (sFreeAreaCount > 2) + _FreeArea(_PopFreeArea(), true, 0); if (sFreeAreaCount == 0) sMaintenanceNeeded = true; @@ -956,8 +953,7 @@ MemoryManager::_AllocateChunks(size_t chunkSize, uint32 chunkCount, return B_OK; if (sFreeAreas != NULL) { - _AddArea(_pop(sFreeAreas)); - sFreeAreaCount--; + _AddArea(_PopFreeArea()); _RequestMaintenance(); _GetChunks(metaChunkList, chunkSize, chunkCount, _metaChunk, _chunk); @@ -1409,16 +1405,14 @@ MemoryManager::_FreeArea(Area* area, bool areaRemoved, uint32 flags) // We want to keep one or two free areas as a reserve. if (sFreeAreaCount <= 1) { - _push(sFreeAreas, area); - sFreeAreaCount++; + _PushFreeArea(area); return; } if (area->vmArea == NULL || (flags & CACHE_DONT_LOCK_KERNEL_SPACE) != 0) { // This is either early in the boot process or we aren't allowed to // delete the area now. - _push(sFreeAreas, area); - sFreeAreaCount++; + _PushFreeArea(area); _RequestMaintenance(); return; } diff --git a/src/system/kernel/slab/MemoryManager.h b/src/system/kernel/slab/MemoryManager.h index 0fe20cb18a..9af7c96d20 100644 --- a/src/system/kernel/slab/MemoryManager.h +++ b/src/system/kernel/slab/MemoryManager.h @@ -15,6 +15,7 @@ #include #include "slab_debug.h" +#include "slab_private.h" class AbstractTraceEntryWithStackTrace; @@ -161,6 +162,9 @@ private: static void _PrepareMetaChunk(MetaChunk* metaChunk, size_t chunkSize); + static void _PushFreeArea(Area* area); + static Area* _PopFreeArea(); + static void _AddArea(Area* area); static status_t _AllocateArea(uint32 flags, Area*& _area); static void _FreeArea(Area* area, bool areaRemoved, @@ -235,6 +239,25 @@ MemoryManager::MaintenanceNeeded() } +/*static*/ inline void +MemoryManager::_PushFreeArea(Area* area) +{ + _push(sFreeAreas, area); + sFreeAreaCount++; +} + + +/*static*/ inline MemoryManager::Area* +MemoryManager::_PopFreeArea() +{ + if (sFreeAreaCount == 0) + return NULL; + + sFreeAreaCount--; + return _pop(sFreeAreas); +} + + /*static*/ inline addr_t MemoryManager::_AreaBaseAddressForAddress(addr_t address) { From 554fe146cb72b440f13241f798d7de80e986f5ab Mon Sep 17 00:00:00 2001 From: Scott McCreary Date: Tue, 11 Sep 2012 00:09:53 -0700 Subject: [PATCH 03/23] Updated several more OptionalPackages --- build/jam/OptionalLibPackages | 20 ++++++++++---------- build/jam/OptionalPackages | 32 ++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 24 deletions(-) diff --git a/build/jam/OptionalLibPackages b/build/jam/OptionalLibPackages index b02eadab6a..0b329920e9 100644 --- a/build/jam/OptionalLibPackages +++ b/build/jam/OptionalLibPackages @@ -38,14 +38,14 @@ if [ IsOptionalHaikuImagePackageAdded AllegroLibs ] { Echo "No optional package AllegroLibs available for $(TARGET_ARCH)" ; } else if $(HAIKU_GCC_VERSION[1]) >= 4 { InstallOptionalHaikuImagePackage - allegro-4.4.1.1-r1a3-x86-gcc4-2011-05-26.zip - : $(baseURL)/lib/allegro-4.4.1.1-r1a3-x86-gcc4-2011-05-26.zip ; + allegro-4.4.1.1-r1a4-x86-gcc4-2012-09-09.zip + : $(baseURL)/lib/allegro-4.4.1.1-r1a4-x86-gcc4-2012-09-09.zip ; InstallOptionalHaikuImagePackage - dumb-0.9.3-r1a3-x86-gcc4-2011-05-26.zip - : $(baseURL)/lib/dumb-0.9.3-r1a3-x86-gcc4-2011-05-26.zip ; + dumb-0.9.3-r1a4-x86-gcc4-2012-09-09.zip + : $(baseURL)/lib/dumb-0.9.3-r1a4-x86-gcc4-2012-09-09.zip ; InstallOptionalHaikuImagePackage - jgmod-0.99-r1a3-x86-gcc4-2011-05-26.zip - : $(baseURL)/lib/jgmod-0.99-r1a3-x86-gcc4-2011-05-26.zip ; + jgmod-0.99-r1a4-x86-gcc4-2012-09-09.zip + : $(baseURL)/lib/jgmod-0.99-r1a4-x86-gcc4-2012-09-09.zip ; } else { InstallOptionalHaikuImagePackage allegro-4.4.1.1-r1a3-x86-gcc2-2011-05-19.zip @@ -67,8 +67,8 @@ if [ IsOptionalHaikuImagePackageAdded box2d ] { } else { if $(HAIKU_GCC_VERSION[1]) >= 4 || $(isHybridBuild) { InstallOptionalHaikuImagePackage - box2d-2.1.2-r1a3-r1a3-x86-gcc4-2011-05-26.zip - : $(baseURL)/lib/box2d-2.1.2-r1a3-x86-gcc4-2011-05-26.zip + box2d-2.1.2-r1a4-x86-gcc4-2012-09-09.zip + : $(baseURL)/lib/box2d-2.1.2-r1a4-x86-gcc4-2012-09-09.zip : : true ; } else { Echo "No optional package box2d available for $(TARGET_ARCH)-gcc2" ; @@ -209,8 +209,8 @@ if [ IsOptionalHaikuImagePackageAdded physfs ] { Echo "No optional package physfs available for $(TARGET_ARCH)" ; } else if $(HAIKU_GCC_VERSION[1]) >= 4 { InstallOptionalHaikuImagePackage - physfs-2.0.1-r1a3-x86-gcc4-2011-05-26.zip - : $(baseURL)/lib/physfs-2.0.1-r1a3-x86-gcc4-2011-05-26.zip + physfs-2.0.1-r1a4-x86-gcc4-2012-09-09.zip + : $(baseURL)/lib/physfs-2.0.1-r1a4-x86-gcc4-2012-09-09.zip : : true ; } else { InstallOptionalHaikuImagePackage diff --git a/build/jam/OptionalPackages b/build/jam/OptionalPackages index 5af5efae8b..f8b3bb8778 100644 --- a/build/jam/OptionalPackages +++ b/build/jam/OptionalPackages @@ -715,8 +715,8 @@ if [ IsOptionalHaikuImagePackageAdded DevelopmentBase ] m4-1.4.16-r1a4-x86-gcc2-2012-08-26.zip : $(baseURL)/m4-1.4.16-r1a4-x86-gcc2-2012-08-26.zip ; InstallOptionalHaikuImagePackage - flex-2.5.35-r1a4-x86-gcc2-2012-08-26.zip - : $(baseURL)/flex-2.5.35-r1a4-x86-gcc2-2012-08-26.zip ; + flex-2.5.35-r1a4-x86-gcc2-2012-09-10.zip + : $(baseURL)/flex-2.5.35-r1a4-x86-gcc2-2012-09-10.zip ; InstallOptionalHaikuImagePackage jam-2.5-r1a4-x86-gcc2-2012-08-27.zip : $(baseURL)/jam-2.5-r1a4-x86-gcc2-2012-08-27.zip ; @@ -1141,12 +1141,12 @@ if [ IsOptionalHaikuImagePackageAdded KeymapSwitcher ] { } else { if $(HAIKU_GCC_VERSION[1]) >= 4 { InstallOptionalHaikuImagePackage - KeymapSwitcher-1.2.7-x86-gcc4-2012-05-19.zip - : $(baseURL)/KeymapSwitcher-1.2.7-x86-gcc4-2012-05-19.zip ; + KeymapSwitcher-1.2.7-r1a4-x86-gcc4-2012-09-09.zip + : $(baseURL)/KeymapSwitcher-1.2.7-r1a4-x86-gcc4-2012-09-09.zip ; } else { InstallOptionalHaikuImagePackage - KeymapSwitcher-1.2.7-x86-gcc2-2012-05-19.zip - : $(baseURL)/KeymapSwitcher-1.2.7-x86-gcc2-2012-05-19.zip ; + KeymapSwitcher-1.2.7-r1a4-x86-gcc2-2012-08-31.zip + : $(baseURL)/KeymapSwitcher-1.2.7-r1a4-x86-gcc2-2012-08-31.zip ; } AddSymlinkToHaikuImage home config settings deskbar Preferences : /boot/common/bin/KeymapSwitcher ; @@ -1273,8 +1273,12 @@ if [ IsOptionalHaikuImagePackageAdded LibXSLT ] { if [ IsOptionalHaikuImagePackageAdded Links ] { if $(TARGET_ARCH) != x86 { Echo "No optional package Links available for $(TARGET_ARCH)" ; - } else if $(HAIKU_GCC_VERSION[1]) >= 4 && ! $(isHybridBuild) { - Echo "No optional package Links available for gcc4" ; + } else if $(HAIKU_GCC_VERSION[1]) >= 4 { + InstallOptionalHaikuImagePackage + links-2.3pre2-r1a4-x86-gcc4-2012-09-09.zip + : $(baseURL)/links-2.3pre2-r1a4-x86-gcc4-2012-09-09.zip ; + AddSymlinkToHaikuImage home config settings deskbar Applications + : /boot/home/config/bin/links ; } else { InstallOptionalHaikuImagePackage links-2.3pre2-r1a4-x86-gcc2-2012-08-30.zip @@ -1648,8 +1652,8 @@ if [ IsOptionalHaikuImagePackageAdded Rsync ] { } else { if $(HAIKU_GCC_VERSION[1]) >= 4 { InstallOptionalHaikuImagePackage - rsync-3.0.7-r1a4-x86-gcc4-2012-08-31.zip - : $(baseURL)/rsync-3.0.7-r1a4-x86-gcc4-2012-08-31.zip + rsync-3.0.7-r1a4-x86-gcc4-2012-09-09.zip + : $(baseURL)/rsync-3.0.7-r1a4-x86-gcc4-2012-09-09.zip : : true ; } else { InstallOptionalHaikuImagePackage @@ -1667,12 +1671,12 @@ if [ IsOptionalHaikuImagePackageAdded Ruby ] { Echo "No optional package Ruby available for $(TARGET_ARCH)" ; } else if $(HAIKU_GCC_VERSION[1]) >= 4 { InstallOptionalHaikuImagePackage - ruby-1.9.1-r1a4-x86-gcc4-2012-08-31.zip - : $(baseURL)/ruby-1.9.1-r1a4-x86-gcc4-2012-08-31.zip ; + ruby-1.9.1-r1a4-x86-gcc4-2012-09-10.zip + : $(baseURL)/ruby-1.9.1-r1a4-x86-gcc4-2012-09-10.zip ; } else { InstallOptionalHaikuImagePackage - ruby-1.9.1-r1a4-x86-gcc2-2012-08-29.zip - : $(baseURL)/ruby-1.9.1-r1a4-x86-gcc2-2012-08-29.zip ; + ruby-1.9.1-r1a4-x86-gcc2-2012-09-10.zip + : $(baseURL)/ruby-1.9.1-r1a4-x86-gcc2-2012-09-10.zip ; } } From 30aeebc7164b9db52cca6bed650c23331f5f45c0 Mon Sep 17 00:00:00 2001 From: Scott McCreary Date: Tue, 11 Sep 2012 23:37:24 -0700 Subject: [PATCH 04/23] Rebuilf beam and transmission gcc4 packages --- build/jam/OptionalPackages | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build/jam/OptionalPackages b/build/jam/OptionalPackages index f8b3bb8778..9126624165 100644 --- a/build/jam/OptionalPackages +++ b/build/jam/OptionalPackages @@ -213,8 +213,8 @@ if [ IsOptionalHaikuImagePackageAdded Beam ] { } else { if $(HAIKU_GCC_VERSION[1]) >= 4 { InstallOptionalHaikuImagePackage - beam-1.2alpha-x86-gcc4-2012-08-11.zip - : $(baseURL)/beam-1.2alpha-x86-gcc4-2012-08-11.zip ; + beam-1.2alpha-r1a4-x86-gcc4-2012-09-12.zip + : $(baseURL)/beam-1.2alpha-r1a4-x86-gcc4-2012-09-12.zip ; } else { InstallOptionalHaikuImagePackage beam-1.2alpha-r1a4-x86-gcc2-2012-08-29.zip @@ -1792,8 +1792,8 @@ if [ IsOptionalHaikuImagePackageAdded Transmission ] { } else { if $(HAIKU_GCC_VERSION[1]) >= 4 { InstallOptionalHaikuImagePackage - transmission-2.21-r1a4-x86-gcc4-2012-09-03.zip - : $(baseURL)/transmission-2.21-r1a4-x86-gcc4-2012-09-03.zip + transmission-2.21-r1a4-x86-gcc4-2012-09-12.zip + : $(baseURL)/transmission-2.21-r1a4-x86-gcc4-2012-09-12.zip : : true ; } else { InstallOptionalHaikuImagePackage From 267b64639698c8aaca919137b8d65803abc1b026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 12 Sep 2012 20:20:43 +0200 Subject: [PATCH 05/23] Run the transaction flusher in another thread. * This fixes bug #8977. --- src/add-ons/kernel/file_systems/bfs/Journal.cpp | 14 ++++++++++++-- src/add-ons/kernel/file_systems/bfs/Journal.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Journal.cpp b/src/add-ons/kernel/file_systems/bfs/Journal.cpp index f1a1f74a2a..473ad284ca 100644 --- a/src/add-ons/kernel/file_systems/bfs/Journal.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Journal.cpp @@ -684,10 +684,20 @@ Journal::_TransactionWritten(int32 transactionID, int32 event, void* _logEntry) /*static*/ void Journal::_TransactionIdle(int32 transactionID, int32 event, void* _journal) { - // The current transaction seems to be idle - flush it + // The current transaction seems to be idle - flush it. We can't do this + // in this thread, as flushing the log can produce new transaction events. + thread_id id = spawn_kernel_thread(&Journal::_FlushLog, "bfs log flusher", + B_NORMAL_PRIORITY, _journal); + if (id > 0) + resume_thread(id); +} + +/*static*/ status_t +Journal::_FlushLog(void* _journal) +{ Journal* journal = (Journal*)_journal; - journal->_FlushLog(false, false); + return journal->_FlushLog(false, false); } diff --git a/src/add-ons/kernel/file_systems/bfs/Journal.h b/src/add-ons/kernel/file_systems/bfs/Journal.h index c128a96c2b..6e22ad0a81 100644 --- a/src/add-ons/kernel/file_systems/bfs/Journal.h +++ b/src/add-ons/kernel/file_systems/bfs/Journal.h @@ -60,7 +60,9 @@ private: int32 event, void* _logEntry); static void _TransactionIdle(int32 transactionID, int32 event, void* _journal); + static status_t _FlushLog(void* _journal); +private: Volume* fVolume; recursive_lock fLock; Transaction* fOwner; From ce14ea0c3ef9cf1b10617b8ffcb06428bffe3739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 12 Sep 2012 21:47:59 +0200 Subject: [PATCH 06/23] DevelopmentMin optional package: add 3rdparty headers * Add freetype, libpng and jpeg headers --- build/jam/OptionalPackages | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/build/jam/OptionalPackages b/build/jam/OptionalPackages index 9126624165..bb22b8dfa5 100644 --- a/build/jam/OptionalPackages +++ b/build/jam/OptionalPackages @@ -846,6 +846,13 @@ if [ IsOptionalHaikuImagePackageAdded DevelopmentMin ] && $(TARGET_ARCH) = x86 { AddHeaderDirectoryToHaikuImage libs tiff : 3rdparty ; AddHeaderDirectoryToHaikuImage libs zlib : 3rdparty ; + CopyDirectoryToHaikuImage develop headers : + [ FDirName $(HAIKU_FREETYPE_DIR) develop headers 3rdparty ] ; + CopyDirectoryToHaikuImage develop headers : $(HAIKU_JPEG_HEADERS) + : 3rdparty ; + CopyDirectoryToHaikuImage develop headers : $(HAIKU_LIBPNG_HEADERS) + : 3rdparty ; + # cpp headers if $(HAIKU_GCC_VERSION[1]) = 2 { # GCC 2 only -- for GCC 4 they come with the DevelopmentBase package From 8e77147bfce3972e04659cf424084f6342c2cc34 Mon Sep 17 00:00:00 2001 From: Scott McCreary Date: Wed, 12 Sep 2012 22:47:08 -0700 Subject: [PATCH 07/23] Rebuilt some more packages mostly to fix directory issues. --- build/jam/OptionalLibPackages | 16 ++++++++-------- build/jam/OptionalPackages | 16 ++++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/build/jam/OptionalLibPackages b/build/jam/OptionalLibPackages index 0b329920e9..a72774aa65 100644 --- a/build/jam/OptionalLibPackages +++ b/build/jam/OptionalLibPackages @@ -48,14 +48,14 @@ if [ IsOptionalHaikuImagePackageAdded AllegroLibs ] { : $(baseURL)/lib/jgmod-0.99-r1a4-x86-gcc4-2012-09-09.zip ; } else { InstallOptionalHaikuImagePackage - allegro-4.4.1.1-r1a3-x86-gcc2-2011-05-19.zip - : $(baseURL)/lib/allegro-4.4.1.1-r1a3-x86-gcc2-2011-05-19.zip ; + allegro-4.4.1.1-r1a4-x86-gcc2-2012-08-30.zip + : $(baseURL)/lib/allegro-4.4.1.1-r1a4-x86-gcc2-2012-08-30.zip ; InstallOptionalHaikuImagePackage - dumb-0.9.3-x86-r1a3-x86-gcc2-2011-05-19.zip - : $(baseURL)/lib/dumb-0.9.3-r1a3-x86-gcc2-2011-05-19.zip ; + dumb-0.9.3-r1a4-x86-gcc2-2012-08-30.zip + : $(baseURL)/lib/dumb-0.9.3-r1a4-x86-gcc2-2012-08-30.zip ; InstallOptionalHaikuImagePackage - jgmod-0.99-x86-gcc2-2011-08-02.zip - : $(baseURL)/lib/jgmod-0.99-x86-gcc2-2011-08-02.zip ; + jgmod-0.99-r1a4-x86-gcc2-2012-08-30.zip + : $(baseURL)/lib/jgmod-0.99-r1a4-x86-gcc2-2012-08-30.zip ; } } @@ -214,8 +214,8 @@ if [ IsOptionalHaikuImagePackageAdded physfs ] { : : true ; } else { InstallOptionalHaikuImagePackage - physfs-2.0.1-r1a3-x86-gcc2-2011-05-19.zip - : $(baseURL)/lib/physfs-2.0.1-r1a3-x86-gcc2-2011-05-19.zip + physfs-2.0.1-r1a4-x86-gcc2-2012-08-29.zip + : $(baseURL)/lib/physfs-2.0.1-r1a4-x86-gcc2-2012-08-29.zip : : true ; } } diff --git a/build/jam/OptionalPackages b/build/jam/OptionalPackages index bb22b8dfa5..e057a1dd9e 100644 --- a/build/jam/OptionalPackages +++ b/build/jam/OptionalPackages @@ -905,8 +905,8 @@ if [ IsOptionalHaikuImagePackageAdded Doxygen ] { } else { if $(HAIKU_GCC_VERSION[1]) >= 4 { InstallOptionalHaikuImagePackage - doxygen-1.6.3-x86-gcc4-2010-05-17.zip - : $(baseURL)/doxygen-1.6.3-x86-gcc4-2010-05-17.zip + doxygen-1.6.3-r1a4-x86-gcc4-2012-09-04.zip + : $(baseURL)/doxygen-1.6.3-r1a4-x86-gcc4-2012-09-04.zip : : true ; } else { InstallOptionalHaikuImagePackage @@ -961,8 +961,8 @@ if [ IsOptionalHaikuImagePackageAdded friss ] { } else { if $(HAIKU_GCC_VERSION[1]) >= 4 { InstallOptionalHaikuImagePackage - friss-24-r1a3-x86-gcc4-2011-05-31.zip - : $(baseURL)/friss-24-r1a3-x86-gcc4-2011-05-31.zip ; + friss-29-r1a4-x86-gcc4-2012-09-09.zip + : $(baseURL)/friss-29-r1a4-x86-gcc4-2012-09-09.zip ; } else { InstallOptionalHaikuImagePackage friss-29-r1a4-x86-gcc2-2012-08-28.zip @@ -1664,8 +1664,8 @@ if [ IsOptionalHaikuImagePackageAdded Rsync ] { : : true ; } else { InstallOptionalHaikuImagePackage - rsync-3.0.7-r1a4-x86-gcc2-2012-08-29.zip - : $(baseURL)/rsync-3.0.7-r1a4-x86-gcc2-2012-08-29.zip + rsync-3.0.7-r1a4-x86-gcc2-2012-09-12.zip + : $(baseURL)/rsync-3.0.7-r1a4-x86-gcc2-2012-09-12.zip : : true ; } } @@ -1804,8 +1804,8 @@ if [ IsOptionalHaikuImagePackageAdded Transmission ] { : : true ; } else { InstallOptionalHaikuImagePackage - transmission-2.21-r1a4-x86-gcc2-2012-08-30.zip - : $(baseURL)/transmission-2.21-r1a4-x86-gcc2-2012-08-30.zip + transmission-2.21-r1a4-x86-gcc2-2012-09-05.zip + : $(baseURL)/transmission-2.21-r1a4-x86-gcc2-2012-09-05.zip : : true ; } } From 517a59c9a1dd1df14944e61474af62c945af3a31 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Thu, 13 Sep 2012 09:30:28 +0200 Subject: [PATCH 08/23] Make a void * pointer const. --- .../media/plugins/aiff_reader/aiff_reader.cpp | 8 ++++---- .../media/plugins/aiff_reader/aiff_reader.h | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/add-ons/media/plugins/aiff_reader/aiff_reader.cpp b/src/add-ons/media/plugins/aiff_reader/aiff_reader.cpp index 310afcd0a7..3e2dc5836f 100644 --- a/src/add-ons/media/plugins/aiff_reader/aiff_reader.cpp +++ b/src/add-ons/media/plugins/aiff_reader/aiff_reader.cpp @@ -405,15 +405,15 @@ aiffReader::GetNextChunk(void *cookie, } uint32 -aiffReader::DecodeFrameRate(void *_80bit_float) +aiffReader::DecodeFrameRate(const void *_80bit_float) { // algorithm from http://www.borg.com/~jglatt/tech/aiff.htm uint32 mantissa; uint32 last; uint32 exp; - - mantissa = (uint32)B_BENDIAN_TO_HOST_INT32(*(uint32 *)((char *)_80bit_float + 2)); - exp = 30 - *(uint8 *)((char *)_80bit_float + 1); + + mantissa = (uint32)B_BENDIAN_TO_HOST_INT32(*(const uint32 *)((const char *)_80bit_float + 2)); + exp = 30 - *(const uint8 *)((const char *)_80bit_float + 1); if (exp > 32) return 0; last = 0; diff --git a/src/add-ons/media/plugins/aiff_reader/aiff_reader.h b/src/add-ons/media/plugins/aiff_reader/aiff_reader.h index 6f1aeae565..097c270e1d 100644 --- a/src/add-ons/media/plugins/aiff_reader/aiff_reader.h +++ b/src/add-ons/media/plugins/aiff_reader/aiff_reader.h @@ -33,16 +33,16 @@ class aiffReader : public Reader public: aiffReader(); ~aiffReader(); - + const char *Copyright(); - + status_t Sniff(int32 *streamCount); void GetFileFormatInfo(media_file_format *mff); status_t AllocateCookie(int32 streamNumber, void **cookie); status_t FreeCookie(void *cookie); - + status_t GetStreamInfo(void *cookie, int64 *frameCount, bigtime_t *duration, media_format *format, const void **infoBuffer, size_t *infoSize); @@ -54,20 +54,20 @@ public: const void **chunkBuffer, size_t *chunkSize, media_header *mediaHeader); private: - uint32 DecodeFrameRate(void *_80bit_float); - + uint32 DecodeFrameRate(const void *_80bit_float); + BPositionIO *Source() { return fSource; } - + private: BPositionIO * fSource; - + media_format fFormat; int64 fDataStart; int64 fDataSize; int64 fFrameCount; bigtime_t fDuration; - + bool fRaw; int64 fPosition; From f78dd1249a1c71736fc7725db6b955d2fa6d3ff0 Mon Sep 17 00:00:00 2001 From: Alexander von Gluck IV Date: Thu, 13 Sep 2012 11:10:42 -0500 Subject: [PATCH 09/23] VM Preflet: Use AutoDeleter on the settings * Prevents a minor memory leak * Thanks for catching this Axel! --- src/preferences/virtualmemory/Settings.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/preferences/virtualmemory/Settings.cpp b/src/preferences/virtualmemory/Settings.cpp index 08f6102607..9b9b21fdb8 100644 --- a/src/preferences/virtualmemory/Settings.cpp +++ b/src/preferences/virtualmemory/Settings.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -138,6 +139,8 @@ Settings::ReadSwapSettings() void* settings = load_driver_settings(kVirtualMemorySettings); if (settings == NULL) return kErrorSettingsNotFound; + CObjectDeleter settingDeleter(settings, + &unload_driver_settings); const char* enabled = get_driver_parameter(settings, "vm", NULL, NULL); const char* automatic = get_driver_parameter(settings, "swap_auto", From 4f444fab2e0cd1c0c5f5212fda1e758eab55bc7d Mon Sep 17 00:00:00 2001 From: Scott McCreary Date: Thu, 13 Sep 2012 20:09:01 -0700 Subject: [PATCH 10/23] Add OptionalPackage Nanumfont, a Korean monospace font --- build/jam/OptionalPackages | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build/jam/OptionalPackages b/build/jam/OptionalPackages index e057a1dd9e..b1b541b1af 100644 --- a/build/jam/OptionalPackages +++ b/build/jam/OptionalPackages @@ -68,6 +68,7 @@ if $(HAIKU_ADD_ALTERNATIVE_GCC_LIBS) = 1 # Man - standard commands to read man pages # Mercurial - the distributed version control system # Nano - the command line text editor +# Nanumfont - Korean monospace font # Neon - support libraries used for example by SVN # NetFS - the native networked file system components # NetSurf - the web browser @@ -1376,6 +1377,14 @@ if [ IsOptionalHaikuImagePackageAdded Nano ] { } +# Nanumfont +if [ IsOptionalHaikuImagePackageAdded Nanumfont ] { + InstallOptionalHaikuImagePackage + nanumfont-2.0-r1a4-x86-gcc2-2012-09-12.zip + : $(baseURL)/nanumfont-2.0-r1a4-x86-gcc2-2012-09-12.zip ; +} + + # Neon if [ IsOptionalHaikuImagePackageAdded Neon ] { if $(TARGET_ARCH) != x86 { From c2ff7a30e31ff4d78e5db198dc29e96c7db0ac63 Mon Sep 17 00:00:00 2001 From: Scott McCreary Date: Thu, 13 Sep 2012 20:25:40 -0700 Subject: [PATCH 11/23] Add OptionalPackage Droid, font from Google's Android project --- build/jam/OptionalPackages | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build/jam/OptionalPackages b/build/jam/OptionalPackages index b1b541b1af..9541517d35 100644 --- a/build/jam/OptionalPackages +++ b/build/jam/OptionalPackages @@ -45,6 +45,7 @@ if $(HAIKU_ADD_ALTERNATIVE_GCC_LIBS) = 1 # DevelopmentMin - development headers, libs, tools, from sources only # DevelopmentPowerPC - Cross compiling environment for PowerPC # Doxygen - Generate documentation from source code +# Droid - Font family from Google's Android project # Expat - XML parsing libraries # Fastdep - fast dependency generator for C/C++ files # friss - RSS/ATOM/... feeds reader @@ -919,6 +920,14 @@ if [ IsOptionalHaikuImagePackageAdded Doxygen ] { } +# Droid +if [ IsOptionalHaikuImagePackageAdded Droid ] { + InstallOptionalHaikuImagePackage + droid-113-r1a4-x86-gcc2-2012-08-27.zip + : $(baseURL)/droid-113-r1a4-x86-gcc2-2012-08-27.zip ; +} + + # Expat if [ IsOptionalHaikuImagePackageAdded Expat ] { if $(TARGET_ARCH) != x86 { From 863a181c0bb346b2494c4815d31d21c8dc355bea Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Fri, 14 Sep 2012 18:16:51 +0200 Subject: [PATCH 12/23] make sure there are no pending interrupts during setup --- .../kernel/busses/scsi/ahci/ahci_controller.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp index 24ded54f21..311825f88b 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp @@ -122,6 +122,10 @@ AHCIController::Init() return B_ERROR; } + // make sure interrupts are disabled + fRegs->ghc &= ~GHC_IE; + FlushPostedWrites(); + if (ResetController() < B_OK) { TRACE("controller reset failed\n"); goto err; @@ -194,6 +198,12 @@ AHCIController::Init() } } + // clear any pending interrupts + uint32 interruptsPending; + interruptsPending = fRegs->is; + fRegs->is = interruptsPending; + FlushPostedWrites(); + // enable interrupts fRegs->ghc |= GHC_IE; FlushPostedWrites(); From 6c9f2e94e7c3aba5b34ca9970fdfbf04ac0a3913 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Fri, 14 Sep 2012 18:19:11 +0200 Subject: [PATCH 13/23] set GHC.AE before performing reset (should be done by BIOS already) --- src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp index 311825f88b..cf60573018 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp @@ -266,6 +266,10 @@ AHCIController::ResetController() uint32 saveCaps = fRegs->cap & (CAP_SMPS | CAP_SSS | CAP_SPM | CAP_EMS | CAP_SXS); uint32 savePI = fRegs->pi; + // AHCI 1.3: Software may perform an HBA reset prior to initializing the controller + // by setting GHC.AE to ‘1’ and then setting GHC.HR to ‘1’ if desired. + fRegs->ghc |= GHC_AE; + FlushPostedWrites(); fRegs->ghc |= GHC_HR; FlushPostedWrites(); if (wait_until_clear(&fRegs->ghc, GHC_HR, 1000000) < B_OK) From 0d73f6ec8a4a4d2359d2b26882f74ed699a03727 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Fri, 14 Sep 2012 18:31:01 +0200 Subject: [PATCH 14/23] properly check intel port count and don't panic on more than 8. --- src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp index cf60573018..e23cddc3cc 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp @@ -284,9 +284,12 @@ AHCIController::ResetController() if (fPCIVendorID == PCI_VENDOR_INTEL) { // Intel PCS—Port Control and Status // SATA port enable bits must be set - int portCount = 1 + ((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK); - if (portCount > 8) - panic("Intel AHCI: too many SATA ports! Please report at http://dev.haiku-os.org"); + int portCount = max_c(fls(fRegs->pi), 1 + ((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK)); + if (portCount > 8) { + // TODO: fix this when specification available + TRACE("don't know how to enable SATA ports 9 to %d\n", portCount); + portCount = 8; + } uint16 pcs = fPCI->read_pci_config(fPCIDevice, 0x92, 2); pcs |= (0xff >> (8 - portCount)); fPCI->write_pci_config(fPCIDevice, 0x92, 2, pcs); From a63b046e90d48e47b2b88a519057b43344976f90 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Fri, 14 Sep 2012 18:42:00 +0200 Subject: [PATCH 15/23] add missing line breaks in debug output --- src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp | 6 +++--- src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp index e23cddc3cc..3612f156b3 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp @@ -186,12 +186,12 @@ AHCIController::Init() if (fPortImplementedMask & (1 << i)) { fPort[i] = new (std::nothrow)AHCIPort(this, i); if (!fPort[i]) { - TRACE("out of memory creating port %d", i); + TRACE("out of memory creating port %d\n", i); break; } status_t status = fPort[i]->Init1(); if (status < B_OK) { - TRACE("init-1 port %d failed", i); + TRACE("init-1 port %d failed\n", i); delete fPort[i]; fPort[i] = NULL; } @@ -212,7 +212,7 @@ AHCIController::Init() if (fPort[i]) { status_t status = fPort[i]->Init2(); if (status < B_OK) { - TRACE("init-2 port %d failed", i); + TRACE("init-2 port %d failed\n", i); fPort[i]->Uninit(); delete fPort[i]; fPort[i] = NULL; diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp index c4e41848e4..7cc78c1bca 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp @@ -398,12 +398,12 @@ AHCIPort::InterruptErrorHandler(uint32 is) TRACE("Interface Non Fatal Error\n"); } if (is & PORT_INT_OF) { - TRACE("Overflow"); + TRACE("Overflow\n"); fResetPort = true; fError = true; } if (is & PORT_INT_IPM) { - TRACE("Incorrect Port Multiplier Status"); + TRACE("Incorrect Port Multiplier Status\n"); } if (is & PORT_INT_PRC) { TRACE("PhyReady Change\n"); From 2f0f9d8780ed3f7ec4804f2aba568868f75251f3 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Fri, 14 Sep 2012 18:56:56 +0200 Subject: [PATCH 16/23] cleanup variable naming for port count --- .../busses/scsi/ahci/ahci_controller.cpp | 31 +++++++++---------- .../kernel/busses/scsi/ahci/ahci_controller.h | 3 +- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp index 3612f156b3..ab0bb0b3d3 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp @@ -25,8 +25,7 @@ AHCIController::AHCIController(device_node *node, fPCIDeviceID(0xffff), fFlags(0), fCommandSlotCount(0), - fPortCountMax(0), - fPortCountAvail(0), + fPortCount(0), fPortImplementedMask(0), fIRQ(0), fInstanceCheck(-1) @@ -132,29 +131,27 @@ AHCIController::Init() } fCommandSlotCount = 1 + ((fRegs->cap >> CAP_NCS_SHIFT) & CAP_NCS_MASK); - fPortCountMax = 1 + ((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK); + fPortCount = 1 + ((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK); fPortImplementedMask = fRegs->pi; // reported mask of implemented ports is sometimes empty if (fPortImplementedMask == 0) { - fPortImplementedMask = 0xffffffff >> (32 - fPortCountMax); + fPortImplementedMask = 0xffffffff >> (32 - fPortCount); TRACE("ports-implemented mask is zero, using 0x%" B_PRIx32 " instead.\n", fPortImplementedMask); } // reported number of ports is sometimes too small - int maxPortIndex; - maxPortIndex = fls(fPortImplementedMask); - if (fPortCountMax < maxPortIndex) { - TRACE("reported number of ports is wrong, using %d instead.\n", maxPortIndex); - fPortCountMax = maxPortIndex; + int highestPort; + highestPort = fls(fPortImplementedMask); // 1-based, 1 to 32 + if (fPortCount < highestPort) { + TRACE("reported number of ports is wrong, using %d instead.\n", highestPort); + fPortCount = highestPort; } - fPortCountAvail = count_bits_set(fPortImplementedMask); - TRACE("cap: Interface Speed Support: generation %" B_PRIu32 "\n", (fRegs->cap >> CAP_ISS_SHIFT) & CAP_ISS_MASK); TRACE("cap: Number of Command Slots: %d (raw %#" B_PRIx32 ")\n", fCommandSlotCount, (fRegs->cap >> CAP_NCS_SHIFT) & CAP_NCS_MASK); - TRACE("cap: Number of Ports: %d (raw %#" B_PRIx32 ")\n", fPortCountMax, (fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK); + TRACE("cap: Number of Ports: %d (raw %#" B_PRIx32 ")\n", fPortCount, (fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK); TRACE("cap: Supports Port Multiplier: %s\n", (fRegs->cap & CAP_SPM) ? "yes" : "no"); TRACE("cap: Supports External SATA: %s\n", (fRegs->cap & CAP_SXS) ? "yes" : "no"); TRACE("cap: Enclosure Management Supported: %s\n", (fRegs->cap & CAP_EMS) ? "yes" : "no"); @@ -172,7 +169,7 @@ AHCIController::Init() TRACE("cap: Supports AHCI mode only: %s\n", (fRegs->cap & CAP_SAM) ? "yes" : "no"); TRACE("ghc: AHCI Enable: %s\n", (fRegs->ghc & GHC_AE) ? "yes" : "no"); TRACE("Ports Implemented Mask: %#08" B_PRIx32 "\n", fPortImplementedMask); - TRACE("Number of Available Ports: %d\n", fPortCountAvail); + TRACE("Number of Available Ports: %d\n", count_bits_set(fPortImplementedMask)); TRACE("AHCI Version %" B_PRIu32 ".%" B_PRIu32 "\n", fRegs->vs >> 16, fRegs->vs & 0xff); TRACE("Interrupt %u\n", fIRQ); @@ -182,7 +179,7 @@ AHCIController::Init() goto err; } - for (int i = 0; i < fPortCountMax; i++) { + for (int i = 0; i < fPortCount; i++) { if (fPortImplementedMask & (1 << i)) { fPort[i] = new (std::nothrow)AHCIPort(this, i); if (!fPort[i]) { @@ -208,7 +205,7 @@ AHCIController::Init() fRegs->ghc |= GHC_IE; FlushPostedWrites(); - for (int i = 0; i < fPortCountMax; i++) { + for (int i = 0; i < fPortCount; i++) { if (fPort[i]) { status_t status = fPort[i]->Init2(); if (status < B_OK) { @@ -234,7 +231,7 @@ AHCIController::Uninit() { TRACE("AHCIController::Uninit\n"); - for (int i = 0; i < fPortCountMax; i++) { + for (int i = 0; i < fPortCount; i++) { if (fPort[i]) { fPort[i]->Uninit(); delete fPort[i]; @@ -307,7 +304,7 @@ AHCIController::Interrupt(void *data) if (interruptPending == 0) return B_UNHANDLED_INTERRUPT; - for (int i = 0; i < self->fPortCountMax; i++) { + for (int i = 0; i < self->fPortCount; i++) { if (interruptPending & (1 << i)) { if (self->fPort[i]) { self->fPort[i]->Interrupt(); diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.h b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.h index 9fd2a6b415..c973d41cb6 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.h +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.h @@ -49,8 +49,7 @@ private: volatile ahci_hba * fRegs; area_id fRegsArea; int fCommandSlotCount; - int fPortCountMax; - int fPortCountAvail; + int fPortCount; uint32 fPortImplementedMask; uint8 fIRQ; AHCIPort * fPort[32]; From 87b33446e13a699d703d4c1678d0fe91901a2e98 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Fri, 14 Sep 2012 19:29:34 +0200 Subject: [PATCH 17/23] gcc2 compile fix (gcc4 didn't complain) --- src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp index ab0bb0b3d3..0d7655aa9f 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp @@ -281,7 +281,7 @@ AHCIController::ResetController() if (fPCIVendorID == PCI_VENDOR_INTEL) { // Intel PCS—Port Control and Status // SATA port enable bits must be set - int portCount = max_c(fls(fRegs->pi), 1 + ((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK)); + int portCount = max_c(fls(fRegs->pi), 1 + (int)((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK)); if (portCount > 8) { // TODO: fix this when specification available TRACE("don't know how to enable SATA ports 9 to %d\n", portCount); From 1f6d0a79c927877cdf2aa5a6c6475a2488090f5f Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Fri, 14 Sep 2012 20:20:29 +0200 Subject: [PATCH 18/23] use template max() instead of max_c() macro --- src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp index 0d7655aa9f..b5ed575812 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_controller.cpp @@ -6,6 +6,7 @@ #include "ahci_controller.h" #include "util.h" +#include #include #include #include @@ -281,7 +282,7 @@ AHCIController::ResetController() if (fPCIVendorID == PCI_VENDOR_INTEL) { // Intel PCS—Port Control and Status // SATA port enable bits must be set - int portCount = max_c(fls(fRegs->pi), 1 + (int)((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK)); + int portCount = std::max(fls(fRegs->pi), 1 + (int)((fRegs->cap >> CAP_NP_SHIFT) & CAP_NP_MASK)); if (portCount > 8) { // TODO: fix this when specification available TRACE("don't know how to enable SATA ports 9 to %d\n", portCount); From 3c5216179e02f3b711bbac9c021f821ad3628cc7 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Fri, 14 Sep 2012 22:21:47 +0200 Subject: [PATCH 19/23] implement support for harddisks bigger than 2TB * can't test this, it's untested, but similar to ATADevice.cpp * should no longer panic when hdd > 2TB is connected * fix request completition in two error cases * add const to some parameters --- .../kernel/busses/scsi/ahci/ahci_port.cpp | 72 ++++++++++++++++--- .../kernel/busses/scsi/ahci/ahci_port.h | 1 + 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp index 7cc78c1bca..85e4403775 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.cpp @@ -548,7 +548,7 @@ AHCIPort::ScsiInquiry(scsi_ccb *request) { TRACE("AHCIPort::ScsiInquiry port %d\n", fIndex); - scsi_cmd_inquiry *cmd = (scsi_cmd_inquiry *)request->cdb; + const scsi_cmd_inquiry *cmd = (const scsi_cmd_inquiry *)request->cdb; scsi_res_inquiry scsiData; ata_device_infoblock ataData; @@ -679,22 +679,50 @@ AHCIPort::ScsiReadCapacity(scsi_ccb *request) { TRACE("AHCIPort::ScsiReadCapacity port %d\n", fIndex); - scsi_cmd_read_capacity *cmd = (scsi_cmd_read_capacity *)request->cdb; + const scsi_cmd_read_capacity *cmd = (const scsi_cmd_read_capacity *)request->cdb; scsi_res_read_capacity scsiData; if (cmd->pmi || cmd->lba || request->data_length < sizeof(scsiData)) { TRACE("invalid request\n"); + request->subsys_status = SCSI_REQ_ABORTED; + gSCSI->finished(request, 1); return; } TRACE("SectorSize %" B_PRIu32 ", SectorCount 0x%" B_PRIx64 "\n", fSectorSize, fSectorCount); - if (fSectorCount > 0xffffffff) - panic("ahci: SCSI emulation doesn't support harddisks larger than 2TB"); + scsiData.block_size = B_HOST_TO_BENDIAN_INT32(fSectorSize); + + if (fSectorCount <= 0xffffffff) + scsiData.lba = B_HOST_TO_BENDIAN_INT32(fSectorCount - 1); + else + scsiData.lba = 0xffffffff; + + if (sg_memcpy(request->sg_list, request->sg_count, &scsiData, + sizeof(scsiData)) < B_OK) { + request->subsys_status = SCSI_DATA_RUN_ERR; + } else { + request->subsys_status = SCSI_REQ_CMP; + request->data_resid = request->data_length - sizeof(scsiData); + } + gSCSI->finished(request, 1); +} + + +void +AHCIPort::ScsiReadCapacity16(scsi_ccb *request) +{ + TRACE("AHCIPort::ScsiReadCapacity16 port %d\n", fIndex); + + //const scsi_cmd_read_capacity_long *cmd = (const scsi_cmd_read_capacity_long *)request->cdb; + scsi_res_read_capacity_long scsiData; + + TRACE("SectorSize %" B_PRIu32 ", SectorCount 0x%" B_PRIx64 "\n", + fSectorSize, fSectorCount); scsiData.block_size = B_HOST_TO_BENDIAN_INT32(fSectorSize); - scsiData.lba = B_HOST_TO_BENDIAN_INT32(fSectorCount - 1); + scsiData.lba = B_HOST_TO_BENDIAN_INT64(fSectorCount - 1); if (sg_memcpy(request->sg_list, request->sg_count, &scsiData, sizeof(scsiData)) < B_OK) { @@ -731,6 +759,7 @@ AHCIPort::ScsiReadWrite(scsi_ccb *request, uint64 lba, size_t sectorCount, TRACE("out of memory when allocating read/write request\n"); request->subsys_status = SCSI_REQ_ABORTED; gSCSI->finished(request, 1); + return; } if (fUse48BitCommands) { @@ -914,13 +943,21 @@ AHCIPort::ScsiExecuteRequest(scsi_ccb *request) case SCSI_OP_READ_CAPACITY: ScsiReadCapacity(request); break; + case SCSI_OP_SERVICE_ACTION_IN: + if ((request->cdb[1] & 0x1f) == SCSI_SAI_READ_CAPACITY_16) + ScsiReadCapacity16(request); + else { + request->subsys_status = SCSI_REQ_INVALID; + gSCSI->finished(request, 1); + } + break; case SCSI_OP_SYNCHRONIZE_CACHE: ScsiSynchronizeCache(request); break; case SCSI_OP_READ_6: case SCSI_OP_WRITE_6: { - scsi_cmd_rw_6 *cmd = (scsi_cmd_rw_6 *)request->cdb; + const scsi_cmd_rw_6 *cmd = (const scsi_cmd_rw_6 *)request->cdb; uint32 position = ((uint32)cmd->high_lba << 16) | ((uint32)cmd->mid_lba << 8) | (uint32)cmd->low_lba; size_t length = cmd->length != 0 ? cmd->length : 256; @@ -931,7 +968,7 @@ AHCIPort::ScsiExecuteRequest(scsi_ccb *request) case SCSI_OP_READ_10: case SCSI_OP_WRITE_10: { - scsi_cmd_rw_10 *cmd = (scsi_cmd_rw_10 *)request->cdb; + const scsi_cmd_rw_10 *cmd = (const scsi_cmd_rw_10 *)request->cdb; uint32 position = B_BENDIAN_TO_HOST_INT32(cmd->lba); size_t length = B_BENDIAN_TO_HOST_INT16(cmd->length); bool isWrite = request->cdb[0] == SCSI_OP_WRITE_10; @@ -948,7 +985,7 @@ AHCIPort::ScsiExecuteRequest(scsi_ccb *request) case SCSI_OP_READ_12: case SCSI_OP_WRITE_12: { - scsi_cmd_rw_12 *cmd = (scsi_cmd_rw_12 *)request->cdb; + const scsi_cmd_rw_12 *cmd = (const scsi_cmd_rw_12 *)request->cdb; uint32 position = B_BENDIAN_TO_HOST_INT32(cmd->lba); size_t length = B_BENDIAN_TO_HOST_INT32(cmd->length); bool isWrite = request->cdb[0] == SCSI_OP_WRITE_12; @@ -962,9 +999,26 @@ AHCIPort::ScsiExecuteRequest(scsi_ccb *request) } break; } + case SCSI_OP_READ_16: + case SCSI_OP_WRITE_16: + { + const scsi_cmd_rw_16 *cmd = (const scsi_cmd_rw_16 *)request->cdb; + uint64 position = B_BENDIAN_TO_HOST_INT64(cmd->lba); + size_t length = B_BENDIAN_TO_HOST_INT32(cmd->length); + bool isWrite = request->cdb[0] == SCSI_OP_WRITE_16; + if (length) { + ScsiReadWrite(request, position, length, isWrite); + } else { + TRACE("AHCIPort::ScsiExecuteRequest error: transfer without " + "data!\n"); + request->subsys_status = SCSI_REQ_INVALID; + gSCSI->finished(request, 1); + } + break; + } case SCSI_OP_WRITE_SAME_16: { - scsi_cmd_wsame_16 *cmd = (scsi_cmd_wsame_16 *)request->cdb; + const scsi_cmd_wsame_16 *cmd = (const scsi_cmd_wsame_16 *)request->cdb; // SCSI unmap is used for trim, otherwise we don't support it if (!cmd->unmap) { diff --git a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.h b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.h index 42b8e6bd00..962e5f7c4b 100644 --- a/src/add-ons/kernel/busses/scsi/ahci/ahci_port.h +++ b/src/add-ons/kernel/busses/scsi/ahci/ahci_port.h @@ -33,6 +33,7 @@ private: void ScsiTestUnitReady(scsi_ccb *request); void ScsiInquiry(scsi_ccb *request); void ScsiReadCapacity(scsi_ccb *request); + void ScsiReadCapacity16(scsi_ccb *request); void ScsiReadWrite(scsi_ccb *request, uint64 lba, size_t sectorCount, bool isWrite); void ScsiSynchronizeCache(scsi_ccb *request); From 4a2ac3c2acae527eedef53c9f28ee9b51a385661 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Sat, 15 Sep 2012 01:22:34 +0200 Subject: [PATCH 20/23] Fix size parameter for ioctl. --- src/bin/mkdos/mkdos.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bin/mkdos/mkdos.cpp b/src/bin/mkdos/mkdos.cpp index 8ab86afa05..3ca3323b51 100644 --- a/src/bin/mkdos/mkdos.cpp +++ b/src/bin/mkdos/mkdos.cpp @@ -164,11 +164,11 @@ status_t Initialize(int fatbits, const char *device, const char *label, bool nop device_geometry biosGeometry; device_geometry deviceGeometry; partition_info partitionInfo; - + isRawDevice = 0 != strstr(device, "/raw"); - hasBiosGeometry = B_OK == ioctl(fd, B_GET_BIOS_GEOMETRY, &biosGeometry); - hasDeviceGeometry = B_OK == ioctl(fd, B_GET_GEOMETRY, &deviceGeometry); - hasPartitionInfo = B_OK == ioctl(fd, B_GET_PARTITION_INFO, &partitionInfo); + hasBiosGeometry = B_OK == ioctl(fd, B_GET_BIOS_GEOMETRY, &biosGeometry, sizeof(biosGeometry)); + hasDeviceGeometry = B_OK == ioctl(fd, B_GET_GEOMETRY, &deviceGeometry, sizeof(deviceGeometry)); + hasPartitionInfo = B_OK == ioctl(fd, B_GET_PARTITION_INFO, &partitionInfo, sizeof(partitionInfo)); if (!isRawDevice && !hasBiosGeometry && !hasDeviceGeometry && !hasPartitionInfo) isRawDevice = true; From 721d056e11263bcb58f155eb0203d0689da22f47 Mon Sep 17 00:00:00 2001 From: Ryan Leavengood Date: Sat, 15 Sep 2012 00:19:42 -0400 Subject: [PATCH 21/23] Don't call unload_driver_settings twice. Thanks Hamish. --- src/preferences/virtualmemory/Settings.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/preferences/virtualmemory/Settings.cpp b/src/preferences/virtualmemory/Settings.cpp index 9b9b21fdb8..c326e36c7e 100644 --- a/src/preferences/virtualmemory/Settings.cpp +++ b/src/preferences/virtualmemory/Settings.cpp @@ -166,7 +166,6 @@ Settings::ReadSwapSettings() SetSwapAutomatic(get_driver_boolean_parameter(settings, "swap_auto", true, false)); SetSwapSize(atoll(size)); - unload_driver_settings(settings); int32 bestScore = -1; dev_t bestVol = -1; From ed5e4ee4280b3481c36365c49ec64d17d6e0a913 Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Sat, 15 Sep 2012 12:38:38 +0200 Subject: [PATCH 22/23] also print partition info --- src/bin/driveinfo.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/src/bin/driveinfo.c b/src/bin/driveinfo.c index c2a96d27e2..84a2a0278c 100644 --- a/src/bin/driveinfo.c +++ b/src/bin/driveinfo.c @@ -13,7 +13,6 @@ static void dump_dev_size(int dev) return; } printf("size: %ld bytes\n", sz); - puts(""); } static void dump_bios_id(int dev) @@ -24,7 +23,6 @@ static void dump_bios_id(int dev) return; } printf("bios id: %d, 0x%x\n", id, id); - puts(""); } static void dump_media_status(int dev) @@ -35,7 +33,6 @@ static void dump_media_status(int dev) return; } printf("media status: %s\n", strerror(st)); - puts(""); } static const char *device_type(uint32 type) @@ -70,7 +67,23 @@ static void dump_geom(int dev, bool bios) printf("%sremovable.\n", geom.removable?"":"not "); printf("%sread_only.\n", geom.read_only?"":"not "); printf("%swrite_once.\n", geom.write_once?"":"not "); - puts(""); +} + +static void dump_partition(int dev) +{ + partition_info partition; + + if (ioctl(dev, B_GET_PARTITION_INFO, &partition, sizeof(partition)) < 0) { + perror("ioctl(B_GET_PARTITION_INFO)"); + return; + } + printf("partition:\n"); + printf("offset:\t%lld\n", partition.offset); + printf("size:\t%lld\n", partition.size); + printf("logical_block_size:\t%ld\n", partition.logical_block_size); + printf("session:\t%ld\n", partition.session); + printf("partition:\t%ld\n", partition.partition); + printf("device:\t%s\n", partition.device); } static void dump_misc(int dev) @@ -88,7 +101,6 @@ static void dump_misc(int dev) printf("device path:\t%s\n", path); } #endif - puts(""); } int main(int argc, char **argv) @@ -104,10 +116,18 @@ int main(int argc, char **argv) return 1; } dump_dev_size(dev); + puts(""); dump_bios_id(dev); + puts(""); dump_media_status(dev); + puts(""); dump_geom(dev, false); + puts(""); dump_geom(dev, true); + puts(""); + dump_partition(dev); + puts(""); dump_misc(dev); + puts(""); return 0; } From 8e813c26cde335c408493c86f544421eb355ffac Mon Sep 17 00:00:00 2001 From: Marcus Overhagen Date: Sat, 15 Sep 2012 12:39:01 +0200 Subject: [PATCH 23/23] ignore partition info logical_block_size --- src/bin/mkdos/mkdos.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/bin/mkdos/mkdos.cpp b/src/bin/mkdos/mkdos.cpp index 3ca3323b51..b6e391053c 100644 --- a/src/bin/mkdos/mkdos.cpp +++ b/src/bin/mkdos/mkdos.cpp @@ -198,13 +198,16 @@ status_t Initialize(int fatbits, const char *device, const char *label, bool nop if (!isRawDevice && !hasPartitionInfo) { fprintf(stderr,"Warning: couldn't get partition information\n"); } - if ( (hasPartitionInfo && partitionInfo.logical_block_size != 512) - || (hasBiosGeometry && biosGeometry.bytes_per_sector != 512) + if ((hasBiosGeometry && biosGeometry.bytes_per_sector != 512) || (hasDeviceGeometry && deviceGeometry.bytes_per_sector != 512)) { - fprintf(stderr,"Error: block size not 512 bytes\n"); + fprintf(stderr,"Error: geometry block size not 512 bytes\n"); close(fd); return B_ERROR; + } else if (hasPartitionInfo && partitionInfo.logical_block_size != 512) { + printf("partition logical block size is not 512, it's %ld bytes\n", + partitionInfo.logical_block_size); } + if (hasDeviceGeometry && deviceGeometry.read_only) { fprintf(stderr,"Error: this is a read-only device\n"); close(fd); @@ -321,7 +324,7 @@ status_t Initialize(int fatbits, const char *device, const char *label, bool nop uint8 biosDriveId; // get bios drive-id, or use 0x80 - if (B_OK != ioctl(fd, B_GET_BIOS_DRIVE_ID, &biosDriveId)) { + if (B_OK != ioctl(fd, B_GET_BIOS_DRIVE_ID, &biosDriveId, sizeof(biosDriveId))) { biosDriveId = 0x80; } else { printf("bios drive id: 0x%02x\n", (int)biosDriveId);