[dc5647e] | 1 | /*
|
---|
[07039850] | 2 | * Copyright (c) 2025 Jiri Svoboda
|
---|
[dc5647e] | 3 | * All rights reserved.
|
---|
| 4 | *
|
---|
| 5 | * Redistribution and use in source and binary forms, with or without
|
---|
| 6 | * modification, are permitted provided that the following conditions
|
---|
| 7 | * are met:
|
---|
| 8 | *
|
---|
| 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.
|
---|
| 16 | *
|
---|
| 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.
|
---|
| 27 | */
|
---|
| 28 |
|
---|
| 29 | /** @addtogroup pc-floppy
|
---|
| 30 | * @{
|
---|
| 31 | */
|
---|
| 32 | /** @file PC floppy disk driver
|
---|
| 33 | */
|
---|
| 34 |
|
---|
| 35 | #ifndef PC_FLOPPY_H
|
---|
| 36 | #define PC_FLOPPY_H
|
---|
| 37 |
|
---|
| 38 | #include <bd_srv.h>
|
---|
| 39 | #include <ddf/driver.h>
|
---|
| 40 | #include <fibril_synch.h>
|
---|
| 41 | #include <stdbool.h>
|
---|
| 42 | #include <stdint.h>
|
---|
| 43 | #include "pc-floppy_hw.h"
|
---|
| 44 |
|
---|
| 45 | #define NAME "pc-floppy"
|
---|
| 46 |
|
---|
| 47 | /** PC floppy controller hardware resources */
|
---|
| 48 | typedef struct {
|
---|
| 49 | /** I/O registers */
|
---|
| 50 | uintptr_t regs;
|
---|
| 51 | /** IRQ */
|
---|
| 52 | int irq;
|
---|
| 53 | /** DMA channel */
|
---|
| 54 | int dma;
|
---|
| 55 | } pc_fdc_hwres_t;
|
---|
| 56 |
|
---|
| 57 | /** PC floppy disk controller */
|
---|
| 58 | typedef struct pc_fdc {
|
---|
| 59 | /** DDF device */
|
---|
| 60 | ddf_dev_t *dev;
|
---|
| 61 | /** I/O base address of the registers */
|
---|
| 62 | uintptr_t regs_physical;
|
---|
| 63 |
|
---|
| 64 | /** Command registers */
|
---|
| 65 | pc_fdc_regs_t *regs;
|
---|
| 66 | /** IRQ (-1 if not used) */
|
---|
| 67 | int irq;
|
---|
| 68 | /** DMA (-1 if not used) */
|
---|
| 69 | int dma;
|
---|
| 70 | /** IRQ handle */
|
---|
| 71 | cap_irq_handle_t ihandle;
|
---|
| 72 |
|
---|
| 73 | /** DMA buffer */
|
---|
| 74 | void *dma_buf;
|
---|
| 75 | /** DMA buffer physical address */
|
---|
| 76 | uintptr_t dma_buf_pa;
|
---|
| 77 | /** DMA buffer size */
|
---|
| 78 | size_t dma_buf_size;
|
---|
| 79 |
|
---|
| 80 | /** Synchronize controller access */
|
---|
| 81 | fibril_mutex_t lock;
|
---|
| 82 |
|
---|
| 83 | struct pc_fdc_drive *drive[2];
|
---|
| 84 | } pc_fdc_t;
|
---|
| 85 |
|
---|
| 86 | /** PC floppy drive */
|
---|
| 87 | typedef struct pc_fdc_drive {
|
---|
| 88 | pc_fdc_t *fdc;
|
---|
| 89 | ddf_fun_t *fun;
|
---|
| 90 | void *charg;
|
---|
| 91 | size_t sec_size;
|
---|
| 92 | unsigned cylinders;
|
---|
| 93 | unsigned heads;
|
---|
| 94 | unsigned sectors;
|
---|
| 95 | bd_srvs_t bds;
|
---|
| 96 | } pc_fdc_drive_t;
|
---|
| 97 |
|
---|
| 98 | extern errno_t pc_fdc_create(ddf_dev_t *, pc_fdc_hwres_t *, pc_fdc_t **);
|
---|
[07039850] | 99 | extern void pc_fdc_quiesce(pc_fdc_t *);
|
---|
[dc5647e] | 100 | extern errno_t pc_fdc_destroy(pc_fdc_t *);
|
---|
| 101 |
|
---|
| 102 | #endif
|
---|
| 103 |
|
---|
| 104 | /** @}
|
---|
| 105 | */
|
---|