vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / kernel / busses / ata / it8211 / it8211.c
blobd65ffe499d2983931e628ca753936b7c7533fdd1
1 /*
2 * Copyright 2008, Michael Lotz. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5 #include <KernelExport.h>
6 #include <stdlib.h>
7 #include <string.h>
9 #include <ata_adapter.h>
11 #define IT8211_CONTROLLER_MODULE_NAME "busses/ata/it8211/driver_v1"
12 #define IT8211_CHANNEL_MODULE_NAME "busses/ata/it8211/channel/v1"
14 #define PCI_VENDOR_ITE 0x1283
15 #define PCI_DEVICE_ITE_IT8211 0x8211
17 static ata_adapter_interface *sATAAdapter;
18 static device_manager_info *sDeviceManager;
21 static void
22 it8211_set_channel(void *channelCookie, ata_channel channel)
24 sATAAdapter->set_channel((ata_adapter_channel_info *)channelCookie,
25 channel);
29 static status_t
30 it8211_write_command_block_regs(void *channelCookie, ata_task_file *taskFile,
31 ata_reg_mask registerMask)
33 return sATAAdapter->write_command_block_regs(
34 (ata_adapter_channel_info *)channelCookie, taskFile, registerMask);
38 static status_t
39 it8211_read_command_block_regs(void *channelCookie, ata_task_file *taskFile,
40 ata_reg_mask registerMask)
42 return sATAAdapter->read_command_block_regs(
43 (ata_adapter_channel_info *)channelCookie, taskFile, registerMask);
47 static uint8
48 it8211_get_altstatus(void *channelCookie)
50 return sATAAdapter->get_altstatus((ata_adapter_channel_info *)channelCookie);
54 static status_t
55 it8211_write_device_control(void *channelCookie, uint8 value)
57 return sATAAdapter->write_device_control(
58 (ata_adapter_channel_info *)channelCookie, value);
62 static status_t
63 it8211_write_pio(void *channelCookie, uint16 *data, int count, bool force16bit)
65 return sATAAdapter->write_pio(
66 (ata_adapter_channel_info *)channelCookie, data, count, force16bit);
70 static status_t
71 it8211_read_pio(void *channelCookie, uint16 *data, int count, bool force16bit)
73 return sATAAdapter->read_pio(
74 (ata_adapter_channel_info *)channelCookie, data, count, force16bit);
78 static status_t
79 it8211_prepare_dma(void *channelCookie, const physical_entry *sgList,
80 size_t sgListCount, bool toDevice)
82 return sATAAdapter->prepare_dma((ata_adapter_channel_info *)channelCookie,
83 sgList, sgListCount, toDevice);
87 static status_t
88 it8211_start_dma(void *channelCookie)
90 return sATAAdapter->start_dma((ata_adapter_channel_info *)channelCookie);
94 static status_t
95 it8211_finish_dma(void *channelCookie)
97 return sATAAdapter->finish_dma((ata_adapter_channel_info *)channelCookie);
101 static status_t
102 init_channel(device_node *node, void **channelCookie)
104 return sATAAdapter->init_channel(node,
105 (ata_adapter_channel_info **)channelCookie,
106 sizeof(ata_adapter_channel_info), sATAAdapter->inthand);
110 static void
111 uninit_channel(void *channelCookie)
113 sATAAdapter->uninit_channel((ata_adapter_channel_info *)channelCookie);
117 static void
118 channel_removed(void *channelCookie)
120 sATAAdapter->channel_removed((ata_adapter_channel_info *)channelCookie);
124 static status_t
125 init_controller(device_node *node, void **cookie)
127 return sATAAdapter->init_controller(node,
128 (ata_adapter_controller_info **)cookie,
129 sizeof(ata_adapter_controller_info));
133 static void
134 uninit_controller(void *cookie)
136 sATAAdapter->uninit_controller((ata_adapter_controller_info *)cookie);
140 static void
141 controller_removed(void *cookie)
143 sATAAdapter->controller_removed((ata_adapter_controller_info *)cookie);
147 static status_t
148 probe_controller(device_node *parent)
150 return sATAAdapter->probe_controller(parent,
151 IT8211_CONTROLLER_MODULE_NAME, "it8211",
152 "ITE IT8211", IT8211_CHANNEL_MODULE_NAME,
153 true, /* DMA */
154 true, /* command queuing */
155 1, /* 16 bit alignment */
156 0xffff, /* 64k boundary */
157 0x10000, /* up to 64k per scatter/gather block */
158 false); /* no compatibility mode */
162 static float
163 supports_device(device_node *parent)
165 const char *bus;
166 uint16 vendorID;
167 uint16 deviceID;
169 if (sDeviceManager->get_attr_string(parent, B_DEVICE_BUS, &bus, false) != B_OK
170 || sDeviceManager->get_attr_uint16(parent, B_DEVICE_VENDOR_ID, &vendorID, false) != B_OK
171 || sDeviceManager->get_attr_uint16(parent, B_DEVICE_ID, &deviceID, false) != B_OK) {
172 return -1.0f;
175 if (strcmp(bus, "pci") != 0 || vendorID != PCI_VENDOR_ITE
176 || deviceID != PCI_DEVICE_ITE_IT8211)
177 return 0.0f;
179 return 1.0f;
183 module_dependency module_dependencies[] = {
184 { B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&sDeviceManager },
185 { ATA_ADAPTER_MODULE_NAME, (module_info **)&sATAAdapter },
190 // exported interface
191 static ata_controller_interface sChannelInterface = {
194 IT8211_CHANNEL_MODULE_NAME,
196 NULL
199 NULL, // supports device
200 NULL, // register device
201 &init_channel,
202 &uninit_channel,
203 NULL, // register child devices
204 NULL, // rescan
205 &channel_removed
208 &it8211_set_channel,
209 &it8211_write_command_block_regs,
210 &it8211_read_command_block_regs,
211 &it8211_get_altstatus,
212 &it8211_write_device_control,
213 &it8211_write_pio,
214 &it8211_read_pio,
215 &it8211_prepare_dma,
216 &it8211_start_dma,
217 &it8211_finish_dma
221 static driver_module_info sControllerInterface = {
223 IT8211_CONTROLLER_MODULE_NAME,
225 NULL
228 &supports_device,
229 &probe_controller,
230 &init_controller,
231 &uninit_controller,
232 NULL, // register child devices
233 NULL, // rescan
234 &controller_removed
238 module_info *modules[] = {
239 (module_info *)&sControllerInterface,
240 (module_info *)&sChannelInterface,
241 NULL