The Pedigree Project  0.1
AtaDisk.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef ATA_ATA_DISK_H
21 #define ATA_ATA_DISK_H
22 
23 #include "BusMasterIde.h"
24 #include "ata-common.h"
25 #include "modules/drivers/common/scsi/ScsiDisk.h"
26 #include "pedigree/kernel/Atomic.h"
27 #include "pedigree/kernel/process/ConditionVariable.h"
28 #include "pedigree/kernel/process/Mutex.h"
29 #include "pedigree/kernel/processor/MemoryRegion.h"
30 #include "pedigree/kernel/processor/types.h"
31 #include "pedigree/kernel/utilities/String.h"
32 
33 class IoBase;
34 
42 class AtaDisk : public ScsiDisk
43 {
44  private:
45  enum AtaDiskType
46  {
47  Block = 0x00,
48  Sequential = 0x01,
49  Printer = 0x02,
50  Processor = 0x03,
51  WriteOnce = 0x04,
52  CdDvd = 0x05,
53  OpticalMemory = 0x07,
54  MediumChanger = 0x08,
55  Raid = 0x0C,
56  Enclosure = 0x0D,
57  None = 0x1F,
58  NotPacket = 0xFF,
59  };
60 
61  public:
62  AtaDisk(
63  class AtaController *pDev, bool isMaster, IoBase *commandRegs,
64  IoBase *controlRegs, BusMasterIde *busMaster = 0);
65  virtual ~AtaDisk();
66 
67  virtual void getName(String &str)
68  {
69  str = m_pName;
70  }
71 
76  bool initialise(size_t nUnit = ~0);
77 
78  // Do-ers for read/write operations. For PACKET devices, these forward to
79  // the ScsiDisk implementations. For non-PACKET devices, these perform real
80  // disk I/O.
81  virtual uint64_t doRead(uint64_t location);
82  virtual uint64_t doWrite(uint64_t location);
83 
85  virtual void irqReceived();
86 
88  virtual BusMasterIde *getBusMaster() const
89  {
90  return m_BusMaster;
91  }
92 
93  virtual size_t getSize() const;
94  virtual size_t getBlockSize() const;
95  virtual size_t getNativeBlockSize() const;
96  virtual size_t getBlockCount() const;
97 
98  // SCSI controller interface calls this to send a PACKET command.
99  virtual bool sendCommand(
100  size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize,
101  uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite);
102 
103  private:
105  void setupLBA28(uint64_t n, uint32_t nSectors);
107  void setupLBA48(uint64_t n, uint32_t nSectors);
108 
110  virtual size_t defaultBlockSize()
111  {
112  if (m_AtaDiskType == CdDvd)
113  {
114  return 2048;
115  }
116  else
117  {
118  return 512;
119  }
120  }
121 
123  struct Buffer
124  {
126  uintptr_t buffer;
127 
129  size_t offset;
130  };
131 
134 
138  char m_pName[64];
140  char m_pSerialNumber[64];
148  size_t m_BlockSize;
149 
156  Mutex m_IrqLock;
157  ConditionVariable m_IrqCondition;
158 
160  AtaDiskType m_AtaDiskType;
161 
163  uint8_t m_PacketSize;
164 
167 
169  void setFeatures(
170  uint8_t command, uint8_t countreg, uint8_t lowreg, uint8_t midreg,
171  uint8_t hireg);
172 
175  IoBase *m_ControlRegs;
176  BusMasterIde *m_BusMaster;
177 
180 
182  PhysicalRegionDescriptor *m_PrdTable;
183 
187 
189  physical_uintptr_t m_PrdTablePhys;
190 
193 
195  bool m_bDma;
196 
199 };
200 
201 #endif
bool initialise(size_t nUnit=~0)
Definition: AtaDisk.cc:60
physical_uintptr_t m_PrdTablePhys
Definition: AtaDisk.h:189
char m_pName[64]
Definition: AtaDisk.h:138
void setFeatures(uint8_t command, uint8_t countreg, uint8_t lowreg, uint8_t midreg, uint8_t hireg)
Definition: AtaDisk.cc:1210
virtual size_t getBlockSize() const
Gets the block size of the disk.
Definition: AtaDisk.cc:1261
virtual BusMasterIde * getBusMaster() const
Definition: AtaDisk.h:88
bool m_bDma
Definition: AtaDisk.h:195
Mutex * m_IrqReceived
Definition: AtaDisk.h:155
void setupLBA48(uint64_t n, uint32_t nSectors)
Definition: AtaDisk.cc:1186
bool m_Removable
Definition: AtaDisk.h:166
Definition: Mutex.h:58
virtual uint64_t doWrite(uint64_t location)
Definition: AtaDisk.cc:943
bool m_IsMaster
Definition: AtaDisk.h:133
size_t m_BlockSize
Definition: AtaDisk.h:148
Definition: String.h:49
MemoryRegion m_PrdTableMemRegion
Definition: AtaDisk.h:192
virtual size_t defaultBlockSize()
Definition: AtaDisk.h:110
Abstrace base class for hardware I/O capabilities.
Definition: IoBase.h:31
IdentifyData m_pIdent
Definition: AtaDisk.h:136
virtual uint64_t doRead(uint64_t location)
Definition: AtaDisk.cc:681
virtual size_t getNativeBlockSize() const
Definition: AtaDisk.cc:1270
size_t offset
Offset into the read.
Definition: AtaDisk.h:129
size_t m_LastPrdTableOffset
Definition: AtaDisk.h:186
virtual bool sendCommand(size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize, uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite)
Definition: AtaDisk.cc:470
Special memory entity in the kernel's virtual address space.
Definition: MemoryRegion.h:35
virtual void irqReceived()
Definition: AtaDisk.cc:1156
The exception was caused by a hardware task switch.
Definition: Processor.h:80
IoBase * m_CommandRegs
Definition: AtaDisk.h:174
Atomic< size_t > m_IrqCount
Definition: AtaDisk.h:198
void setupLBA28(uint64_t n, uint32_t nSectors)
Definition: AtaDisk.cc:1162
bool m_SupportsLBA48
Definition: AtaDisk.h:146
PhysicalRegionDescriptor * m_PrdTable
Definition: AtaDisk.h:182
AtaDiskType m_AtaDiskType
Definition: AtaDisk.h:160
uintptr_t buffer
Virtual address of buffer to read into (page sized).
Definition: AtaDisk.h:126
uint8_t m_PacketSize
Definition: AtaDisk.h:163
virtual size_t getSize() const
Gets the size of the disk.
Definition: AtaDisk.cc:1228
virtual void getName(String &str)
Definition: AtaDisk.h:67
bool m_SupportsLBA28
Definition: AtaDisk.h:144
char m_pSerialNumber[64]
Definition: AtaDisk.h:140
char m_pFirmwareRevision[64]
Definition: AtaDisk.h:142
Mutex m_PrdTableLock
Definition: AtaDisk.h:179