PATADiskDevice.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include <AK/Memory.h>
  27. #include <AK/StringView.h>
  28. #include <Kernel/FileSystem/FileDescription.h>
  29. #include <Kernel/Storage/IDEChannel.h>
  30. #include <Kernel/Storage/IDEController.h>
  31. #include <Kernel/Storage/PATADiskDevice.h>
  32. namespace Kernel {
  33. UNMAP_AFTER_INIT NonnullRefPtr<PATADiskDevice> PATADiskDevice::create(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 cylinders, u16 heads, u16 spt, u16 capabilities, int major, int minor)
  34. {
  35. return adopt(*new PATADiskDevice(controller, channel, type, interface_type, cylinders, heads, spt, capabilities, major, minor));
  36. }
  37. UNMAP_AFTER_INIT PATADiskDevice::PATADiskDevice(const IDEController& controller, IDEChannel& channel, DriveType type, InterfaceType interface_type, u16 cylinders, u16 heads, u16 spt, u16 capabilities, int major, int minor)
  38. : StorageDevice(controller, major, minor, 512, 0)
  39. , m_cylinders(cylinders)
  40. , m_heads(heads)
  41. , m_sectors_per_track(spt)
  42. , m_capabilities(capabilities)
  43. , m_channel(channel)
  44. , m_drive_type(type)
  45. , m_interface_type(interface_type)
  46. {
  47. }
  48. UNMAP_AFTER_INIT PATADiskDevice::~PATADiskDevice()
  49. {
  50. }
  51. const char* PATADiskDevice::class_name() const
  52. {
  53. return "PATADiskDevice";
  54. }
  55. void PATADiskDevice::start_request(AsyncBlockDeviceRequest& request)
  56. {
  57. bool use_dma = !m_channel.m_io_group.bus_master_base().is_null() && m_channel.m_dma_enabled.resource();
  58. m_channel.start_request(request, use_dma, is_slave(), m_capabilities);
  59. }
  60. String PATADiskDevice::device_name() const
  61. {
  62. return String::formatted("hd{:c}", 'a' + minor());
  63. }
  64. size_t PATADiskDevice::max_addressable_block() const
  65. {
  66. return m_cylinders * m_heads * m_sectors_per_track;
  67. }
  68. bool PATADiskDevice::is_slave() const
  69. {
  70. return m_drive_type == DriveType::Slave;
  71. }
  72. }