summaryrefslogtreecommitdiffhomepage
path: root/src/boot/BootKit/HW/ATA.h
blob: 25629869d58ec10808365ed8c1c45995cf96fa91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/* ========================================

  Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.

======================================== */

#pragma once

#include <BootKit/Device.h>
#include <modules/ATA/ATA.h>

using namespace Kernel;

class BootDeviceATA final : public Device {
 public:
  enum {
    kPrimary   = ATA_PRIMARY_IO,
    kSecondary = ATA_SECONDARY_IO,
  };

  explicit BootDeviceATA() noexcept;
  ~BootDeviceATA() = default;

  enum { kSectorSize = kATASectorSize };

  struct ATATrait final : public Device::Trait {
    UInt16  mBus{kPrimary};
    UInt8   mMaster{0};
    Boolean mErr{false};

    operator bool() { return !mErr; }
  };

 public:
  operator bool();

  SizeT GetSectorsCount() noexcept;
  SizeT GetDiskSize() noexcept;

  BootDeviceATA& Read(Char* Buf, SizeT SecCount) override;
  BootDeviceATA& Write(Char* Buf, SizeT SecCount) override;

  ATATrait& Leak() override;

 private:
  ATATrait mTrait;
};