stdlibc: ~several fixes
[meinos.git] / apps / cdrom / device.h
blob429ebf11a6a6b794311de14153d274a99ec1698a
1 /*
2 meinOS - A unix-like x86 microkernel operating system
3 Copyright (C) 2008 Janosch Gräf <janosch.graef@gmx.net>
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifndef _DEVICE_H_
20 #define _DEVICE_H_
22 #include <stdint.h>
23 #include <devfs.h>
25 #define CDROM_REQUEST_SENSE 0x03
26 #define CDROM_INQUIRY 0x12
27 #define CDROM_START_STOP 0x1B
28 #define CDROM_LOCK 0x1E
29 #define CDROM_READ_CAPACITY 0x25
30 #define CDROM_READ 0xA8
32 #define CDROM_BUFSIZE DEVFS_BUFSIZE
34 #define CDROM_R 0
35 #define CDROM_W 1
37 #define CDROM_TYPE 0x05
39 struct cdrom_device {
40 char *name;
41 char *rpc_func;
42 uint16_t vendor_id;
43 uint16_t product_id;
44 int started;
45 int loaded;
46 int locked;
47 size_t block_count;
48 size_t block_size;
49 devfs_dev_t *devfs;
52 typedef union {
53 struct {
54 uint8_t opcode;
55 uint8_t res0;
56 uint32_t lba;
57 uint8_t res1;
58 uint16_t length;
59 uint8_t res2[3];
60 } __attribute__ ((packed)) dfl;
61 struct {
62 uint8_t opcode;
63 uint8_t res0;
64 uint32_t lba;
65 uint32_t length;
66 uint16_t res1;
67 } __attribute__ ((packed)) ext;
68 uint8_t raw8[12];
69 uint16_t raw16[6];
70 uint32_t raw32[3];
71 } cdrom_cmd_t;
73 struct cdrom_inquiry_data {
74 unsigned type:5;
75 unsigned :10;
76 unsigned rmb:1;
77 unsigned ansi_version:3;
78 unsigned ecma_version:3;
79 unsigned iso_version:2;
80 unsigned response_type:4;
81 unsigned atapi_version:4;
82 uint8_t additional_length;
83 unsigned :24;
84 uint16_t vendor_id;
85 uint16_t product_id;
86 uint16_t product_rev_level;
87 } __attribute__ ((packed));
89 struct cdrom_read_capacity_data {
90 uint32_t lba;
91 uint32_t block_size;
92 } __attribute__ ((packed));
94 struct cdrom_request_sense_data {
95 unsigned error_code:7;
96 unsigned valid:1;
97 uint8_t segment_number;
98 unsigned sense_key:4;
99 unsigned res0:1;
100 unsigned ili:1;
101 unsigned res1:2;
102 uint16_t information;
103 uint8_t additionaL_sense_length;
104 uint16_t command_specific_information;
105 uint8_t additional_sense_code;
106 uint8_t additional_sense_code_qualifier;
107 uint8_t field_replacable_unit_code;
108 unsigned sense_key_specific:15;
109 unsigned sense_key_valid:1;
110 uint8_t additional_sense_bytes[0];
111 } __attribute__ ((packed));
113 struct cdrom_request_sense_data *cdrom_request_sense(struct cdrom_device *dev);
114 int cdrom_inquiry(struct cdrom_device *dev);
115 int cdrom_start(struct cdrom_device *dev,int start,int load);
116 int cdrom_lock(struct cdrom_device *dev,int lock);
117 int cdrom_read_capacity(struct cdrom_device *dev);
118 void *cdrom_read(struct cdrom_device *dev,size_t first_block,size_t block_count);
119 struct cdrom_device *cdrom_device_create(const char *name);
120 void cdrom_device_destroy(struct cdrom_device *dev);
121 int cdrom_buf_init();
123 static inline int cdrom_load(struct cdrom_device *dev,int load) {
124 return cdrom_start(dev,dev->started,load);
127 static inline uint32_t bei(uint32_t v) {
128 uint32_t r;
129 swab(&v,&r,4);
130 return r;
133 static inline uint16_t bes(uint16_t v) {
134 uint16_t r;
135 swab(&v,&r,2);
136 return r;
139 #endif