21 acmd[2] = (lba >> 24) & 0xFF;
22 acmd[3] = (lba >> 16) & 0xFF;
23 acmd[4] = (lba >> 8) & 0xFF;
24 acmd[5] = (lba >> 0) & 0xFF;
26 if (opcode == 0xA8 || opcode == 0xAA) {
28 acmd[6] = (sector_count >> 24) & 0xFF;
29 acmd[7] = (sector_count >> 16) & 0xFF;
30 acmd[8] = (sector_count >> 8) & 0xFF;
31 acmd[9] = (sector_count >> 0) & 0xFF;
37 acmd[7] = (sector_count >> 8) & 0xFF;
38 acmd[8] = (sector_count >> 0) & 0xFF;
50 read_capacity10_resp_t* resp =
51 (read_capacity10_resp_t*)IOUtils::DMAAlloc(
sizeof(*resp),
54 memset(resp, 0,
sizeof(*resp));
61 .buffer = (
void*)resp_phys,
62 .buffer_size =
sizeof(*resp),
70 if (!block->
ops.
submit(block, &cap_req)) {
71 log(
mod,
"failed to idenitify device");
74 block->
sector_size = __builtin_bswap32(resp->block_size);
76 IOUtils::DMAFree((
void*)resp_phys, (
void*)resp,
sizeof(*resp));
87 .buffer = (
void*)buff_phys,
97 log(
mod,
"failed to idenitify device");
98 IOUtils::DMAFree((
void*)buff_phys, (
void*)buff, 512);
103 if (
info & (1 << 15)) {
107 log(
mod,
"method %b", method);
109 uint16_t command_set_supported = buff[83] & 0b111;
110 log(
mod,
"supported : %b", command_set_supported);
112 char serial_number[21] = {0};
114 log(
mod,
"serial number: %s", (
char*)serial_number);
116 char firmware_version[9] = {0};
118 log(
mod,
"firmware version: %s", (
char*)firmware_version);
120 char* model_number = (
char*)
kalloc(41);
121 memset(model_number, 0, 41);
123 log(
mod,
"model number: %s", (
char*)model_number);
128 uint16_t cmd_f_supported = buff[82];
129 log(
mod,
"cmd_f_supported: %b", cmd_f_supported);
131 uint16_t ata_version = (buff[80] & 0x1F) >> 1;
132 log(
mod,
"ata_version support: %b", ata_version);
134 log(
mod,
"block 0x%x", block);
165 log(
mod,
"block 0x%x", block);
167 IOUtils::DMAFree((
void*)buff_phys, (
void*)buff, 512);
176 log(i->mod,
"read: vops is null");
183 log(i->mod,
"read: block device is null");
187 if (!buf ||
count == 0) {
188 log(i->mod,
"read: invalid buffer or count");
192 const size_t sector_size =
200 void* buff_ = IOUtils::DMAAlloc(sector_count * sector_size, &buff_phys);
202 log(i->mod,
"read: DMA alloc failed");
205 memset(buff_, 0, sector_count * sector_size);
208 i->build_acmd(0xA8, lba, sector_count, acmd);
213 .buffer = (
void*)buff_phys,
214 .buffer_size = sector_count * sector_size,
215 .block_count = sector_count,
218 .packet_cmd_len = 12,
222 int ret = block->
ops.
submit(block, &req);
224 log(i->mod,
"read: submit failed (lba=%d, sectors=%d)", lba,
226 IOUtils::DMAFree((
void*)buff_phys, buff_,
227 sector_count * sector_size);
233 IOUtils::DMAFree((
void*)buff_phys, buff_, sector_count * sector_size);
235 log(i->mod,
"read: success (lba=%d, sectors=%d)", lba, sector_count);
244 log(i->mod,
"read: vops is null");
251 log(i->mod,
"write: block device is null");
255 if (!buf ||
count == 0) {
256 log(i->mod,
"write: invalid buffer or count");
263 "write: device is read-only or write not supported");
267 const size_t sector_size =
276 i->build_acmd(0xAA, lba, sector_count, acmd);
281 .buffer = (
void*)buff_phys,
282 .buffer_size = sector_count * sector_size,
283 .block_count = sector_count,
286 .packet_cmd_len = 12,
290 int ret = block->
ops.
submit(block, &req);
292 log(i->mod,
"write: submit failed (lba=%u, count=%u, err=%d)",
293 lba, sector_count, ret);
297 log(i->mod,
"write: success (lba=%u, sectors=%u)", lba, sector_count);
305 for (
int i = 0; i <
len; i += 2) {
311 for (
int i =
len - 1; i >= 0; i--) {
void identify(struct ioforge_block_device *block)
static int read(vnode_t *vnode, uintptr_t addr, void *buf, size_t count)
void read_sector_size(struct ioforge_block_device *block)
void read_ascii(char *out, uint16_t off, uint16_t *buff, uint16_t len)
static ATAPIModule * getInstance()
void build_acmd(uint8_t opcode, uint32_t lba, uint32_t sector_count, uint8_t(&acmd)[16])
void probe(struct ioforge_block_device *block)
static int write(vnode_t *vnode, uintptr_t addr, void *buf, size_t count)
struct dentry * dentry_ptr
int vxnamei(const char *path, dentry_ptr *out)
Resolves a file path to a directory entry (dentry).
cdev_ptr_t create_dev(void *ops, uint32_t major)
void serial2_printf(const char *fmt,...)
#define log(mod, fmt,...)
@ IOFORGE_BLOCK_OP_PACKET
@ IOFORGE_BLOCK_OP_IDENTIFY
void * kalloc(size_t size)
int notify_call(char *name, uint32_t event, void *data)
void memset(void *ptr, int value, size_t num)
void memcopy(void *dest, void *src, size_t size)
kstring str(const char *str)
struct ioforge_block_op ops
int(* submit)(struct ioforge_block_device *dev, struct ioforge_block_request *req)
int(* write)(vnode_t *vnode, uintptr_t addr, void *buf, size_t count)
int(* open)(vnode_t *vnode, int op_mode, thread_t *thread)
int(* read)(vnode_t *vnode, uintptr_t addr, void *buf, size_t count)
vnode_t * create_and_attach_vnode()
struct vops_blk vops_blk_t