1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: PCI IDE bus driver
4 * FILE: drivers/storage/pciide/pciide.c
5 * PURPOSE: Main file
6 * PROGRAMMERS: Herv� Poussineau (hpoussin@reactos.org)
7 */
8
9 #include "pciide.h"
10
11 #define NDEBUG
12 #include <debug.h>
13
14 IDE_CHANNEL_STATE NTAPI
PciIdeChannelEnabled(IN PVOID DeviceExtension,IN ULONG Channel)15 PciIdeChannelEnabled(
16 IN PVOID DeviceExtension,
17 IN ULONG Channel)
18 {
19 PCI_COMMON_CONFIG PciConfig;
20 NTSTATUS Status;
21
22 DPRINT("PciIdeChannelEnabled(%p, %lu)\n", DeviceExtension, Channel);
23
24 Status = PciIdeXGetBusData(
25 DeviceExtension,
26 &PciConfig,
27 0,
28 PCI_COMMON_HDR_LENGTH);
29 if (!NT_SUCCESS(Status))
30 {
31 DPRINT("PciIdeXGetBusData() failed with status 0x%08lx\n", Status);
32 return ChannelStateUnknown;
33 }
34
35 if (PCI_CONFIGURATION_TYPE(&PciConfig) != PCI_DEVICE_TYPE)
36 {
37 DPRINT("Wrong PCI card type. Disabling IDE channel #%lu\n", Channel);
38 return ChannelDisabled;
39 }
40
41 if (PciConfig.BaseClass != PCI_CLASS_MASS_STORAGE_CTLR || PciConfig.SubClass != PCI_SUBCLASS_MSC_IDE_CTLR)
42 {
43 DPRINT("Wrong PCI card base class/sub class. Disabling IDE channel #%lu\n", Channel);
44 return ChannelDisabled;
45 }
46
47 return ChannelStateUnknown;
48 }
49
50 BOOLEAN NTAPI
PciIdeSyncAccessRequired(IN PVOID DeviceExtension)51 PciIdeSyncAccessRequired(
52 IN PVOID DeviceExtension)
53 {
54 DPRINT1("PciIdeSyncAccessRequired %p\n", DeviceExtension);
55
56 return FALSE; /* FIXME */
57 }
58
59 NTSTATUS NTAPI
PciIdeTransferModeSelect(IN PVOID DeviceExtension,IN PPCIIDE_TRANSFER_MODE_SELECT XferMode)60 PciIdeTransferModeSelect(
61 IN PVOID DeviceExtension,
62 IN PPCIIDE_TRANSFER_MODE_SELECT XferMode)
63 {
64 ULONG i;
65
66 DPRINT1("PciIdeTransferModeSelect(%p %p)\n", DeviceExtension, XferMode);
67
68 for (i = 0; i < MAX_IDE_DEVICE; i++)
69 XferMode->DevicePresent[i] = FALSE; /* FIXME */
70
71 return STATUS_SUCCESS;
72 }
73
74 ULONG NTAPI
PciIdeUseDma(IN PVOID DeviceExtension,IN PUCHAR CdbCommand,IN PUCHAR Slave)75 PciIdeUseDma(
76 IN PVOID DeviceExtension,
77 IN PUCHAR CdbCommand,
78 IN PUCHAR Slave)
79 {
80 DPRINT("PciIdeUseDma(%p %p %p)\n", DeviceExtension, CdbCommand, Slave);
81
82 /* Nothing should prevent us to use DMA */
83 return 1;
84 }
85
86 NTSTATUS NTAPI
PciIdeGetControllerProperties(IN PVOID DeviceExtension,OUT PIDE_CONTROLLER_PROPERTIES ControllerProperties)87 PciIdeGetControllerProperties(
88 IN PVOID DeviceExtension,
89 OUT PIDE_CONTROLLER_PROPERTIES ControllerProperties)
90 {
91 if (ControllerProperties->Size != sizeof(IDE_CONTROLLER_PROPERTIES))
92 return STATUS_REVISION_MISMATCH;
93
94 ControllerProperties->PciIdeChannelEnabled = PciIdeChannelEnabled;
95 ControllerProperties->PciIdeSyncAccessRequired = PciIdeSyncAccessRequired;
96 ControllerProperties->PciIdeTransferModeSelect = PciIdeTransferModeSelect;
97 ControllerProperties->IgnoreActiveBitForAtaDevice = FALSE;
98 ControllerProperties->AlwaysClearBusMasterInterrupt = TRUE;
99 ControllerProperties->PciIdeUseDma = PciIdeUseDma;
100 ControllerProperties->AlignmentRequirement = 1;
101 ControllerProperties->DefaultPIO = 0; /* FIXME */
102 ControllerProperties->PciIdeUdmaModesSupported = NULL; /* optional */
103
104 ControllerProperties->SupportedTransferMode[0][0] =
105 ControllerProperties->SupportedTransferMode[0][1] =
106 ControllerProperties->SupportedTransferMode[1][0] =
107 ControllerProperties->SupportedTransferMode[1][1] =
108 PIO_MODE0 | PIO_MODE1 | PIO_MODE2 | PIO_MODE3 | PIO_MODE4 |
109 SWDMA_MODE0 | SWDMA_MODE1 | SWDMA_MODE2 |
110 MWDMA_MODE0 | MWDMA_MODE1 | MWDMA_MODE2 |
111 UDMA_MODE0 | UDMA_MODE1 | UDMA_MODE2 | UDMA_MODE3 | UDMA_MODE4;
112
113 return STATUS_SUCCESS;
114 }
115
116 NTSTATUS NTAPI
DriverEntry(IN PDRIVER_OBJECT DriverObject,IN PUNICODE_STRING RegistryPath)117 DriverEntry(
118 IN PDRIVER_OBJECT DriverObject,
119 IN PUNICODE_STRING RegistryPath)
120 {
121 NTSTATUS Status;
122
123 Status = PciIdeXInitialize(
124 DriverObject,
125 RegistryPath,
126 PciIdeGetControllerProperties,
127 0);
128
129 return Status;
130 }
131