Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Release 1.0
[palacios.git] / misc / test_vm / include / geekos / blockdev.h
1 /*
2  * Block devices
3  * Copyright (c) 2003 David H. Hovemeyer <daveho@cs.umd.edu>
4  * Copyright (c) 2003, Jeffrey K. Hollingsworth <hollings@cs.umd.edu>
5  * $Revision: 1.1 $
6  * 
7  * This is free software.  You are permitted to use,
8  * redistribute, and modify it as specified in the file "COPYING".
9  */
10
11 #ifndef GEEKOS_BLOCKDEV_H
12 #define GEEKOS_BLOCKDEV_H
13
14 #include <geekos/ktypes.h>
15 #include <geekos/kthread.h>
16 #include <geekos/list.h>
17 #include <geekos/fileio.h>
18
19 #ifdef GEEKOS
20
21 /*
22  * Type of block device request.
23  */
24 enum Request_Type {
25     BLOCK_READ, BLOCK_WRITE
26 };
27
28 /*
29  * State of a block I/O request.
30  */
31 enum Request_State {
32     PENDING, COMPLETED, ERROR
33 };
34
35 struct Block_Request;
36
37 /*
38  * List of block I/O requests.
39  */
40 DEFINE_LIST(Block_Request_List, Block_Request);
41
42 /*
43  * An I/O request for a block device.
44  */
45 struct Block_Request {
46     struct Block_Device *dev;
47     enum Request_Type type;
48     int blockNum;
49     void *buf;
50     volatile enum Request_State state;
51     volatile int errorCode;
52     struct Thread_Queue waitQueue;
53
54     DEFINE_LINK(Block_Request_List, Block_Request);
55 };
56
57 IMPLEMENT_LIST(Block_Request_List, Block_Request);
58
59 struct Block_Device;
60 struct Block_Device_Ops;
61
62 /*
63  * A block device.
64  */
65 struct Block_Device {
66     char name[BLOCKDEV_MAX_NAME_LEN];
67     struct Block_Device_Ops *ops;
68     int unit;
69     bool inUse;
70     void *driverData;
71     struct Thread_Queue *waitQueue;
72     struct Block_Request_List *requestQueue;
73
74     DEFINE_LINK(Block_Device_List, Block_Device);
75 };
76
77 /*
78  * Operations that may be requested on block devices.
79  */
80 struct Block_Device_Ops {
81     int (*Open)(struct Block_Device *dev);
82     int (*Close)(struct Block_Device *dev);
83     int (*Get_Num_Blocks)(struct Block_Device *dev);
84 };
85
86 /*
87  * Low level block device API.
88  * Only block device drivers need to use these functions.
89  */
90 int Register_Block_Device(const char *name, struct Block_Device_Ops *ops,
91     int unit, void *driverData, struct Thread_Queue *waitQueue,
92     struct Block_Request_List *requestQueue);
93 int Open_Block_Device(const char *name, struct Block_Device **pDev);
94 int Close_Block_Device(struct Block_Device *dev);
95 struct Block_Request *Create_Request(struct Block_Device *dev, enum Request_Type type,
96     int blockNum, void *buf);
97 void Post_Request_And_Wait(struct Block_Request *request);
98 struct Block_Request *Dequeue_Request(struct Block_Request_List *requestQueue,
99     struct Thread_Queue *waitQueue);
100 void Notify_Request_Completion(struct Block_Request *request, enum Request_State state, int errorCode);
101
102 /*
103  * High level block device API.
104  * For use by filesystem and disk paging code.
105  */
106 int Block_Read(struct Block_Device *dev, int blockNum, void *buf);
107 int Block_Write(struct Block_Device *dev, int blockNum, void *buf);
108 int Get_Num_Blocks(struct Block_Device *dev);
109
110 /*
111  * Misc. routines
112  */
113
114 /*
115  * Round offset up to nearest sector.
116  */
117 static __inline__ ulong_t Round_Up_To_Block(ulong_t offset)
118 {
119     return (offset % SECTOR_SIZE) == 0
120         ? offset
121         : offset + (SECTOR_SIZE - (offset % SECTOR_SIZE));
122 }
123
124 /*
125  * Round offset down to nearest sector.
126  */
127 static __inline__ ulong_t Round_Down_To_Block(ulong_t offset)
128 {
129     return (offset % SECTOR_SIZE) == 0
130         ? offset
131         : offset - (offset % SECTOR_SIZE);
132 }
133
134 #endif /* GEEKOS */
135
136 #endif
137