2 * Copyright (c) 2024 Jiri Svoboda
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /** @addtogroup pci-ide
32 /** @file PCI IDE driver definitions.
39 #include <ata/ata_hw.h>
40 #include <ddf/driver.h>
41 #include <fibril_synch.h>
44 #include "pci-ide_hw.h"
46 #define NAME "pci-ide"
48 /** PCI IDE hardware resources */
50 uintptr_t bmregs
; /** PCI Bus Master register block base address. */
51 uintptr_t cmd1
; /**< Primary channel command block base address. */
52 uintptr_t ctl1
; /**< Primary channel control block base address. */
53 uintptr_t cmd2
; /**< Secondary channel command block base address. */
54 uintptr_t ctl2
; /**< Secondary channel control block base address. */
55 int irq1
; /**< Primary channel IRQ */
56 int irq2
; /**< Secondary channel IRQ */
59 /** PCI IDE channel */
60 typedef struct pci_ide_channel
{
61 /** Parent controller */
62 struct pci_ide_ctrl
*ctrl
;
63 /** I/O base address of the command registers */
64 uintptr_t cmd_physical
;
65 /** I/O base address of the control registers */
66 uintptr_t ctl_physical
;
68 /** Command registers */
70 /** Control registers */
72 /** IRQ (-1 if not used) */
75 cap_irq_handle_t ihandle
;
77 /** Synchronize controller access */
79 /** Value of status register read by interrupt handler */
82 /** Physical region descriptor table */
84 /** Physical region descriptor table physical address */
88 /** DMA buffer physical address */
90 /** DMA buffer size */
92 /** Current DMA transfer direction */
93 ata_dma_dir_t cur_dir
;
94 /** Current data buffer */
96 /** Current data buffer size */
99 /** Libata ATA channel */
100 ata_channel_t
*channel
;
101 struct pci_ide_fun
*fun
[2];
107 /** ISA IDE controller */
108 typedef struct pci_ide_ctrl
{
112 /** I/O base address of bus master IDE registers */
113 uintptr_t bmregs_physical
;
114 /** Bus master IDE registers */
115 pci_ide_regs_t
*bmregs
;
116 /** Primary and secondary channel */
117 pci_ide_channel_t channel
[2];
120 /** PCI IDE function */
121 typedef struct pci_ide_fun
{
126 extern errno_t
pci_ide_ctrl_init(pci_ide_ctrl_t
*, pci_ide_hwres_t
*);
127 extern errno_t
pci_ide_ctrl_fini(pci_ide_ctrl_t
*);
128 extern errno_t
pci_ide_channel_init(pci_ide_ctrl_t
*, pci_ide_channel_t
*,
129 unsigned, pci_ide_hwres_t
*);
130 extern errno_t
pci_ide_channel_fini(pci_ide_channel_t
*);