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); 2903768a40SAxel 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, 36*435c43f5SIngo Weinhold status_t status, 37*435c43f5SIngo Weinhold generic_size_t transferredBytes); 38e91e4ee0SIngo Weinhold 395060d798SIngo Weinhold virtual void Dump() const; 405060d798SIngo Weinhold 41e91e4ee0SIngo Weinhold private: 42e91e4ee0SIngo Weinhold struct Operation; 43e91e4ee0SIngo Weinhold 44e91e4ee0SIngo Weinhold private: 45e91e4ee0SIngo Weinhold status_t _DoRequest(IORequest* request, 46*435c43f5SIngo Weinhold generic_size_t& _bytesTransferred); 47e91e4ee0SIngo Weinhold status_t _TransferRequestLine(IORequest* request, 48f14480bcSIngo Weinhold off_t lineOffset, size_t lineSize, 49f14480bcSIngo Weinhold off_t requestOffset, size_t requestLength); 50f14480bcSIngo Weinhold status_t _TransferRequestLineUncached(IORequest* request, 51e91e4ee0SIngo Weinhold off_t lineOffset, off_t requestOffset, 52e91e4ee0SIngo Weinhold size_t requestLength); 53e91e4ee0SIngo Weinhold status_t _DoOperation(Operation& operation); 54e91e4ee0SIngo Weinhold 55f14480bcSIngo Weinhold status_t _TransferPages(size_t firstPage, 56f14480bcSIngo Weinhold size_t pageCount, bool isWrite, bool isVIP); 57f14480bcSIngo Weinhold void _DiscardPages(size_t firstPage, 58f14480bcSIngo Weinhold size_t pageCount); 59f14480bcSIngo Weinhold void _CachePages(size_t firstPage, size_t pageCount); 60e91e4ee0SIngo Weinhold 61f14480bcSIngo Weinhold status_t _CopyPages(IORequest* request, 62f14480bcSIngo Weinhold size_t pagesRelativeOffset, 63f14480bcSIngo Weinhold off_t requestOffset, size_t requestLength, 64f14480bcSIngo Weinhold bool toRequest); 65f14480bcSIngo Weinhold 66f14480bcSIngo Weinhold status_t _MapPages(size_t firstPage, size_t endPage); 67f14480bcSIngo Weinhold void _UnmapPages(size_t firstPage, size_t endPage); 68e91e4ee0SIngo Weinhold 69e91e4ee0SIngo Weinhold private: 70e91e4ee0SIngo Weinhold mutex fSerializationLock; 71e91e4ee0SIngo Weinhold off_t fDeviceCapacity; 72e91e4ee0SIngo Weinhold size_t fLineSize; 73e91e4ee0SIngo Weinhold uint32 fLineSizeShift; 74f14480bcSIngo Weinhold size_t fPagesPerLine; 75f14480bcSIngo Weinhold area_id fArea; 76f14480bcSIngo Weinhold void* fAreaBase; 77f14480bcSIngo Weinhold vm_page_reservation fMappingReservation; 78f14480bcSIngo Weinhold VMCache* fCache; 79f14480bcSIngo Weinhold vm_page** fPages; 80*435c43f5SIngo Weinhold generic_io_vec* fVecs; 81e91e4ee0SIngo Weinhold }; 82e91e4ee0SIngo Weinhold 83e91e4ee0SIngo Weinhold 84e91e4ee0SIngo Weinhold #endif // IO_CACHE_H 85