diff --git a/.gitignore b/.gitignore index 6c7dcd2..70f7247 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ __pycache__ .* *.cmd *.order -*.mod.c \ No newline at end of file +*.mod.c +*.out \ No newline at end of file diff --git a/dac.h b/dac.h new file mode 100644 index 0000000..849c667 --- /dev/null +++ b/dac.h @@ -0,0 +1,20 @@ +#define DAC__RS__PIXEL_ADDRESS_WRITE 0b000 +#define DAC__RS__PIXEL_ADDRESS_READ 0b011 +#define DAC__RS__COLOR_VALUE 0b001 +#define DAC__RS__PIXEL_MASK 0b010 +#define DAC__RS__PLL_ADDRESS_WRITE 0b100 +#define DAC__RS__PLL_PARAMETER 0b101 +#define DAC__RS__COMMAND 0b110 +#define DAC__RS__PLL_ADDRESS_READ 0b111 + +#define DAC__PLL_PARAMETER__CLK0_f0_PLL 0x00 +#define DAC__PLL_PARAMETER__CLK0_f1_PLL 0x01 +#define DAC__PLL_PARAMETER__CLK0_f2_PLL 0x02 +#define DAC__PLL_PARAMETER__CLK0_f3_PLL 0x03 +#define DAC__PLL_PARAMETER__CLK0_f4_PLL 0x04 +#define DAC__PLL_PARAMETER__CLK0_f5_PLL 0x05 +#define DAC__PLL_PARAMETER__CLK0_f6_PLL 0x06 +#define DAC__PLL_PARAMETER__CLK0_f7_PLL 0x07 +#define DAC__PLL_PARAMETER__CLK1_fA_PLL 0x0a +#define DAC__PLL_PARAMETER__CLK1_fB_PLL 0x0b +#define DAC__PLL_PARAMETER__PLL_CONTROL 0x0e diff --git a/gen/voodoo2.py b/gen/voodoo2.py index c4b3876..59e0166 100644 --- a/gen/voodoo2.py +++ b/gen/voodoo2.py @@ -205,6 +205,8 @@ def render_all(rls): yield "" yield from render_register_struct(rls, max_length) yield from render_static_assert(rls, max_length) + yield "" + yield "typedef struct voodoo2_reg voodoo2_reg;" with open(sys.argv[1], 'r') as f: buf = f.read() diff --git a/gen/voodoo2_config.py b/gen/voodoo2_config.py index 5fd43c3..954484e 100644 --- a/gen/voodoo2_config.py +++ b/gen/voodoo2_config.py @@ -83,6 +83,8 @@ def render_all(buf): yield '#include "reg.h"' yield "" yield from render_struct(buf) + yield "" + yield "typedef struct voodoo2_config voodoo2_config;" with open(sys.argv[1], 'r') as f: buf = f.read() diff --git a/main.c b/main.c index b93d496..6d3a766 100644 --- a/main.c +++ b/main.c @@ -8,6 +8,9 @@ #include #include "voodoo2.h" +#include "voodoo2_bits.h" +#include "voodoo2_config.h" +#include "dac.h" struct name_int { const char * name; @@ -81,10 +84,10 @@ static inline void dac_write_pll_8(voodoo2_reg * voodoo2, int address, int parameter_m) { - dac_data_write(voodoo2, address, DAC__RS__PLL_ADDRESS_WRITE, 0); + dac_data_write(voodoo2, address, DAC__RS__PLL_ADDRESS_WRITE); wait_graphics_busy(voodoo2); - dac_data_write(voodoo2, parameter_m, DAC__RS__PLL_PARAMETER, 0); + dac_data_write(voodoo2, parameter_m, DAC__RS__PLL_PARAMETER); wait_graphics_busy(voodoo2); } @@ -93,13 +96,13 @@ static inline void dac_write_pll_16(voodoo2_reg * voodoo2, int parameter_m, int parameter_n) { - dac_data_write(voodoo2, address, DAC__RS__PLL_ADDRESS_WRITE, 0); + dac_data_write(voodoo2, address, DAC__RS__PLL_ADDRESS_WRITE); wait_graphics_busy(voodoo2); - dac_data_write(voodoo2, parameter_m, DAC__RS__PLL_PARAMETER, 0); + dac_data_write(voodoo2, parameter_m, DAC__RS__PLL_PARAMETER); wait_graphics_busy(voodoo2); - dac_data_write(voodoo2, parameter_n, DAC__RS__PLL_PARAMETER, 0); + dac_data_write(voodoo2, parameter_n, DAC__RS__PLL_PARAMETER); wait_graphics_busy(voodoo2); } @@ -108,29 +111,44 @@ typedef struct mn { uint8_t n; } mn_t; -static inline struct mn_t dac_read_16(voodoo2_reg * voodoo, - int address) +static inline mn_t dac_read_pll_16(voodoo2_reg * voodoo2, + int address) { - dac_data_write(base, address, DAC__RS__PLL_ADDRESS_READ); - wait_graphics_busy(base); + dac_data_write(voodoo2, address, DAC__RS__PLL_ADDRESS_READ); + wait_graphics_busy(voodoo2); - dac_data_read(base, 0, DAC__RS__PLL_PARAMETER); - wait_graphics_busy(base); + dac_data_read(voodoo2, 0, DAC__RS__PLL_PARAMETER); + wait_graphics_busy(voodoo2); int m = voodoo2->fbiInit2 & 0xff; - dac_data_read(base, 0, DAC__RS__PLL_PARAMETER); - wait_graphics_busy(base); + dac_data_read(voodoo2, 0, DAC__RS__PLL_PARAMETER); + wait_graphics_busy(voodoo2); int n = voodoo2->fbiInit2 & 0xff; - return (struct m_n){ m, n }; + return (mn_t){ m, n }; } int main() { - const char * config = "/sys/bus/pci/devices/0000:02:0a.0/config"; - int fd = open(config, O_RDWR | O_SYNC); + const char * config_path = "/sys/bus/pci/devices/0000:02:0a.0/config"; + int fd = open(config_path, O_RDWR | O_SYNC); assert(fd >= 0); + uint32_t config_size = (sizeof (struct voodoo2_config)); + + void * config_base = mmap(0, config_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); + assert(config_base != MAP_FAILED); + voodoo2_config * config = (voodoo2_config *)config_base; + + printf("Vendor ID: %04x\n", config->Vendor_ID); + printf("Device ID: %04x\n", config->Device_ID); + + munmap(config_base, config_size); + close(fd); + + return 0; + + /* const char * filename = "/sys/bus/pci/devices/0000:02:0a.0/resource0"; int fd = open(filename, O_RDWR | O_SYNC); @@ -138,12 +156,12 @@ int main() uint32_t map_size = 0x4000; - off_t target_base = 0; - void * map_base = mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target_base); + void * map_base = mmap(0, map_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); assert(map_base != MAP_FAILED); struct voodoo2_reg * reg = (struct voodoo2_reg *)map_base; print_registers(reg); close(fd); + */ } diff --git a/voodoo2.h b/voodoo2.h index f7b29f2..c2a0fe5 100644 --- a/voodoo2.h +++ b/voodoo2.h @@ -3,8 +3,7 @@ #include #include -#include "reg32.h" - +#include "reg.h" struct voodoo2_reg { reg32 status; // (r ) Voodoo2 Graphics Status @@ -335,3 +334,6 @@ static_assert((offsetof (struct voodoo2_reg, trexInit0)) == 0x31c); static_assert((offsetof (struct voodoo2_reg, trexInit1)) == 0x320); static_assert((offsetof (struct voodoo2_reg, nccTable0[0])) == 0x324); static_assert((offsetof (struct voodoo2_reg, nccTable1[0])) == 0x354); + +typedef struct voodoo2_reg voodoo2_reg; + diff --git a/voodoo2_config.h b/voodoo2_config.h index 49e2e90..2475bd8 100644 --- a/voodoo2_config.h +++ b/voodoo2_config.h @@ -52,3 +52,6 @@ static_assert((offsetof (struct voodoo2_config, busSnoop1)) == 0x48); static_assert((offsetof (struct voodoo2_config, cfgStatus)) == 0x4c); static_assert((offsetof (struct voodoo2_config, cfgScratch)) == 0x50); static_assert((offsetof (struct voodoo2_config, siProcess)) == 0x54); + +typedef struct voodoo2_config voodoo2_config; +