1e91e4ee0SIngo Weinhold /* 2e91e4ee0SIngo Weinhold * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de. 3e91e4ee0SIngo Weinhold * Distributed under the terms of the MIT License. 4e91e4ee0SIngo Weinhold */ 5e91e4ee0SIngo Weinhold #ifndef IO_CACHE_H 6e91e4ee0SIngo Weinhold #define IO_CACHE_H 7e91e4ee0SIngo Weinhold 8e91e4ee0SIngo Weinhold 9e91e4ee0SIngo Weinhold #include <lock.h> 10f14480bcSIngo Weinhold #include <vm/vm_page.h> 11e91e4ee0SIngo Weinhold 12e91e4ee0SIngo Weinhold #include "dma_resources.h" 135060d798SIngo Weinhold #include "IOScheduler.h" 14e91e4ee0SIngo Weinhold 15e91e4ee0SIngo Weinhold 16f14480bcSIngo Weinhold struct VMCache; 17f14480bcSIngo Weinhold struct vm_page; 18f14480bcSIngo Weinhold 19f14480bcSIngo Weinhold 205060d798SIngo Weinhold class IOCache : public IOScheduler { 21e91e4ee0SIngo Weinhold public: 22e91e4ee0SIngo Weinhold IOCache(DMAResource* resource, 23e91e4ee0SIngo Weinhold size_t cacheLineSize); 245060d798SIngo Weinhold virtual ~IOCache(); 25e91e4ee0SIngo Weinhold 265060d798SIngo Weinhold virtual status_t Init(const char* name); 27e91e4ee0SIngo Weinhold 285060d798SIngo Weinhold virtual void SetDeviceCapacity(off_t deviceCapacity); 29*03768a40SAxel Dörfler virtual void MediaChanged(); 30e91e4ee0SIngo Weinhold 315060d798SIngo Weinhold virtual status_t ScheduleRequest(IORequest* request); 32e91e4ee0SIngo Weinhold 335060d798SIngo Weinhold virtual void AbortRequest(IORequest* request, 345060d798SIngo Weinhold status_t status = B_CANCELED); 355060d798SIngo Weinhold virtual void OperationCompleted(IOOperation* operation, 36e91e4ee0SIngo Weinhold status_t status, size_t transferredBytes); 37e91e4ee0SIngo Weinhold 385060d798SIngo Weinhold virtual void Dump() const; 395060d798SIngo Weinhold 40e91e4ee0SIngo Weinhold private: 41e91e4ee0SIngo Weinhold struct Operation; 42e91e4ee0SIngo Weinhold 43e91e4ee0SIngo Weinhold private: 44e91e4ee0SIngo Weinhold status_t _DoRequest(IORequest* request, 45e91e4ee0SIngo Weinhold size_t& _bytesTransferred); 46e91e4ee0SIngo Weinhold status_t _TransferRequestLine(IORequest* request, 47f14480bcSIngo Weinhold off_t lineOffset, size_t lineSize, 48f14480bcSIngo Weinhold off_t requestOffset, size_t requestLength); 49f14480bcSIngo Weinhold status_t _TransferRequestLineUncached(IORequest* request, 50e91e4ee0SIngo Weinhold off_t lineOffset, off_t requestOffset, 51e91e4ee0SIngo Weinhold size_t requestLength); 52e91e4ee0SIngo Weinhold status_t _DoOperation(Operation& operation); 53e91e4ee0SIngo Weinhold 54f14480bcSIngo Weinhold status_t _TransferPages(size_t firstPage, 55f14480bcSIngo Weinhold size_t pageCount, bool isWrite, bool isVIP); 56f14480bcSIngo Weinhold void _DiscardPages(size_t firstPage, 57f14480bcSIngo Weinhold size_t pageCount); 58f14480bcSIngo Weinhold void _CachePages(size_t firstPage, size_t pageCount); 59e91e4ee0SIngo Weinhold 60f14480bcSIngo Weinhold status_t _CopyPages(IORequest* request, 61f14480bcSIngo Weinhold size_t pagesRelativeOffset, 62f14480bcSIngo Weinhold off_t requestOffset, size_t requestLength, 63f14480bcSIngo Weinhold bool toRequest); 64f14480bcSIngo Weinhold 65f14480bcSIngo Weinhold status_t _MapPages(size_t firstPage, size_t endPage); 66f14480bcSIngo Weinhold void _UnmapPages(size_t firstPage, size_t endPage); 67e91e4ee0SIngo Weinhold 68e91e4ee0SIngo Weinhold private: 69e91e4ee0SIngo Weinhold mutex fSerializationLock; 70e91e4ee0SIngo Weinhold off_t fDeviceCapacity; 71e91e4ee0SIngo Weinhold size_t fLineSize; 72e91e4ee0SIngo Weinhold uint32 fLineSizeShift; 73f14480bcSIngo Weinhold size_t fPagesPerLine; 74f14480bcSIngo Weinhold area_id fArea; 75f14480bcSIngo Weinhold void* fAreaBase; 76f14480bcSIngo Weinhold vm_page_reservation fMappingReservation; 77f14480bcSIngo Weinhold VMCache* fCache; 78f14480bcSIngo Weinhold vm_page** fPages; 79f14480bcSIngo Weinhold iovec* fVecs; 80e91e4ee0SIngo Weinhold }; 81e91e4ee0SIngo Weinhold 82e91e4ee0SIngo Weinhold 83e91e4ee0SIngo Weinhold #endif // IO_CACHE_H 84