43 enum ScsiPeripheralType {
45 SequentialDevice = 0x01,
47 ProcessorDevice = 0x03,
48 WriteOnceDevice = 0x04,
50 OpticalMemoryDevice = 0x07,
51 MediumChangerDevice = 0x08,
53 EnclosureDevice = 0x0D,
61 uint32_t SenseKey : 4;
65 uint32_t filemark : 1;
72 uint8_t senseKeySpecific[3];
84 uint8_t ProdIdent[16];
96#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
97 using HostedReadRequestHook = void (*)(
ScsiDisk*, uint64_t,
void*);
98 static void setHostedReadRequestHookForTest(HostedReadRequestHook hook,
void* context);
103 void shutdownCache(
bool deviceAvailable =
true);
104 virtual void shutdownDeviceCache();
105 bool hasNoCacheLoans();
110 bool readInto(uint64_t location,
void* buffer,
size_t length)
override;
112 bool writeFrom(uint64_t location,
const void* buffer,
size_t length)
override;
115 virtual void write(uint64_t location);
116 virtual void flush(uint64_t location);
117 virtual bool sync(uint64_t location,
bool async);
119 bool zero(uint64_t location,
size_t length)
override;
120 bool syncPages(
const uint64_t* locations,
size_t count)
override;
122 virtual void align(uint64_t location);
125 str =
String(
"SCSI Disk");
130 virtual uint64_t doRead(uint64_t location);
131 virtual uint64_t doWrite(uint64_t location);
132 virtual uint64_t doWriteDirectPhysical(uint64_t location, uintptr_t page,
133 physical_uintptr_t physical);
134 virtual uint64_t doSync(uint64_t location);
135 virtual PagingStatus doPagingTransfer(PagingOperation operation, uint64_t offset,
void* page);
139 static constexpr uint64_t SyncWholeDevice = ~uint64_t{0};
142 return m_NumBlocks * m_NativeBlockSize;
145 virtual size_t getBlockCount()
const {
158 return m_NativeBlockSize;
161 virtual bool pin(uint64_t location);
162 virtual void unpin(uint64_t location);
165 BufferView acquireView(uint64_t location,
bool writable, uint64_t& token)
override;
166 void releaseView(uint64_t token,
bool writable)
override;
168 virtual bool supportsBufferTransfers()
const {
171 virtual bool supportsDirectCacheWrite()
const {
174 virtual Device* dmaDevice()
const {
177 virtual bool transferBuffer(uint64_t location,
void* buffer,
size_t length,
bool writing);
178 virtual bool transferReadBuffers(ReadBuffer* buffers,
size_t count);
179 virtual bool transferWriteBuffers(WriteBuffer* buffers,
size_t count);
204 size_t getCacheFillLength(uint64_t location)
const;
210 Inquiry* getInquiry()
const {
225 static void discard(
void* context);
241 bool transferBufferRange(uint64_t location,
void* buffer,
size_t length,
bool writing);
242 static bool cacheRangesOverlap(uint64_t firstStart,
size_t firstLength, uint64_t secondStart,
243 size_t secondLength);
247 bool readSense(
Sense* s);
249 bool sendCommand(
ScsiCommand* pCommand, uintptr_t pRespBuffer, uint16_t nRespBytes,
250 bool bWrite =
false);
252 bool getCapacityInternal(
size_t* blockNumber,
size_t* blockSize);
255 bool flushCachePage(uint64_t location, uintptr_t page);
258 bool writePageBuffer(uint64_t location, uintptr_t page);
261 size_t getCachePageValidLength(uint64_t location)
const;
264 static bool retireCachePageCallback(uintptr_t key, uintptr_t page,
void* meta);
267 uint64_t getAlignmentPoint(uint64_t location)
const;
268 bool hasShiftedCacheAlignment()
const;
270 static bool cacheCallback(CacheConstants::CallbackCause cause, uintptr_t loc, uintptr_t page,
283#if HOSTED && PEDIGREE_HOSTED_SMOKE_TESTS
284 static Mutex m_HostedReadRequestHookLock;
285 static HostedReadRequestHook m_HostedReadRequestHook;
286 static void* m_HostedReadRequestHookContext;
289 mutable Mutex m_AlignmentLock;
291 bool m_HasShiftedCacheAlignment;
295 size_t m_NativeBlockSize;
297 ScsiPeripheralType m_DeviceType;
306 MUST_USE_RESULT virtual uint64_t doWriteDirect(uint64_t location, uintptr_t page);