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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc1/] [or1ksim/] [peripheral/] [atadevice.h] - Blame information for rev 1726

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

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

powered by: WebSVN 2.1.0

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