singrdk/base/Kernel/Singularity.Drivers/PseudoBus.cs

116 lines
2.8 KiB
C#
Raw Permalink Normal View History

2008-03-05 09:52:00 -05:00
///////////////////////////////////////////////////////////////////////////////
//
// Microsoft Research Singularity
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// File: PseudoBus.cs
//
// Note:
//
using Microsoft.Singularity.Channels;
using Microsoft.Singularity.Io;
using System;
using System.Collections;
namespace Microsoft.Singularity.Drivers
{
2008-11-17 18:29:00 -05:00
// create the resource object for CTR to fill in
[DriverCategory]
[Signature("/root/pseudobus0")]
[EnumeratesDevice("pseudo/...")]
internal class PseudoBusResources : DriverCategoryDeclaration
{
}
2008-03-05 09:52:00 -05:00
/// <summary>
/// Bus for pseudo-devices. A pseudo-device is typically a
/// layer in I/O stack that may or may not be associated
/// with one or more physical devices.
/// </summary>
public class PseudoBus : IBusDevice
{
public const string Name = "/pseudo0";
private static PseudoBus instance = null;
private SortedList! pseudoDevices;
2008-11-17 18:29:00 -05:00
internal PseudoBus()
2008-03-05 09:52:00 -05:00
{
pseudoDevices = new SortedList();
}
2008-11-17 18:29:00 -05:00
void IDevice.Initialize()
2008-03-05 09:52:00 -05:00
{
2008-11-17 18:29:00 -05:00
DebugStub.Print("Initializing PseudoBusDevice.\n");
instance = this;
RegisterBootPseudoDevices();
2008-03-05 09:52:00 -05:00
}
2008-11-17 18:29:00 -05:00
void IDevice.Finalize()
2008-03-05 09:52:00 -05:00
{
}
2008-11-17 18:29:00 -05:00
internal void RegisterPseudoDevice(string! name, IoConfig config)
2008-03-05 09:52:00 -05:00
{
2008-11-17 18:29:00 -05:00
pseudoDevices.Add(name, config);
2008-03-05 09:52:00 -05:00
}
SortedList IBusDevice.Enumerate()
{
return pseudoDevices;
}
2008-11-17 18:29:00 -05:00
//
// Register boot time pseudo devices
//
internal void RegisterBootPseudoDevices()
2008-03-05 09:52:00 -05:00
{
2008-11-17 18:29:00 -05:00
// Pseudo Devices have no resources (I/O ports, memory, etc.)
if (instance != null) {
PseudoConfig config = new PseudoConfig("iotest");
instance.RegisterPseudoDevice("/test/iotest", config);
}
2008-03-05 09:52:00 -05:00
}
2008-11-17 18:29:00 -05:00
// Allows us to be registered as a root level driver
public PseudoConfig! ReportConfig()
2008-03-05 09:52:00 -05:00
{
2008-11-17 18:29:00 -05:00
PseudoConfig config = new PseudoConfig("root");
return config;
2008-03-05 09:52:00 -05:00
}
}
public class PseudoConfig : IoConfig
{
static private int count = 0;
public PseudoConfig(string className)
{
string[] ids = { String.Format("/pseudo0{0}/{1}", className, count++) };
this.Ids = ids;
}
public override string! ToString()
{
assert Ids != null;
assert Ids.Length > 0;
string id = Ids[0];
assert id != null;
return id;
}
public override string ToPrint()
{
return ToString();
}
}
}
2008-11-17 18:29:00 -05:00