xref: /haiku/src/system/kernel/device_manager/IOScheduler.h (revision 125183f9e5c136781f71c879faaeab43fdc3ea7b)
1 /*
2  * Copyright 2010, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 #ifndef IO_SCHEDULER_H
6 #define IO_SCHEDULER_H
7 
8 
9 #include <KernelExport.h>
10 
11 #include <util/DoublyLinkedList.h>
12 
13 #include "IOCallback.h"
14 #include "IORequest.h"
15 
16 
17 struct IORequestOwner : DoublyLinkedListLinkImpl<IORequestOwner> {
18 	team_id			team;
19 	thread_id		thread;
20 	int32			priority;
21 	IORequestList	requests;
22 	IORequestList	completed_requests;
23 	IOOperationList	operations;
24 	IORequestOwner*	hash_link;
25 
26 			bool				IsActive() const
27 									{ return !requests.IsEmpty()
28 										|| !completed_requests.IsEmpty()
29 										|| !operations.IsEmpty(); }
30 
31 			void				Dump() const;
32 };
33 
34 
35 class IOScheduler : public DoublyLinkedListLinkImpl<IOScheduler> {
36 public:
37 								IOScheduler(DMAResource* resource);
38 	virtual						~IOScheduler();
39 
40 	virtual	status_t			Init(const char* name);
41 
42 			const char*			Name() const	{ return fName; }
43 			int32				ID() const		{ return fID; }
44 
45 	virtual	void				SetCallback(IOCallback& callback);
46 	virtual	void				SetCallback(io_callback callback, void* data);
47 
48 	virtual	void				SetDeviceCapacity(off_t deviceCapacity);
49 
50 	virtual	status_t			ScheduleRequest(IORequest* request) = 0;
51 
52 	virtual	void				AbortRequest(IORequest* request,
53 									status_t status = B_CANCELED) = 0;
54 	virtual	void				OperationCompleted(IOOperation* operation,
55 									status_t status, size_t transferredBytes)
56 										= 0;
57 									// called by the driver when the operation
58 									// has been completed successfully or failed
59 									// for some reason
60 
61 	virtual	void				Dump() const = 0;
62 
63 protected:
64 			DMAResource*		fDMAResource;
65 			char*				fName;
66 			int32				fID;
67 			io_callback			fIOCallback;
68 			void*				fIOCallbackData;
69 			bool				fSchedulerRegistered;
70 };
71 
72 
73 #endif	// IO_SCHEDULER_H
74