BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / busses / ide / generic_ide_pci / generic_ide_pci.c
blob1118d0717345f85644aa2b3ee6ecd8b0d19d2b89
1 /*
2 * Copyright 2002/03, Thomas Kurschel. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
6 /*! Generic PCI bus mastering IDE driver. */
8 #include <KernelExport.h>
9 #include <stdlib.h>
10 #include <string.h>
12 #include <ide_adapter.h>
14 #define GENERIC_IDE_PCI_CONTROLLER_MODULE_NAME "busses/ide/generic_ide_pci/driver_v1"
15 #define GENERIC_IDE_PCI_CHANNEL_MODULE_NAME "busses/ide/generic_ide_pci/channel/v1"
17 #define IDE_PCI_CONTROLLER_TYPE_NAME "ide pci controller"
19 ide_for_controller_interface *ide;
20 static ide_adapter_interface *ide_adapter;
21 device_manager_info *pnp;
24 static void
25 set_channel(void *cookie, ide_channel channel)
27 ide_adapter->set_channel((ide_adapter_channel_info *)cookie, channel);
31 static status_t
32 write_command_block_regs(void *channel_cookie, ide_task_file *tf, ide_reg_mask mask)
34 return ide_adapter->write_command_block_regs((ide_adapter_channel_info *)channel_cookie, tf, mask);
38 static status_t
39 read_command_block_regs(void *channel_cookie, ide_task_file *tf, ide_reg_mask mask)
41 return ide_adapter->read_command_block_regs((ide_adapter_channel_info *)channel_cookie, tf, mask);
45 static uint8
46 get_altstatus(void *channel_cookie)
48 return ide_adapter->get_altstatus((ide_adapter_channel_info *)channel_cookie);
52 static status_t
53 write_device_control(void *channel_cookie, uint8 val)
55 return ide_adapter->write_device_control((ide_adapter_channel_info *)channel_cookie, val);
59 static status_t
60 write_pio(void *channel_cookie, uint16 *data, int count, bool force_16bit)
62 return ide_adapter->write_pio((ide_adapter_channel_info *)channel_cookie, data, count, force_16bit);
66 static status_t
67 read_pio(void *channel_cookie, uint16 *data, int count, bool force_16bit)
69 return ide_adapter->read_pio((ide_adapter_channel_info *)channel_cookie, data, count, force_16bit);
73 static status_t
74 prepare_dma(void *channel_cookie,
75 const physical_entry *sg_list, size_t sg_list_count,
76 bool to_device)
78 return ide_adapter->prepare_dma((ide_adapter_channel_info *)channel_cookie, sg_list, sg_list_count, to_device);
82 static status_t
83 start_dma(void *channel_cookie)
85 return ide_adapter->start_dma((ide_adapter_channel_info *)channel_cookie);
89 static status_t
90 finish_dma(void *channel_cookie)
92 return ide_adapter->finish_dma((ide_adapter_channel_info *)channel_cookie);
96 static status_t
97 init_channel(device_node *node, void **channel_cookie)
99 return ide_adapter->init_channel(node,
100 (ide_adapter_channel_info **)channel_cookie,
101 sizeof(ide_adapter_channel_info), ide_adapter->inthand);
105 static void
106 uninit_channel(void *channel_cookie)
108 ide_adapter->uninit_channel((ide_adapter_channel_info *)channel_cookie);
112 static void
113 channel_removed(void *channel_cookie)
115 ide_adapter->channel_removed((ide_adapter_channel_info *)channel_cookie);
119 static status_t
120 init_controller(device_node *node, ide_adapter_controller_info **cookie)
122 return ide_adapter->init_controller(node, cookie,
123 sizeof( ide_adapter_controller_info));
127 static void
128 uninit_controller(ide_adapter_controller_info *controller)
130 ide_adapter->uninit_controller(controller);
134 static void
135 controller_removed(ide_adapter_controller_info *controller)
137 return ide_adapter->controller_removed(controller);
141 static status_t
142 probe_controller(device_node *parent)
144 return ide_adapter->probe_controller(parent,
145 GENERIC_IDE_PCI_CONTROLLER_MODULE_NAME, "generic_ide_pci",
146 "Generic IDE PCI Controller",
147 GENERIC_IDE_PCI_CHANNEL_MODULE_NAME,
148 true,
149 true, // assume that command queuing works
150 1, // assume 16 bit alignment is enough
151 0xffff, // boundary is on 64k according to spec
152 0x10000, // up to 64k per S/G block according to spec
153 true); // by default, compatibility mode is used
157 static float
158 supports_device(device_node *parent)
160 const char *bus;
161 uint16 baseClass, subClass;
163 // make sure parent is an PCI IDE mass storage host adapter device node
164 if (pnp->get_attr_string(parent, B_DEVICE_BUS, &bus, false) != B_OK
165 || pnp->get_attr_uint16(parent, B_DEVICE_TYPE, &baseClass, false) != B_OK
166 || pnp->get_attr_uint16(parent, B_DEVICE_SUB_TYPE, &subClass, false) != B_OK)
167 return -1;
169 if (strcmp(bus, "pci") || baseClass != PCI_mass_storage)
170 return 0.0f;
172 if (subClass == PCI_ide)
173 return 0.3f;
175 // vendor 105a: Promise Technology, Inc.; device 4d69: 20269 (Ultra133TX2)
176 // has subClass set to PCI_mass_storage_other, and there are others as well.
177 if (subClass == PCI_mass_storage_other)
178 return 0.3f;
180 return 0.0f;
184 module_dependency module_dependencies[] = {
185 { IDE_FOR_CONTROLLER_MODULE_NAME, (module_info **)&ide },
186 { B_DEVICE_MANAGER_MODULE_NAME, (module_info **)&pnp },
187 { IDE_ADAPTER_MODULE_NAME, (module_info **)&ide_adapter },
192 // exported interface
193 static ide_controller_interface channel_interface = {
196 GENERIC_IDE_PCI_CHANNEL_MODULE_NAME,
198 NULL
201 NULL, // supports device
202 NULL, // register device
203 init_channel,
204 uninit_channel,
205 NULL, // register child devices
206 NULL, // rescan
207 channel_removed,
210 &set_channel,
212 &write_command_block_regs,
213 &read_command_block_regs,
215 &get_altstatus,
216 &write_device_control,
218 &write_pio,
219 &read_pio,
221 &prepare_dma,
222 &start_dma,
223 &finish_dma,
227 static driver_module_info controller_interface = {
229 GENERIC_IDE_PCI_CONTROLLER_MODULE_NAME,
231 NULL
234 supports_device,
235 probe_controller,
236 (status_t (*)(device_node *, void **)) init_controller,
237 (void (*)(void *)) uninit_controller,
238 NULL, // register child devices
239 NULL, // rescan
240 (void (*)(void *)) controller_removed,
243 module_info *modules[] = {
244 (module_info *)&controller_interface,
245 (module_info *)&channel_interface,
246 NULL