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" 13*5060d798SIngo Weinhold #include "IOScheduler.h" 14e91e4ee0SIngo Weinhold 15e91e4ee0SIngo Weinhold 16f14480bcSIngo Weinhold struct VMCache; 17f14480bcSIngo Weinhold struct vm_page; 18f14480bcSIngo Weinhold 19f14480bcSIngo Weinhold 20*5060d798SIngo Weinhold class IOCache : public IOScheduler { 21e91e4ee0SIngo Weinhold public: 22e91e4ee0SIngo Weinhold IOCache(DMAResource* resource, 23e91e4ee0SIngo Weinhold size_t cacheLineSize); 24*5060d798SIngo Weinhold virtual ~IOCache(); 25e91e4ee0SIngo Weinhold 26*5060d798SIngo Weinhold virtual status_t Init(const char* name); 27e91e4ee0SIngo Weinhold 28*5060d798SIngo Weinhold virtual void SetDeviceCapacity(off_t deviceCapacity); 29e91e4ee0SIngo Weinhold 30*5060d798SIngo Weinhold virtual status_t ScheduleRequest(IORequest* request); 31e91e4ee0SIngo Weinhold 32*5060d798SIngo Weinhold virtual void AbortRequest(IORequest* request, 33*5060d798SIngo Weinhold status_t status = B_CANCELED); 34*5060d798SIngo Weinhold virtual void OperationCompleted(IOOperation* operation, 35e91e4ee0SIngo Weinhold status_t status, size_t transferredBytes); 36e91e4ee0SIngo Weinhold 37*5060d798SIngo Weinhold virtual void Dump() const; 38*5060d798SIngo Weinhold 39e91e4ee0SIngo Weinhold private: 40e91e4ee0SIngo Weinhold struct Operation; 41e91e4ee0SIngo Weinhold 42e91e4ee0SIngo Weinhold private: 43e91e4ee0SIngo Weinhold status_t _DoRequest(IORequest* request, 44e91e4ee0SIngo Weinhold size_t& _bytesTransferred); 45e91e4ee0SIngo Weinhold status_t _TransferRequestLine(IORequest* request, 46f14480bcSIngo Weinhold off_t lineOffset, size_t lineSize, 47f14480bcSIngo Weinhold off_t requestOffset, size_t requestLength); 48f14480bcSIngo Weinhold status_t _TransferRequestLineUncached(IORequest* request, 49e91e4ee0SIngo Weinhold off_t lineOffset, off_t requestOffset, 50e91e4ee0SIngo Weinhold size_t requestLength); 51e91e4ee0SIngo Weinhold status_t _DoOperation(Operation& operation); 52e91e4ee0SIngo Weinhold 53f14480bcSIngo Weinhold status_t _TransferPages(size_t firstPage, 54f14480bcSIngo Weinhold size_t pageCount, bool isWrite, bool isVIP); 55f14480bcSIngo Weinhold void _DiscardPages(size_t firstPage, 56f14480bcSIngo Weinhold size_t pageCount); 57f14480bcSIngo Weinhold void _CachePages(size_t firstPage, size_t pageCount); 58e91e4ee0SIngo Weinhold 59f14480bcSIngo Weinhold status_t _CopyPages(IORequest* request, 60f14480bcSIngo Weinhold size_t pagesRelativeOffset, 61f14480bcSIngo Weinhold off_t requestOffset, size_t requestLength, 62f14480bcSIngo Weinhold bool toRequest); 63f14480bcSIngo Weinhold 64f14480bcSIngo Weinhold status_t _MapPages(size_t firstPage, size_t endPage); 65f14480bcSIngo Weinhold void _UnmapPages(size_t firstPage, size_t endPage); 66e91e4ee0SIngo Weinhold 67e91e4ee0SIngo Weinhold private: 68e91e4ee0SIngo Weinhold mutex fSerializationLock; 69e91e4ee0SIngo Weinhold off_t fDeviceCapacity; 70e91e4ee0SIngo Weinhold size_t fLineSize; 71e91e4ee0SIngo Weinhold uint32 fLineSizeShift; 72f14480bcSIngo Weinhold size_t fPagesPerLine; 73f14480bcSIngo Weinhold area_id fArea; 74f14480bcSIngo Weinhold void* fAreaBase; 75f14480bcSIngo Weinhold vm_page_reservation fMappingReservation; 76f14480bcSIngo Weinhold VMCache* fCache; 77f14480bcSIngo Weinhold vm_page** fPages; 78f14480bcSIngo Weinhold iovec* fVecs; 79e91e4ee0SIngo Weinhold }; 80e91e4ee0SIngo Weinhold 81e91e4ee0SIngo Weinhold 82e91e4ee0SIngo Weinhold #endif // IO_CACHE_H 83