The Pedigree Project 0.1
AtaController.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_CONTROLLER_H
21#define ATA_CONTROLLER_H
22
23#include "pedigree/kernel/Log.h"
24#include "pedigree/kernel/machine/IrqHandler.h"
25#include "pedigree/kernel/machine/types.h"
26#include "pedigree/kernel/processor/types.h"
27#include "pedigree/kernel/utilities/RequestQueue.h"
28#include "pedigree/kernel/utilities/String.h"
29#include "pedigree/kernel/utilities/Vector.h"
30
31#include "modules/drivers/common/scsi/ScsiController.h"
32
33class Controller;
34class IoBase;
35
37class AtaController : public ScsiController, public IrqHandler {
38 public:
39 AtaController(Controller* pDev, int nController = 0, bool startWorker = true)
40 : ScsiController(pDev, startWorker), m_nController(nController) {
41 setSpecificType(String("ata-controller"));
42
43 // Ensure we have no stupid children lying around.
45 }
46 virtual ~AtaController() {}
47
49 virtual void shutdown() = 0;
50
51 virtual void getName(String& str) = 0;
52
53 virtual bool compareRequests(const RequestQueue::Request& a, const RequestQueue::Request& b);
54
55 // IRQ handler callback.
56 virtual IrqDisposition irq(irq_id_t number) {
57 NOTICE("AtaController: irq" << Dec << number << Hex << " ignored");
58 return IrqDisposition::NotHandled;
59 }
60
61 IoBase* m_pCommandRegs;
62 IoBase* m_pControlRegs;
63
64 private:
66 void operator=(const AtaController&);
67
68 protected:
71 static bool canCoalesceCanonicalRequests(uint64_t aType, uint64_t aDisk, uint64_t aLocation,
72 uint64_t bType, uint64_t bDisk, uint64_t bLocation) {
73 return aType == SCSI_REQUEST_READ && bType == SCSI_REQUEST_READ && aDisk == bDisk &&
74 aLocation == bLocation;
75 }
76
77 bool beginShutdown() {
78 if (m_bShutdown) {
79 return false;
80 }
81 m_bShutdown = true;
82 return true;
83 }
84
85 int m_nController;
86
88 void maskDiskInterrupts();
89
91 void stopDiskDma();
92
93 virtual size_t getNumUnits() {
94 return getNumChildren();
95 }
96
97 private:
98 bool m_bShutdown = false;
99};
100
101#endif
virtual void getName(String &str)=0
virtual IrqDisposition irq(irq_id_t number)
virtual void shutdown()=0
void maskDiskInterrupts()
static bool canCoalesceCanonicalRequests(uint64_t aType, uint64_t aDisk, uint64_t aLocation, uint64_t bType, uint64_t bDisk, uint64_t bLocation)
virtual bool compareRequests(const RequestQueue::Request &a, const RequestQueue::Request &b)
size_t getNumChildren()
Definition Device.cc:131
virtual void setSpecificType(String str)
Definition Device.h:182
Vector< Device * > m_Children
Definition Device.h:334
Abstrace base class for hardware I/O capabilities.
Definition IoBase.h:32
@ Dec
Definition Log.h:126
@ Hex
Definition Log.h:124
IrqDisposition
Definition IrqHandler.h:31
void clear(bool freeMem=false)
Definition Vector.h:378