OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [peripheral/] [atadevice.h] - Blame information for rev 857

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jeremybenn
/* atadevice.h -- ATA Device code simulation
2
 
3
   Copyright (C) 2002 Richard Herveille, rherveille@opencores.org
4
   Copyright (C) 2008 Embecosm Limited
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
 
23
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25
 
26
/*
27
 * Definitions for the Opencores ATA Controller Core, Device model
28
 */
29
 
30
#ifndef ATADEVICE__H
31
#define ATADEVICE__H
32
 
33
/* Autoconf and/or portability configuration */
34
#include "port.h"
35
 
36
/* System includes */
37
#include <stdio.h>
38
 
39
/* --- Register definitions --- */
40
/* ----- ATA Registers                                                */
41
/* These are actually the memory locations where the ATA registers    */
42
/* can be found in the host system; i.e. as seen from the CPU.        */
43
/* However, this doesn't matter for the simulator.                    */
44
#define ATA_ASR   0x78          /* Alternate Status Register      (R)  */
45
#define ATA_CR    0x5c          /* Command Register               (W)  */
46
#define ATA_CHR   0x54          /* Cylinder High Register       (R/W)  */
47
#define ATA_CLR   0x50          /* Cylinder Low Register        (R/W)  */
48
#define ATA_DR    0x40          /* Data Register                       */
49
#define ATA_DCR   0x78          /* Device Control Register        (W)  */
50
#define ATA_DHR   0x58          /* Device/Head Register         (R/W)  */
51
#define ATA_ERR   0x44          /* Error Register                 (R)  */
52
#define ATA_FR    0x44          /* Features Register              (W)  */
53
#define ATA_SCR   0x48          /* Sector Count Register        (R/W)  */
54
#define ATA_SNR   0x4c          /* Sector Number Register       (R/W)  */
55
#define ATA_SR    0x5c          /* Status Register                (R)  */
56
#define ATA_DA    0x7c          /* Device Address Register        (R)  */
57
             /* ATA/ATAPI-5 does not describe Device Status Register  */
58
 
59
/* --------------------------------------                             */
60
/* ----- ATA Device bit defenitions -----                             */
61
/* --------------------------------------                             */
62
 
63
/* ----- ATA (Alternate) Status Register                              */
64
#define ATA_SR_BSY  0x80        /* Busy                               */
65
#define ATA_SR_DRDY 0x40        /* Device Ready                       */
66
#define ATA_SR_DF   0x20        /* Device Fault                       */
67
#define ATA_SR_DSC  0x10        /* Device Seek Complete               */
68
#define ATA_SR_DRQ  0x08        /* Data Request                       */
69
#define ATA_SR_COR  0x04        /* Corrected data (obsolete)          */
70
#define ATA_SR_IDX  0x02        /*                (obsolete)          */
71
#define ATA_SR_ERR  0x01        /* Error                              */
72
 
73
/* ----- ATA Device Control Register                                  */
74
                                /* bits 7-3 are reserved              */
75
#define ATA_DCR_RST 0x04        /* Software reset   (RST=1, reset)    */
76
#define ATA_DCR_IEN 0x02        /* Interrupt Enable (IEN=0, enabled)  */
77
                                /* always write a '0' to bit0         */
78
 
79
/* ----- ATA Device Address Register                                  */
80
/* All values in this register are one's complement (i.e. inverted)   */
81
#define ATA_DAR_WTG 0x40        /* Write Gate                         */
82
#define ATA_DAR_H   0x3c        /* Head Select                        */
83
#define ATA_DAR_DS1 0x02        /* Drive select 1                     */
84
#define ATA_DAR_DS0 0x01        /* Drive select 0                     */
85
 
86
/* ----- Device/Head Register                                         */
87
#define ATA_DHR_LBA 0x40        /* LBA/CHS mode ('1'=LBA mode)        */
88
#define ATA_DHR_DEV 0x10        /* Device       ('0'=dev0, '1'=dev1)  */
89
#define ATA_DHR_H   0x0f        /* Head Select                        */
90
 
