[Krafton Jungle] PintOS 2.0.0
크래프톤 정글 PintOS
 
Loading...
Searching...
No Matches
disk.h File Reference
#include <inttypes.h>
#include <stdint.h>
Include dependency graph for disk.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DISK_SECTOR_SIZE   512
 
#define PRDSNu   PRIu32
 

Typedefs

typedef uint32_t disk_sector_t
 

Functions

void disk_init (void)
 
void disk_print_stats (void)
 
struct diskdisk_get (int chan_no, int dev_no)
 
disk_sector_t disk_size (struct disk *)
 
void disk_read (struct disk *, disk_sector_t, void *)
 
void disk_write (struct disk *, disk_sector_t, const void *)
 
void register_disk_inspect_intr ()
 

Macro Definition Documentation

◆ DISK_SECTOR_SIZE

#define DISK_SECTOR_SIZE   512

◆ PRDSNu

#define PRDSNu   PRIu32

Typedef Documentation

◆ disk_sector_t

Function Documentation

◆ disk_get()

struct disk * disk_get ( int  chan_no,
int  dev_no 
)
186 {
187 ASSERT (dev_no == 0 || dev_no == 1);
188
189 if (chan_no < (int) CHANNEL_CNT) {
190 struct disk *d = &channels[chan_no].devices[dev_no];
191 if (d->is_ata)
192 return d;
193 }
194 return NULL;
195}
#define ASSERT(CONDITION)
Definition: debug.h:30
static struct channel channels[CHANNEL_CNT]
Definition: disk.c:81
#define CHANNEL_CNT
Definition: disk.c:80
#define NULL
Definition: stddef.h:4
struct disk devices[2]
Definition: disk.c:76
Definition: disk.c:52
int dev_no
Definition: disk.c:55
bool is_ata
Definition: disk.c:57
Here is the caller graph for this function:

◆ disk_init()

