Esempio n. 1
0
static struct SectorCache *
cache_fetch(uint_32 sector) {
	//printk("enter cache_fetch\n");
	struct SectorCache *ptr = &cache[sector % NR_SEC_CACHE];

	if (ptr->used == TRUE && ptr->sector == sector) {
		//printk("hit\n");
		/* cache hit, do nothing */
	} else {
		//printk("miss\n");
		if (ptr->used == TRUE && ptr->dirty == TRUE) {
			/* write back */
			ide_prepare(ptr->sector);
			do_write(&ptr->content);
		}
		/* issue a read command */
		ide_prepare(sector);
		issue_read();
		do_read(&ptr->content);
		ptr->used = TRUE;
		ptr->sector = sector;
		ptr->dirty = FALSE;
	}
	return ptr;
}
Esempio n. 2
0
void
disk_do_write(void *buf, uint32_t sector) {
	int i;

	ide_prepare(sector);
	issue_write();

	for (i = 0; i < 512 / sizeof(uint32_t); i ++) {
		out_long(IDE_PORT_BASE, *(((uint32_t*)buf) + i));
	}
}
Esempio n. 3
0
void
disk_do_read(void *buf, uint32_t sector) {
	int i;

	ide_prepare(sector);
	issue_read();

	waitdisk();
	for (i = 0; i < 512 / sizeof(uint32_t); i ++) {
		*(((uint32_t*)buf) + i) = in_long(IDE_PORT_BASE);
	}
}
Esempio n. 4
0
void
ide_driver_thread(void) {
	static struct Message m;

	while (TRUE) {
		receive(ANY, &m);
		if (m.src == MSG_HARD_INTR) {
			if (m.type == IDE_WRITEBACK) {
				int i;
				for (i = 0; i < NR_SEC_CACHE; i ++) {
					if (cache[i].dirty == TRUE) {
						ide_prepare(cache[i].sector);
						do_write(&cache[i].content);
						cache[i].dirty = FALSE;
					}
				}
			} else {
				panic("IDE interrupt is leaking");
			}
		} else if (m.type == DEV_READ) {
			//printk("IDE driver receive request!\n");
			//printk("rr\n");
			uint_32 i, data;
			struct PCB *pcb = fetch_pcb(m.src);
			//printk("length = %d\n", m.dev_io.length);
			for (i = 0; i < m.dev_io.length; i ++) {
				//printk("%d\n", i);
				data = read_byte(m.dev_io.offset + i);
				//printk("after data\n");
				copy_from_kernel(pcb, m.dev_io.buf + i, &data, 1);
			}
			m.type = -1;
			m.int_msg.p1 = i;
			//printk("Almost Finished!\n");
			send(m.src, &m);
			//printk("ss\n");
		} else if (m.type == DEV_WRITE) {
			uint_32 i, data;
			struct PCB *pcb = fetch_pcb(m.src);
			for (i = 0; i < m.dev_io.length; i ++) {
				copy_to_kernel(pcb, &data, m.dev_io.buf + i, 1);
				write_byte(m.dev_io.offset + i, data);
			}
			m.type = -1;
			m.int_msg.p1 = i;
			send(m.src, &m);
		}
	}
}