91
/* ----- Error Register                                               */
92
#define ATA_ERR_BBK  0x80       /* Bad Block                          */
93
#define ATA_ERR_UNC  0x40       /* Uncorrectable Data Error           */
94
#define ATA_ERR_IDNF 0x10       /* ID Not Found                       */
95
#define ATA_ERR_ABT  0x04       /* Aborted Command                    */
96
#define ATA_ERR_TON  0x02       /* Track0 Not Found                   */
97
#define ATA_ERR_AMN  0x01       /* Address Mark Not Found             */
98
 
99
/* --------------------------                                         */
100
/* ----- Device Defines -----                                         */
101
/* --------------------------                                         */
102
 
103
/* types for hard disk simulation                                     */
104
#define TYPE_NO_CONNECT 0
105
#define TYPE_FILE       1
106
#define TYPE_LOCAL      2
107
 
108
 
109
/* -----------------------------                                      */
110
/* ----- Statemachine defines --                                      */
111
/* -----------------------------                                      */
112
#define ATA_STATE_IDLE   0x00
113
#define ATA_STATE_SW_RST 0x01
114
#define ATA_STATE_HW_RST 0x02
115
 
116
 
117
/* ----------------------------                                       */
118
/* ----- Structs          -----                                       */
119
/* ----------------------------                                       */
120
struct ata_device
121
{
122
 
123
  /******* Housekeeping *****************************************/
124
  struct
125
  {
126
    /* Pointer to host that device is attached to         */
127
    void *host;
128
    /* device number                                      */
129
    int dev;
130
 
131
    /* current PIO mode                                   */
132
    int pio_mode;
133
 
134
    /* current DMA mode                                   */
135
    int dma_mode;
136
 
137
    /* databuffer                                         */
138
    uint16_t dbuf[4096];
139
    uint16_t *dbuf_ptr;
140
    uint16_t dbuf_cnt;
141
 
142
    /* current statemachine state                         */
143
    int state;
144
 
145
    /* current CHS translation settings                   */
146
    unsigned int heads_per_cylinder;
147
    unsigned int sectors_per_track;
148
 
149
    /* Current byte being read                            */
150
    uint32_t lba;
151
    /* Number of sectors still needing to be read         */
152
    int nr_sect;
153
    /* function to call when block of data has been transfered */
154
    void (*end_t_func) (struct ata_device *);
155
  } internals;
156
 
157
 
158
        /******* ATA Device Registers *********************************/
159
  struct
160
  {
161
    uint8_t command;
162
    uint8_t cylinder_low;
163
    uint8_t cylinder_high;
164
    uint8_t device_control;
165
    uint8_t device_head;
166
    uint8_t error;
167
    uint8_t features;
168
    uint8_t sector_count;
169
    uint8_t sector_number;
170
    uint8_t status;
171
 
172
    uint16_t dataport_i;
173
  } regs;
174
 
175
        /******** ata device output signals **************************/
176
  struct
177
  {
178
    int iordy;
179
    int intrq;
180
    int dmarq;
181
    int pdiagi, pdiago;
182
    int daspi, daspo;
183
  } sigs;
184
 
185
        /******** simulator settings **********************************/
186
  struct
187
  {
188
    char *file;         /* Filename (if type == FILE)                   */
189
    FILE *stream;       /* stream where the simulated device connects to */
190
    int type;           /* Simulate device using                        */
191
    /* NO_CONNECT: no device connected (dummy)      */
192
    /* FILE      : a file                           */
193
    /* LOCAL     : a local stream, e.g./dev/hda1    */
194
    uint32_t size;      /* size in bytes of the simulated device    */
195
    uint32_t size_sect; /* size in sectors of the simulated device */
196
    int packet;         /* device implements PACKET command set         */
197
 
198
    unsigned int heads;
199
    unsigned int sectors;
200
 
201
    char *firmware;
202
    unsigned int mwdma;
203
    unsigned int pio;
204
  } conf;
205
};
206
 
207
struct ata_devices
208
{
209
  struct ata_device device[2];
210
};
211
 
212
/* all devices                                                        */
213
void ata_devices_init (struct ata_devices *devices);
214
void ata_devices_hw_reset (struct ata_devices *devices, int reset_signal);
215
short ata_devices_read (struct ata_devices *devices, char adr);
216
void ata_devices_write (struct ata_devices *devices, char adr, short value);
217
 
218
#endif  /* ATADEVICE__H */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.