void disk_init ( void  )
101 {
102 size_t chan_no;
103
104 for (chan_no = 0; chan_no < CHANNEL_CNT; chan_no++) {
105 struct channel *c = &channels[chan_no];
106 int dev_no;
107
108 /* Initialize channel. */
109 snprintf (c->name, sizeof c->name, "hd%zu", chan_no);
110 switch (chan_no) {
111 case 0:
112 c->reg_base = 0x1f0;
113 c->irq = 14 + 0x20;
114 break;
115 case 1:
116 c->reg_base = 0x170;
117 c->irq = 15 + 0x20;
118 break;
119 default:
120 NOT_REACHED ();
121 }
122 lock_init (&c->lock);
123 c->expecting_interrupt = false;
124 sema_init (&c->completion_wait, 0);
125
126 /* Initialize devices. */
127 for (dev_no = 0; dev_no < 2; dev_no++) {
128 struct disk *d = &c->devices[dev_no];
129 snprintf (d->name, sizeof d->name, "%s:%d", c->name, dev_no);
130 d->channel = c;
131 d->dev_no = dev_no;
132
133 d->is_ata = false;
134 d->capacity = 0;
135
136 d->read_cnt = d->write_cnt = 0;
137 }
138
139 /* Register interrupt handler. */
141
142 /* Reset hardware. */
143 reset_channel (c);
144
145 /* Distinguish ATA hard disks from other devices. */
146 if (check_device_type (&c->devices[0]))
147 check_device_type (&c->devices[1]);
148
149 /* Read hard disk identity information. */
150 for (dev_no = 0; dev_no < 2; dev_no++)
151 if (c->devices[dev_no].is_ata)
153 }
154
155 /* DO NOT MODIFY BELOW LINES. */
157}
#define NOT_REACHED()
Definition: debug.h:34
static void identify_ata_device(struct disk *)
Definition: disk.c:346
void register_disk_inspect_intr(void)
Definition: disk.c:551
static void reset_channel(struct channel *)
Definition: disk.c:260
static bool check_device_type(struct disk *)
Definition: disk.c:320
static void interrupt_handler(struct intr_frame *)
Definition: disk.c:516
void intr_register_ext(uint8_t vec, intr_handler_func *, const char *name)
Definition: interrupt.c:228
int int snprintf(char *, size_t, const char *,...) PRINTF_FORMAT(3
Definition: disk.c:66
bool expecting_interrupt
Definition: disk.c:72
struct semaphore completion_wait
Definition: disk.c:74
char name[8]
Definition: disk.c:67
uint16_t reg_base
Definition: disk.c:68
uint8_t irq
Definition: disk.c:69
struct lock lock
Definition: disk.c:71
disk_sector_t capacity
Definition: disk.c:58
struct channel * channel
Definition: disk.c:54
long long write_cnt
Definition: disk.c:61
long long read_cnt
Definition: disk.c:60
char name[8]
Definition: disk.c:53
void sema_init(struct semaphore *, unsigned value)
Definition: synch.c:52
void lock_init(struct lock *)
Definition: synch.c:186
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disk_print_stats()

void disk_print_stats ( void  )
161 {
162 int chan_no;
163
164 for (chan_no = 0; chan_no < CHANNEL_CNT; chan_no++) {
165 int dev_no;
166
167 for (dev_no = 0; dev_no < 2; dev_no++) {
168 struct disk *d = disk_get (chan_no, dev_no);
169 if (d != NULL && d->is_ata)
170 printf ("%s: %lld reads, %lld writes\n",
171 d->name, d->read_cnt, d->write_cnt);
172 }
173 }
174}
struct disk * disk_get(int chan_no, int dev_no)
Definition: disk.c:186
int printf(const char *,...) PRINTF_FORMAT(1
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disk_read()

void disk_read ( struct disk d,
disk_sector_t  sec_no,
void *  buffer 
)
211 {
212 struct channel *c;
213
214 ASSERT (d != NULL);
215 ASSERT (buffer != NULL);
216
217 c = d->channel;
218 lock_acquire (&c->lock);
219 select_sector (d, sec_no);
222 if (!wait_while_busy (d))
223 PANIC ("%s: disk read failed, sector=%"PRDSNu, d->name, sec_no);
224 input_sector (c, buffer);
225 d->read_cnt++;
226 lock_release (&c->lock);
227}
#define PANIC(...)
Definition: debug.h:14
static bool wait_while_busy(const struct disk *)
Definition: disk.c:474
static void issue_pio_command(struct channel *, uint8_t command)
Definition: disk.c:426
static void input_sector(struct channel *, void *)
Definition: disk.c:438
static void select_sector(struct disk *, disk_sector_t)
Definition: disk.c:408
#define CMD_READ_SECTOR_RETRY
Definition: disk.c:48
#define PRDSNu
Definition: disk.h:16
static struct intq buffer
Definition: input.c:7
void lock_release(struct lock *)
Definition: synch.c:243
void sema_down(struct semaphore *)
Definition: synch.c:68
void lock_acquire(struct lock *)
Definition: synch.c:202
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disk_size()

disk_sector_t disk_size ( struct disk d)
200 {
201 ASSERT (d != NULL);
202
203 return d->capacity;
204}
Here is the caller graph for this function:

◆ disk_write()

void disk_write ( struct disk d,
disk_sector_t  sec_no,
const void *  buffer 
)
235 {
236 struct channel *c;
237
238 ASSERT (d != NULL);
239 ASSERT (buffer != NULL);
240
241 c = d->channel;
242 lock_acquire (&c->lock);
243 select_sector (d, sec_no);
245 if (!wait_while_busy (d))
246 PANIC ("%s: disk write failed, sector=%"PRDSNu, d->name, sec_no);
249 d->write_cnt++;
250 lock_release (&c->lock);
251}
#define CMD_WRITE_SECTOR_RETRY
Definition: disk.c:49
static void output_sector(struct channel *, const void *)
Definition: disk.c:445
Here is the call graph for this function:
Here is the caller graph for this function:

◆ register_disk_inspect_intr()

void register_disk_inspect_intr ( )
551 {
552 intr_register_int (0x43, 3, INTR_OFF, inspect_read_cnt, "Inspect Disk Read Count");
553 intr_register_int (0x44, 3, INTR_OFF, inspect_write_cnt, "Inspect Disk Write Count");
554}
static void inspect_write_cnt(struct intr_frame *f)
Definition: disk.c:539
static void inspect_read_cnt(struct intr_frame *f)
Definition: disk.c:533
@ INTR_OFF
Definition: interrupt.h:9
void intr_register_int(uint8_t vec, int dpl, enum intr_level, intr_handler_func *, const char *name)
Definition: interrupt.c:248
Here is the call graph for this function:
Here is the caller graph for this function: