2 * Copyright 2002/03, Thomas Kurschel. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 /*! Generic PCI bus mastering IDE driver. */
8 #include <KernelExport.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
;
25 set_channel(void *cookie
, ide_channel channel
)
27 ide_adapter
->set_channel((ide_adapter_channel_info
*)cookie
, channel
);
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
);
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
);
46 get_altstatus(void *channel_cookie
)
48 return ide_adapter
->get_altstatus((ide_adapter_channel_info
*)channel_cookie
);
53 write_device_control(void *channel_cookie
, uint8 val
)
55 return ide_adapter
->write_device_control((ide_adapter_channel_info
*)channel_cookie
, val
);
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
);
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
);
74 prepare_dma(void *channel_cookie
,
75 const physical_entry
*sg_list
, size_t sg_list_count
,
78 return ide_adapter
->prepare_dma((ide_adapter_channel_info
*)channel_cookie
, sg_list
, sg_list_count
, to_device
);
83 start_dma(void *channel_cookie
)
85 return ide_adapter
->start_dma((ide_adapter_channel_info
*)channel_cookie
);
90 finish_dma(void *channel_cookie
)
92 return ide_adapter
->finish_dma((ide_adapter_channel_info
*)channel_cookie
);
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
);
106 uninit_channel(void *channel_cookie
)
108 ide_adapter
->uninit_channel((ide_adapter_channel_info
*)channel_cookie
);
113 channel_removed(void *channel_cookie
)
115 ide_adapter
->channel_removed((ide_adapter_channel_info
*)channel_cookie
);
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
));
128 uninit_controller(ide_adapter_controller_info
*controller
)
130 ide_adapter
->uninit_controller(controller
);
135 controller_removed(ide_adapter_controller_info
*controller
)
137 return ide_adapter
->controller_removed(controller
);
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
,
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
158 supports_device(device_node
*parent
)
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
)
169 if (strcmp(bus
, "pci") || baseClass
!= PCI_mass_storage
)
172 if (subClass
== PCI_ide
)
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
)
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
,
201 NULL
, // supports device
202 NULL
, // register device
205 NULL
, // register child devices
212 &write_command_block_regs
,
213 &read_command_block_regs
,
216 &write_device_control
,
227 static driver_module_info controller_interface
= {
229 GENERIC_IDE_PCI_CONTROLLER_MODULE_NAME
,
236 (status_t (*)(device_node
*, void **)) init_controller
,
237 (void (*)(void *)) uninit_controller
,
238 NULL
, // register child devices
240 (void (*)(void *)) controller_removed
,
243 module_info
*modules
[] = {
244 (module_info
*)&controller_interface
,
245 (module_info
*)&channel_interface
,